From org.eclipse.jetty.server.Authentication: * - * @param servletRequest The request - * @param servletResponse The response - * @param mandatory True if authentication is mandatory. - * @return An Authentication. If Authentication is successful, this will be a {@link - * Authentication.User}. If a response has been sent by the Authenticator (which can be done - * for both successful and unsuccessful authentications), then the result will implement - * {@link Authentication.ResponseSent}. If Authentication is not mandatory, then a {@link - * Authentication.Deferred} may be returned. - * @throws ServerAuthException + * @param req The request + * @param res The response + * @param cb The callback + * @throws ServerAuthException if an error occurred */ @Override public AuthenticationState validateRequest(Request req, Response res, Callback cb) throws ServerAuthException { ServletContextRequest contextRequest = Request.as(req, ServletContextRequest.class); - HttpServletRequest request = contextRequest.getServletApiRequest(); HttpServletResponse response = contextRequest.getHttpServletResponse(); - // Trusted inbound ip, auth headers can be trusted. - - // Use the canonical path within the context for authentication and authorization - // as this is what is used to generate response content - String uri = URIUtil.addPaths(request.getServletPath(), request.getPathInfo()); - - if (uri == null) { - uri = "/"; - } - // Check this before checking if there is a user logged in, so - // that we can log out properly. Specifically, watch out for - // the case where the user logs in, but as a role that isn't - // allowed to see /*. They should still be able to log out. - if (isLoginOrErrorPage(uri) && !AuthenticationState.Deferred.isDeferred(res)) { - logger.atFine().log( - "Got %s, returning DeferredAuthentication to imply authentication is in progress.", - uri); - return null; + if (response == null) { + throw new ServerAuthException("validateRequest called with null response!!!"); } - if (request.getAttribute(SKIP_ADMIN_CHECK_ATTR) != null) { - logger.atFine().log("Returning DeferredAuthentication because of SkipAdminCheck."); - // Warning: returning DeferredAuthentication here will bypass security restrictions! + if (AuthenticationState.Deferred.isDeferred(res)) { return null; } - if (response == null) { - throw new ServerAuthException("validateRequest called with null response!!!"); - } - try { UserService userService = UserServiceFactory.getUserService(); // If the user is authenticated already, just create a @@ -198,10 +195,6 @@ public AuthenticationState validateRequest(Request req, Response res, Callback c } } - if (AuthenticationState.Deferred.isDeferred(res)) { - return null; - } - try { logger.atFine().log( "Got %s but no one was logged in, redirecting.", request.getRequestURI());