Examples of AuthResult


Examples of org.apache.geronimo.tomcat.security.AuthResult

                authorizationBC.setOffset(authorizationBC.getOffset() - 6);
            }

            UserIdentity userIdentity = loginService.login(username, password);
            if (userIdentity != null) {
                return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, false);
            }
        }


        // Send an "unauthorized" response and an appropriate challenge
        if (isAuthMandatory) {
            try {
                StringBuilder authenticateCC = new StringBuilder();
                authenticateCC.append("Basic realm=\"");
                authenticateCC.append((realmName == null) ? "<unspecified>" : realmName);
                authenticateCC.append('\"');
                response.addHeader(new String(AUTHENTICATE_BYTES), authenticateCC.toString());
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, null, false);
            } catch (IOException e) {
                throw new ServerAuthException(e);
            }
        }
        return new AuthResult(TomcatAuthStatus.SUCCESS, unauthenticatedIdentity, false);
    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

    @Override
    public AuthResult login(String username, String password, Request request) throws ServletException {
        UserIdentity userIdentity = loginService.login(username, password);
        if (userIdentity != null) {
            return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, false);
        }
        return new AuthResult(TomcatAuthStatus.FAILURE, null, false);
    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

    public AuthResult validateRequest(Request request, HttpServletResponse response, boolean isAuthMandatory, UserIdentity cachedIdentity) throws ServerAuthException {
        String authorization = request.getHeader("authorization");
        if (authorization != null) {
            UserIdentity userIdentity = findPrincipal(request, authorization);
            if (userIdentity != null) {
                return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, false);
            }
        }



        // Send an "unauthorized" response and an appropriate challenge

        // Next, generate a nOnce token (that is a token which is supposed
        // to be unique).
        if (isAuthMandatory) {
            String nOnce = generateNOnce(request);

            setAuthenticateHeader(response, nOnce);
            try {
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
            } catch (IOException e) {
                throw new ServerAuthException(e);
            }
            return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, null, false);
        }
        return new AuthResult(TomcatAuthStatus.SUCCESS, unauthenticatedIdentity, false);

    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

    @Override
    public AuthResult login(String username, String password, Request request) throws ServletException {
        UserIdentity userIdentity = loginService.login(username, password);
        if (userIdentity != null) {
            return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, false);
        }
        return new AuthResult(TomcatAuthStatus.FAILURE, null, false);
    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

    public AuthResult validateRequest(Request request, HttpServletResponse response, boolean isAuthMandatory, UserIdentity cachedIdentity) throws ServerAuthException {
        try {
            Session session = request.getSessionInternal(isAuthMandatory);
            if (session == null) {
                //default identity??
                return new AuthResult(TomcatAuthStatus.SUCCESS, null, false);
            }
            if (matchRequest(request, session)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Restore request from session '" + session.getIdInternal() + "'");
                }
                if (!restoreRequest(request, session)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Proceed to restored request");
                    }
                    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
                    return new AuthResult(TomcatAuthStatus.SEND_FAILURE, null, false);
                }
            }
            if (cachedIdentity != null) {
                return new AuthResult(TomcatAuthStatus.SUCCESS, cachedIdentity, true);
            }

            //we have not yet completed authentication.
            // Acquire references to objects we will need to evaluate
            MessageBytes uriMB = MessageBytes.newInstance();
            CharChunk uriCC = uriMB.getCharChunk();
            uriCC.setLimit(-1);
            String contextPath = request.getContextPath();
            String requestURI = request.getDecodedRequestURI();

            // Is this the action request from the login page?
            boolean loginAction =
                    requestURI.startsWith(contextPath) &&
                            requestURI.endsWith(Constants.FORM_ACTION);

            // No -- Save this request and redirect to the form login page
            if (!loginAction) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Save request in session '" + session.getIdInternal() + "'");
                }
                if (!isAuthMandatory) {
                    return new AuthResult(TomcatAuthStatus.SUCCESS, null, false);
                }
                try {
                    saveRequest(request, session);
                } catch (IOException ioe) {
                    logger.debug("Request body too big to save during authentication");
                    response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                            sm.getString("authenticator.requestBodyTooBig"));
                    return new AuthResult(TomcatAuthStatus.SEND_FAILURE, null, false);
                }
                forwardToLoginPage(request, response);
                return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, unauthenticatedIdentity, false);
            }

            // Yes -- Validate the specified credentials and redirect
            // to the error page if they are not correct
//            if (characterEncoding != null) {
//                request.setCharacterEncoding(characterEncoding);
//            }
            String username = request.getParameter(Constants.FORM_USERNAME);
            String password = request.getParameter(Constants.FORM_PASSWORD);
            if (logger.isDebugEnabled()) {
                logger.debug("Authenticating username '" + username + "'");
            }
            UserIdentity userIdentity = loginService.login(username, password);
            if (userIdentity == null) {
                forwardToErrorPage(request, response);
                //TODO right status?
                return new AuthResult(TomcatAuthStatus.SEND_FAILURE, unauthenticatedIdentity, false);
            }

            if (logger.isDebugEnabled()) {
                logger.debug("Authentication of '" + username + "' was successful");
            }

            session = request.getSessionInternal(false);
            if (session == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("User took so long to log on the session expired");
                }
                response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT,
                        sm.getString("authenticator.sessionExpired"));
                return new AuthResult(TomcatAuthStatus.SEND_FAILURE, unauthenticatedIdentity, false);
            }

            // Redirect the user to the original request URI (which will cause
            // the original request to be restored)
            requestURI = savedRequestURL(session);
            if (logger.isDebugEnabled()) {
                logger.debug("Redirecting to original '" + requestURI + "'");
            }
            if (requestURI == null) {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                        sm.getString("authenticator.formlogin"));
                return new AuthResult(TomcatAuthStatus.SEND_FAILURE, null, false);
            } else {
                response.sendRedirect(response.encodeRedirectURL(requestURI));
                return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, userIdentity, true);
            }
        } catch (IOException e) {
            throw new ServerAuthException(e);
        }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

    @Override
    public AuthResult login(String username, String password, Request request) throws ServletException {
        UserIdentity userIdentity = loginService.login(username, password);
        if (userIdentity != null) {
            return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, true);
        }
        return new AuthResult(TomcatAuthStatus.FAILURE, null, false);
    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

                try {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                } catch (IOException e) {
                    throw new ServerAuthException(e);
                }
                return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, null, false);
            }
            return new AuthResult(TomcatAuthStatus.SUCCESS, unauthenticatedIdentity, false);
        }

        // Validate any credentials already included with this request
        String username = null;
        String password = null;

        authorization.toBytes();
        ByteChunk authorizationBC = authorization.getByteChunk();
        if (authorizationBC.startsWithIgnoreCase("basic ", 0)) { // Basic authorization
            authorizationBC.setOffset(authorizationBC.getOffset() + 6);
            // FIXME: Add trimming
            // authorizationBC.trim();

            CharChunk authorizationCC = authorization.getCharChunk();
            Base64.decode(authorizationBC, authorizationCC);

            // Get username and password
            int colon = authorizationCC.indexOf(':');
            if (colon < 0) {
                username = authorizationCC.toString();
            } else {
                char[] buf = authorizationCC.getBuffer();
                username = new String(buf, 0, colon);
                password = new String(buf, colon + 1, authorizationCC.getEnd() - colon - 1);
            }

            authorizationBC.setOffset(authorizationBC.getOffset() - 6);
        } else if (authorizationBC.startsWithIgnoreCase("negotiate ", 0)) { // Spnego authorization
            authorizationBC.setOffset(authorizationBC.getOffset() + 10);
            username = authorizationBC.toString();
            authorizationBC.setOffset(authorizationBC.getOffset() - 10);
        }

        UserIdentity userIdentity = loginService.login(username, password);
        if (userIdentity != null) {
            return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, false);
        }

        // Send an "unauthorized" response and an appropriate challenge (BASIC)
        if (isAuthMandatory) {
            try {
                StringBuilder authenticateCC = new StringBuilder();
                authenticateCC.append("Basic realm=\"");
                if (realmName == null) {
                    authenticateCC.append(request.getServerName());
                    authenticateCC.append(':');
                    authenticateCC.append(Integer.toString(request.getServerPort()));
                } else {
                    authenticateCC.append(realmName);
                }
                authenticateCC.append('\"');
                response.addHeader(WWW_AUTHENTICATE, authenticateCC.toString());
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, null, false);
            } catch (IOException e) {
                throw new ServerAuthException(e);
            }
        }

        return new AuthResult(TomcatAuthStatus.SUCCESS, unauthenticatedIdentity, false);
    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

    @Override
    public AuthResult login(String username, String password, Request request) throws ServletException {
        UserIdentity userIdentity = loginService.login(username, password);
        if (userIdentity != null) {
            return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, false);
        }
        return new AuthResult(TomcatAuthStatus.FAILURE, null, false);
    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

        try {
            if ((certs == null) || (certs.length < 1)) {
                if (isAuthMandatory) {
                    response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                                   sm.getString("authenticator.certificates"));
                    return new AuthResult(TomcatAuthStatus.SEND_FAILURE, null, false);
                } else {
                    return new AuthResult(TomcatAuthStatus.SUCCESS, unauthenticatedIdentity, false);
                }
            }

            // Authenticate the specified certificate chain
            UserIdentity userIdentity = loginService.login(certs);
            if (userIdentity != null) {
                return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, true);
            }
            if (isAuthMandatory) {
                response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                                   sm.getString("authenticator.unauthorized"));
                return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, null, false);
            }
        } catch (IOException e) {
            throw new ServerAuthException(e);
        }
        return new AuthResult(TomcatAuthStatus.SUCCESS, unauthenticatedIdentity, false);
    }
View Full Code Here

Examples of org.apache.geronimo.tomcat.security.AuthResult

    @Override
    public AuthResult login(String username, String password, Request request) throws ServletException {
        UserIdentity userIdentity = loginService.login(username, password);
        if (userIdentity != null) {
            return new AuthResult(TomcatAuthStatus.SUCCESS, userIdentity, true);
        }
        return new AuthResult(TomcatAuthStatus.FAILURE, null, false);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.