Package com.adito.security

Examples of com.adito.security.LogonStateAndCache


            ActionMessages messages = new ActionMessages();
            messages.add(Globals.MESSAGE_KEY, new ActionMessage("login.sessionLocked"));
            saveMessages(request, messages);
        }

        LogonStateAndCache logonStateMachine = (LogonStateAndCache) request.getSession().getAttribute(
                        LogonStateAndCache.LOGON_STATE_MACHINE);
        if (logonStateMachine == null) {
            // there is no state machine so go back to the logonpage.
            return new ActionForward("/showLogon.do");
        } else {
            List<LabelValueBean> l = new ArrayList<LabelValueBean>();
            for (Iterator i = logonStateMachine.getAuthSchemes().iterator(); i.hasNext();) {
                AuthenticationScheme seq = (DefaultAuthenticationScheme) i.next();
                LabelValueBean lvb = new LabelValueBean(seq.getResourceName(), String.valueOf(seq.getResourceId()));
                l.add(lvb);
            }
            logonStateMachine.setState(LogonStateAndCache.STATE_KNOWN_USERNAME_MULTIPLE_SCHEMES_SELECT);
            ((SchemeSelectionForm) form).setAuthenticationSchemes(l);
            return mapping.findForward("success");
        }
    }
View Full Code Here


        /*
         * Get the authentication session and module to use to validate this
         * authentication attempt
         */
        AuthenticationScheme scheme = (AuthenticationScheme) request.getSession().getAttribute(Constants.AUTH_SESSION);
        LogonStateAndCache logonStateMachine = (LogonStateAndCache) request.getSession().getAttribute(
                        LogonStateAndCache.LOGON_STATE_MACHINE);

        // there are different users so we need to logon again, clearing the authentication scheme and logon machine.
        if (sessionInfo != null && logonStateMachine != null && !sessionInfo.getUser().equals(logonStateMachine.getUser())){
            request.getSession().removeAttribute(Constants.AUTH_SESSION);
            request.getSession().removeAttribute(LogonStateAndCache.LOGON_STATE_MACHINE);
            LogonControllerFactory.getInstance().logoffSession(request, response);
            msgs.add(Globals.ERROR_KEY, new ActionMessage("login.logonNotAllowed", "Session no longer valid, logon again."));
            saveErrors(request, msgs);
            return new RedirectWithMessages(mapping.findForward("logon"), request);
        }
       
        if (logonStateMachine == null) {
            logonStateMachine = new LogonStateAndCache(LogonStateAndCache.STATE_STARTED, request.getSession());
            request.getSession().setAttribute(LogonStateAndCache.LOGON_STATE_MACHINE, logonStateMachine);
        }
        if (scheme == null) {

            ActionForward fwd = null;
View Full Code Here

        if (module == null) {
            throw new Exception("No current authentication module");
        }
        RequestParameterMap params = new RequestParameterMap(new ServletRequestAdapter(request));
        User currentUser = scheme.getUser();
        LogonStateAndCache logonStateMachine = (LogonStateAndCache) request.getSession().getAttribute(
                        LogonStateAndCache.LOGON_STATE_MACHINE);

        if (logonStateMachine == null) {
            logonStateMachine = new LogonStateAndCache(LogonStateAndCache.STATE_STARTED, request.getSession());
        }

        if (logonStateMachine.getState() == LogonStateAndCache.STATE_KNOWN_USERNAME_NO_SCHEME_SPOOF_PASSWORD_ENTRY) {
            scheme.addCredentials(new PasswordCredentials("", "".toCharArray()));
        } else if (logonStateMachine.getState() == LogonStateAndCache.STATE_UNKNOWN_USERNAME_PROMPT_FOR_PASSWORD) {
            Credentials creds = module.authenticate(request, params);
            if(creds!=null)
              scheme.addCredentials(creds);
        } else {
          Credentials creds = module.authenticate(request, params);
            if(creds!=null) {
              scheme.addCredentials(creds);
              logonStateMachine.setState(LogonStateAndCache.STATE_VALID_LOGON);
            }
            // Check we have a user object
            if (currentUser == null && scheme.getUser() == null) {
                throw new Exception("The first authentication did not provide a user.");
            }
View Full Code Here

          if(back) {
            /**
             * This is designed to take the user back to the start of their default scheme. This
             * can only be invoked from the authentication scheme selection page.
             */
                LogonStateAndCache logonStateMachine = (LogonStateAndCache) request.getSession().getAttribute(
                        LogonStateAndCache.LOGON_STATE_MACHINE);
                logonStateMachine.setState(LogonStateAndCache.STATE_USERNAME_KNOWN);
                ((LogonForm) form).setUsername(logonStateMachine.getUser() == null ? logonStateMachine.getSpoofedUsername() : logonStateMachine.getUser().getPrincipalName());
                ((LogonForm) form).setHasMoreAuthenticationSchemes(logonStateMachine.enabledSchemesGraeterThanOne());
                return mapping.findForward("display");
          }
         
            // Configure the logon state machine
            LogonStateAndCache logonStateMachine = checkLogonStateMachine(request, response, logonForm, reset);
           
            /*
             * Only when in STARTED state do we collect the username
             */
            if(logonStateMachine.getState() == LogonStateAndCache.STATE_STARTED) {
              logonStateMachine.setState(LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTRY);
              return mapping.findForward("username");
            }
           
            // try to check the auth session, if not you need to sign in again.
            fwd = checkAuthSession((LogonForm)form, reset, mapping, request, response, logonStateMachine);
View Full Code Here

     * @return logon state machine
     * @throws Exception on any error
     */
    LogonStateAndCache checkLogonStateMachine(HttpServletRequest request, HttpServletResponse response, LogonForm form, boolean reset) throws Exception {

        LogonStateAndCache logonStateMachine = (LogonStateAndCache) request.getSession().getAttribute(
                        LogonStateAndCache.LOGON_STATE_MACHINE);

        /** Reset the logon state machine if :-
         *
         * 1. This is the first connection from this browser session.
         * 2. The 'reset' parameter has been passed on the request
         * 3. The logon state machine is in {@link LogonStateAndCache#STATE_RETURN_TO_LOGON}
         *
         */
        UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(form.getRealmName());
        if (logonStateMachine == null || logonStateMachine.getState() == LogonStateAndCache.STATE_RETURN_TO_LOGON || reset) {
          /*
           * If the client is already logged on, then we got here because
           * a <i>Session Lock</i> has occured and so only require
           * the users password
           */
            if (LogonControllerFactory.getInstance().hasClientLoggedOn(request, response) == LogonController.LOGGED_ON) {
                logonStateMachine = new LogonStateAndCache(LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTERED, request.getSession());
                logonStateMachine.setUser(LogonControllerFactory.getInstance().getUser(request));
                form.initUser();
                form.setHasMoreAuthenticationSchemes(false);
            } else {
              /*
               * This is a brand new session so we require the username
               */
                logonStateMachine = new LogonStateAndCache(LogonStateAndCache.STATE_STARTED, request.getSession());
                request.getSession().removeAttribute(Constants.AUTH_SESSION);
                if(!Util.isNullOrTrimmedBlank(form.getUsername())) {
                  try {
                    User user = udb.getAccount(form.getUsername());
                    logonStateMachine.removeFromSpoofCache(user.getPrincipalName());
                    form.initUser();
                    try {
                      logonStateMachine.setUser(user);
                    }
                    catch(AccountLockedException ale) {
                      // Continue anyway and get the exception later
                    }
                    logonStateMachine.setState(LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTERED);
                  }
                  catch(UserNotFoundException unfe) {
                      form.initUser();
                      // Spoof some authentication schemes
                      form.setHasMoreAuthenticationSchemes(true);
                  }
                }
               
            }
        } else {
            /*
             * A username has been provided but it was unknown. The error message
             * indicating this will not be displayed until the next stage is
             * complete
             */
          if (logonStateMachine.getState() == LogonStateAndCache.STATE_UNKNOWN_USERNAME) {
              logonStateMachine.setState(LogonStateAndCache.STATE_UNKNOWN_USERNAME_PROMPT_FOR_PASSWORD);
          }
          else  if (logonStateMachine.getState() == LogonStateAndCache.STATE_KNOWN_USERNAME_MULTIPLE_SCHEMES_SELECT){           
            /*
             * The scheme to sign on with has changed, so we need to update the
                 * logon state machine.
                 */
                logonStateMachine.forceHighestPriorityScheme(request.getParameter("selectedAuthenticationScheme"),
                    request.getParameter("username"));
                logonStateMachine.setState(LogonStateAndCache.STATE_KNOWN_USERNAME_MULTIPLE_SCHEMES);               
            } else if (logonStateMachine.getState() == LogonStateAndCache.STATE_KNOWN_USERNAME_NO_SCHEME_SPOOF_PASSWORD_ENTRY){
              /*
                 * The scheme to sign on with has changed, so we need to update the
                 * logon state machine
                 */
                logonStateMachine.setSpoofedHighestPriorityScheme(request.getParameter("username"));
            }
            else if(logonStateMachine.getState() == LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTRY){
              /*
               * The username has been collected, now process it.
               */
              if(Util.isNullOrTrimmedBlank(form.getUsername())) {
                /**
                 * Page refreshed, stay in same state
                 */
                  logonStateMachine.setState(LogonStateAndCache.STATE_STARTED);
              }
              else {
                  logonStateMachine.setState(LogonStateAndCache.STATE_DISPLAY_USERNAME_ENTERED);
                  try {
                    User user = udb.getAccount(form.getUsername());
                    logonStateMachine.removeFromSpoofCache(user.getPrincipalName());
                    try {
                      logonStateMachine.setUser(user);
                    }
                    catch(AccountLockedException ale) {
                      // Continue anyway and get the exception later
                    }
                  }
                  catch(UserNotFoundException unfe) {
                    // Continue anyway
                    String username = request.getParameter("username");
                    Realm realm = UserDatabaseManager.getInstance().getDefaultRealm();
                    logonStateMachine.setState(LogonStateAndCache.STATE_UNKNOWN_USERNAME_PROMPT_FOR_PASSWORD);
                      logonStateMachine.setSpoofedHighestPriorityScheme(username);
                      logonStateMachine.getHighestPriorityScheme().setAccountLock(LogonControllerFactory.getInstance().checkForAccountLock(username, realm.getResourceName()));
                  }
              }
            }
         
            ((LogonForm) form).setHasMoreAuthenticationSchemes(logonStateMachine.enabledSchemesGraeterThanOne());
        }
       
        return logonStateMachine;
    }
View Full Code Here

TOP

Related Classes of com.adito.security.LogonStateAndCache

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.