Package winstone

Examples of winstone.AuthenticationPrincipal


        if (realPassword == null)
            return null;
        else if (!realPassword.equals(password))
            return null;
        else
            return new AuthenticationPrincipal(userName, password,
                    (List) this.roles.get(userName));
    }
View Full Code Here


    /**
     * Retrieve an authenticated user
     */
    public AuthenticationPrincipal retrieveUser(String userName) {
        return new AuthenticationPrincipal(userName, (String) this.passwords
                .get(userName), (List) this.roles.get(userName));
    }
View Full Code Here

        if (realPassword == null)
            return null;
        else if (!realPassword.equals(password))
            return null;
        else
            return new AuthenticationPrincipal(userName, password,
                    (List) this.roles.get(userName));
    }
View Full Code Here

     */
    public AuthenticationPrincipal retrieveUser(String userName) {
        if (userName == null)
            return null;
        else
            return new AuthenticationPrincipal(userName,
                    (String) this.passwords.get(userName), (List) this.roles
                            .get(userName));
    }
View Full Code Here

            int length = decodeBase64(inBytes, outBytes, 0, inBytes.length, 0);

            String decoded = new String(outBytes, 0, length);
            int delimPos = decoded.indexOf(':');
            if (delimPos != -1) {
                AuthenticationPrincipal principal = this.realm
                        .authenticateByUsernamePassword(decoded.substring(0,
                                delimPos).trim(), decoded.substring(
                                delimPos + 1).trim());
                if (principal != null) {
                    principal.setAuthType(HttpServletRequest.BASIC_AUTH);
                    if (request instanceof WinstoneRequest)
                        ((WinstoneRequest) request).setRemoteUser(principal);
                    else if (request instanceof HttpServletRequestWrapper) {
                        HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
                        if (wrapper.getRequest() instanceof WinstoneRequest)
View Full Code Here

            return true;
        else if ((algorithm != null) && !algorithm.equals("MD5"))
            return true;

        // Get a user matching the username
        AuthenticationPrincipal principal = this.realm.retrieveUser(userName);
        if (principal == null)
            return true;

        // Compute the 2 digests and compare
        String userRealmPasswordDigest = md5Encode(userName + ":" + realm + ":"
                + principal.getPassword());
        String methodURIDigest = md5Encode(request.getMethod() + ":" + uri);
        String serverResponseDigest = md5Encode(userRealmPasswordDigest + ":"
                + nOnce + ":" + nc + ":" + cnOnce + ":" + qop + ":"
                + methodURIDigest);
        if (serverResponseDigest.equals(clientResponseDigest)) {
            principal.setAuthType(HttpServletRequest.DIGEST_AUTH);
            if (request instanceof WinstoneRequest)
                ((WinstoneRequest) request).setRemoteUser(principal);
            else if (request instanceof HttpServletRequestWrapper) {
                HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
                if (wrapper.getRequest() instanceof WinstoneRequest)
View Full Code Here

        if (pathRequested.endsWith(FORM_ACTION)) {
            String username = request.getParameter(FORM_USER);
            String password = request.getParameter(FORM_PASS);

            // Send to error page if invalid
            AuthenticationPrincipal principal = this.realm
                    .authenticateByUsernamePassword(username, password);
            if (principal == null) {
                javax.servlet.RequestDispatcher rdError = request
                        .getRequestDispatcher(this.errorPage);
                rdError.forward(request, response);
            }

            // Send to stashed request
            else {
                // Iterate back as far as we can
                ServletRequest wrapperCheck = request;
                while (wrapperCheck instanceof HttpServletRequestWrapper) {
                    wrapperCheck = ((HttpServletRequestWrapper) wrapperCheck).getRequest();
                }
               
                // Get the stashed request
                WinstoneRequest actualRequest = null;
                if (wrapperCheck instanceof WinstoneRequest) {
                    actualRequest = (WinstoneRequest) wrapperCheck;
                    actualRequest.setRemoteUser(principal);
                } else {
                    Logger.log(Logger.WARNING, AUTH_RESOURCES,
                            "FormAuthenticationHandler.CantSetUser",
                            wrapperCheck.getClass().getName());
                }
                HttpSession session = request.getSession(true);
                String previousLocation = this.loginPage;
                RetryRequestParams cachedRequest = (RetryRequestParams)
                        session.getAttribute(CACHED_REQUEST);
                if ((cachedRequest != null) && (actualRequest != null)) {
                    // Repopulate this request from the params we saved
                    request = new RetryRequestWrapper(request, cachedRequest);
                    previousLocation =
                        (request.getServletPath() == null ? "" : request.getServletPath()) +
                        (request.getPathInfo() == null ? "" : request.getPathInfo());
                } else {
                    Logger.log(Logger.DEBUG, AUTH_RESOURCES,
                            "FormAuthenticationHandler.NoCachedRequest");
                }
               
                // do role check, since we don't know that this user has permission
                if (doRoleCheck(request, response, previousLocation)) {
                    principal.setAuthType(HttpServletRequest.FORM_AUTH);
                    session.setAttribute(AUTHENTICATED_USER, principal);
                    javax.servlet.RequestDispatcher rdPrevious = request
                            .getRequestDispatcher(previousLocation);
                    rdPrevious.forward(request, response);
                } else {
                    javax.servlet.RequestDispatcher rdError = request
                            .getRequestDispatcher(this.errorPage);
                    rdError.forward(request, response);
                }
            }
            return false;
        }
        // If it's not a login, get the session, and look up the auth user variable
        else {
            WinstoneRequest actualRequest = null;
            if (request instanceof WinstoneRequest) {
                actualRequest = (WinstoneRequest) request;
            } else if (request instanceof HttpServletRequestWrapper) {
                HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
                if (wrapper.getRequest() instanceof WinstoneRequest) {
                    actualRequest = (WinstoneRequest) wrapper.getRequest();
                } else {
                    Logger.log(Logger.WARNING, AUTH_RESOURCES,
                            "FormAuthenticationHandler.CantSetUser", wrapper
                                    .getRequest().getClass().getName());
                }
            } else {
                Logger.log(Logger.WARNING, AUTH_RESOURCES,
                        "FormAuthenticationHandler.CantSetUser", request
                                .getClass().getName());
            }

            HttpSession session = actualRequest.getSession(false);
            if (session != null) {
                AuthenticationPrincipal authenticatedUser = (AuthenticationPrincipal)
                        session.getAttribute(AUTHENTICATED_USER);
                if (authenticatedUser != null) {
                    actualRequest.setRemoteUser(authenticatedUser);
                    Logger.log(Logger.FULL_DEBUG, AUTH_RESOURCES,
                            "FormAuthenticationHandler.GotUserFromSession");
View Full Code Here

                    certificateArray[n].checkValidity();
                } catch (Throwable err) {
                    failed = true;
                }
            if (!failed) {
                AuthenticationPrincipal principal = this.realm
                        .retrieveUser(certificateArray[0].getSubjectDN()
                                .getName());
                if (principal != null) {
                    principal.setAuthType(HttpServletRequest.CLIENT_CERT_AUTH);
                    if (request instanceof WinstoneRequest)
                        ((WinstoneRequest) request).setRemoteUser(principal);
                    else if (request instanceof HttpServletRequestWrapper) {
                        HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
                        if (wrapper.getRequest() instanceof WinstoneRequest)
View Full Code Here

TOP

Related Classes of winstone.AuthenticationPrincipal

Copyright © 2018 www.massapicom. 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.