difin commented on code in PR #5561: URL: https://github.com/apache/hive/pull/5561#discussion_r1868080359
########## service/src/java/org/apache/hive/service/servlet/LDAPAuthenticationFilter.java: ########## @@ -44,29 +45,28 @@ public LDAPAuthenticationFilter(LdapAuthService ldapAuthService) { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - HttpServletRequest httpRequest = (HttpServletRequest) request; - String requestURI = httpRequest.getRequestURI(); - - boolean isLoginFormRequest = requestURI.endsWith(LOGIN_FORM_URI); - boolean isLoginServletRequest = requestURI.endsWith(LOGIN_SERVLET_URI); boolean isLoggedIn = ldapAuthService.authenticate(httpRequest, (HttpServletResponse) response); - - if (isLoggedIn && (isLoginFormRequest || isLoginServletRequest)) { - // User is already logged in, and is trying to login again; forward to the main homepage - RequestDispatcher dispatcher = request.getRequestDispatcher(HiveServer2.HS2_WEBUI_ROOT_URI); + boolean forwardRequest = (isLoginRequest(httpRequest) && isLoggedIn) || (!isLoginRequest(httpRequest) && !isLoggedIn); + if (forwardRequest) { + ServletContext rootContext = request.getServletContext().getContext("/"); + // if the request is trying to login, forward to the main homepage in case + // the user has already logged in, otherwise the login page. + String forwardUri = isLoggedIn ? HiveServer2.HS2_WEBUI_ROOT_URI : LOGIN_FORM_URI; + RequestDispatcher dispatcher = rootContext.getRequestDispatcher(forwardUri); dispatcher.forward(request, response); - } else if (isLoggedIn || isLoginFormRequest || isLoginServletRequest) { - // User is either already logged in or this is a request for the login page or processing of a login attempt, - // in all these cases allow to continue the request as is without changes - chain.doFilter(request, response); } else { - // User is not logged in, so authentication is required; forwards to the login page - RequestDispatcher dispatcher = request.getRequestDispatcher(LOGIN_FORM_URI); - dispatcher.forward(request, response); + chain.doFilter(request, response); } } + public boolean isLoginRequest(HttpServletRequest request) { + String method = request.getMethod(); + String servletPath = request.getServletPath(); + return LOGIN_FORM_URI.equals(servletPath) || + "post".equalsIgnoreCase(method) && LOGIN_SERVLET_URI.equals(servletPath); Review Comment: I think it would be better to use HttpMethod.POST.toLowerCase() instead of hardcoded method name -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org