diff --git a/presto-main/src/main/java/io/prestosql/server/security/AuthenticationFilter.java b/presto-main/src/main/java/io/prestosql/server/security/AuthenticationFilter.java index 643805a48..0931ad840 100644 --- a/presto-main/src/main/java/io/prestosql/server/security/AuthenticationFilter.java +++ b/presto-main/src/main/java/io/prestosql/server/security/AuthenticationFilter.java @@ -101,12 +101,21 @@ public class AuthenticationFilter nextFilter.doFilter(withPrincipal(request, new BasicPrincipal(authenticatedUser.get())), response); return; } + + // skip authentication for login/logout page + if (isSkipAuth(request)) { + nextFilter.doFilter(request, response); + return; + } + + if (needRedirect(request, authenticators)) { + // redirect to login page + URI redirectUri = UiAuthenticator.buildLoginFormURI(URI.create(request.getRequestURI())); + response.sendRedirect(redirectUri.toString()); + return; + } } - // skip authentication for login/logout page - if (isSkipAuth(request)) { - nextFilter.doFilter(request, response); - return; - } + // try to authenticate, collecting errors and authentication headers Set messages = new LinkedHashSet<>(); Set authenticateHeaders = new LinkedHashSet<>(); @@ -132,16 +141,8 @@ public class AuthenticationFilter // authentication failed skipRequestBody(request); - // skip authentication if non-secure or not configured - if (isWebUi(request)) { - URI redirectUri = UiAuthenticator.buildLoginFormURI(URI.create(request.getRequestURI())); - response.sendRedirect(redirectUri.toString()); - return; - } - else { - for (String value : authenticateHeaders) { - response.addHeader(WWW_AUTHENTICATE, value); - } + for (String value : authenticateHeaders) { + response.addHeader(WWW_AUTHENTICATE, value); } if (messages.isEmpty()) { @@ -150,6 +151,38 @@ public class AuthenticationFilter response.sendError(SC_UNAUTHORIZED, Joiner.on(" | ").join(messages)); } + public static boolean needRedirect(HttpServletRequest request, final List authenticators) + { + boolean pwdAuthentication = false; + boolean kerberosAuthentication = false; + + for (Authenticator authenticator : authenticators) { + if (authenticator instanceof PasswordAuthenticator) { + pwdAuthentication = true; + } + else if (authenticator instanceof KerberosAuthenticator) { + kerberosAuthentication = true; + } + } + + // Only use PasswordAuthenticator, all pages needs to redirect to login page + if (pwdAuthentication && !kerberosAuthentication) { + return true; + } + + // If request path is web uri : "/" and enable kerberos or ldap authenticator, request path "/" needs to redirect to login page + if (isWebUri(request) && (pwdAuthentication || kerberosAuthentication)) { + return true; + } + return false; + } + + public static boolean isWebUri(HttpServletRequest request) + { + String pathInfo = request.getPathInfo(); + return pathInfo.equals("/"); + } + public static boolean isWebUi(HttpServletRequest request) { String pathInfo = request.getPathInfo(); diff --git a/presto-main/src/main/resources/webapp/login.html b/presto-main/src/main/resources/webapp/login.html index bf73da9dd..0c92a7b53 100644 --- a/presto-main/src/main/resources/webapp/login.html +++ b/presto-main/src/main/resources/webapp/login.html @@ -80,23 +80,43 @@ font-size: 15px; font-weight: bold; } + + .login-form .radio-Group { + min-height: 38px; + border-radius: 2px; + } + + .login-form .radio-Group label{ + padding: 7px; + font-size: 15px; + font-weight: normal; + } + + +
Loading...
+