Package org.apache.jetspeed.security

Examples of org.apache.jetspeed.security.User


                {
                    try
                    {
                        //manager.setPassword(userName, currPassword, newPassword);
                      // Changes for new Security API's
                      User user = manager.getUser(userName);
                      PasswordCredential credential = manager.getPasswordCredential(user);
                      credential.setPassword(currPassword, newPassword);
                      manager.storePasswordCredential(credential);
                        audit.logUserActivity(userName, getIPAddress(actionRequest), AuditActivity.PASSWORD_CHANGE_SUCCESS, USER_ADMINISTRATION);
View Full Code Here


                return;
            }
            if (optionForceEmailsToBeSystemUnique)
            {
                boolean emailExistsFlag = true;
                User user = null;
                try
                {
                    user = admin.lookupUserFromEmail((String) userInfo
                            .get(USER_ATTRIBUTE_EMAIL));
                } catch (AdministrationEmailException e1)
View Full Code Here

                    RoleManager roleManager = ((AbstractAdminWebApplication)getApplication()).getServiceLocator().getRoleManager();
                    PageManager pageManager = ((AbstractAdminWebApplication) getApplication()).getServiceLocator().getPageManager();
                    try
                    {
                        getManager().addPrincipal(principal, null);
                        User user = userManager.getUser(getUserName());

                        if(!StringUtils.isEmpty(defaultRole))
                        {
                            roleManager.addRoleToUser(getUserName(), defaultRole);
                        }
                        if(!StringUtils.isEmpty(requiredRole))
                        {
                            roleManager.addRoleToUser(getUserName(), requiredRole);
                        }
                       
                        Profiler profiler = getServiceLocator().getProfiler();
                       
                        if (!StringUtils.isEmpty(getProfilingRule()))
                        {
                            ProfilingRule profilingRule = profiler.getRule(getProfilingRule());
                           
                            if (profilingRule != null)
                            {
                                profiler.setRuleForPrincipal(principal, profilingRule, "default");
                            }
                            else
                            {
                                log.error("Failed to set profiling rule for principal. Invalid profiling rule: " + getProfilingRule());
                            }
                        }
                        else if (!StringUtils.isEmpty(defaultProfile))
                        {
                            ProfilingRule defaultProfilingRule = profiler.getRule(defaultProfile);
                           
                            if (defaultProfilingRule != null)
                            {
                                profiler.setRuleForPrincipal(principal, defaultProfilingRule, "default");
                            }
                            else
                            {
                                if (log.isDebugEnabled())
                                {
                                    log.debug("Default profiling rule is not applied to the principal because the default profiling rule is not found: " + defaultProfile);
                                }
                            }
                        }
                       
                        String subSite;
                        if (!StringUtils.isEmpty(defaultSubsite))
                        {
                            user.getSecurityAttributes().getAttribute(User.JETSPEED_USER_SUBSITE_ATTRIBUTE,true).setStringValue(defaultSubsite);
                            user.getSecurityAttributes().getAttribute(User.JETSPEED_USER_SUBSITE_ATTRIBUTE, true).setStringValue(defaultSubsite);
                            subSite = subsiteRoot + defaultSubsite + Folder.USER_FOLDER + user.getName();
                        }
                       
                        else
                        {
                            subSite = Folder.USER_FOLDER + user.getName();;
                        }
                       
                        if (!StringUtils.isEmpty(templateFolder))
                        {
                            try
                            {
                                Folder source = pageManager.getFolder(templateFolder);
                                pageManager.deepCopyFolder(source, subSite, user.getName());
                            }
                            catch (FolderNotFoundException e)
                            {
                                error(e.getMessage());
                            }
View Full Code Here

               
                sso.setPassword(ssoUser, password);
            }
            else
            {
                User user = userManager.getUser(request.getUserPrincipal().getName());
                sso.addUser(site, user, username, password);
            }
        }
        catch (SSOException e)
        {
View Full Code Here

                    return;
                }               
               
                if (userManager.userExists(username))
                {                   
                    User user = null;
                    try
                    {
                        user = userManager.getUser(username);
                    }
                    catch (Exception e)
                    {
                        StatusMessage msg = new StatusMessage("User not accessible.", StatusMessage.ERROR);
                        PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);
                        userBean.setInvalidUser(true);
                        userBean.setQuestion( questionFactory.getRandomQuestion() );                       
                        setView(actionRequest, phase, SUCCESS2); // act like nothing happening
                        return;
                    }
                    userBean.setUsername(username);
                    userBean.setUser(user);                   
                    UserCredential credential = null;
                    try
                    {
                        credential = SecurityHelper.getCredential(userManager, user);
                    }
                    catch (SecurityException e)
                    {}
                    if (credential != null)
                    {
                        if (credential.isEnabled() == false)
                        {
                            userBean.setInvalidUser(true);
                            setView(actionRequest, phase, SUCCESS2);
                            userBean.setQuestion( questionFactory.getRandomQuestion() );                           
                            StatusMessage msg = new StatusMessage("The account has been disabled.", StatusMessage.ERROR);
                            PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);                           
                            return;
                        }
                    }
                    userBean.setUser(user);
                    userBean.setUsername(username);
                    // see if we have a valid MFA Cookie
                    Cookie mfaCookie = SecurityHelper.getMFACookie(actionRequest, username);
                    if (mfaCookie == null)
                    {
                        if (generateQuestionAndAnswer(userBean))
                        {
                            setView(actionRequest, phase, SUCCESS2);
                        }
                        else
                        {
                            // go into enrollment mode
                            setView(actionRequest, phase, SUCCESS3);                               
                        }                           
                    }
                    else
                    {
                      Map<String, SecurityAttribute> userAttributes = userBean.getUser().getSecurityAttributes().getAttributeMap();
                      String cookie = getUserAttribute(userAttributes, "user.cookie", username);                         
                        if (mfaCookie.getValue().equals(cookie))
                        {                       
                            userBean.setHasCookie(true);
                          userBean.setPassPhrase(getUserAttribute(userAttributes, "user.passphrase", ""));
                            setView(actionRequest, phase, SUCCESS1);
                        }
                        else
                        {
                            userBean.setHasCookie(false);
                            if (generateQuestionAndAnswer(userBean))
                            {
                                setView(actionRequest, phase, SUCCESS2);
                            }
                            else
                            {
                                // go into enrollment mode
                                setView(actionRequest, phase, SUCCESS3);
                            }                                                               
                        }
                    }
                }
                else
                {
                    // Proceed on but mark the User Bean as invalid user to prevent user harvesting
                  // Also need to supply a random challenge question.
                    userBean.setInvalidUser(true);
                  userBean.setQuestion( questionFactory.getRandomQuestion() );
                    StatusMessage msg = new StatusMessage("The text entered does not match the displayed text.", StatusMessage.ERROR);
                    PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);                   
                    setView(actionRequest, phase, SUCCESS2);
                }               
            }           
            else if (phase.equals("two"))
            {
                if (userBean.isInvalidUser())
                {
                    // prevent harvesting
                    StatusMessage msg = new StatusMessage("Invalid User.", StatusMessage.ERROR);
                    PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);                   
                    setView(actionRequest, phase, FAILURE1);
                }
                else
                {
                    if (userBean.getUser() == null)
                    {
                        StatusMessage msg = new StatusMessage("User not accessible.", StatusMessage.ERROR);
                        PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);
                        setView(actionRequest, phase, FAILURE1);                                                                                                           
                        return;
                    }
                    String typedAnswer = actionRequest.getParameter("answer");
                    String publicTerminal = actionRequest.getParameter("publicTerminal");
                    userBean.setPublicTerminal(publicTerminal != null);
                    Map<String, SecurityAttribute> userAttributes = userBean.getUser().getSecurityAttributes().getAttributeMap();
                    int failures = Integer.parseInt(getUserAttribute(userAttributes, "user.question.failures", "0"));                   
                    if (SecurityHelper.isEmpty(typedAnswer) || !typedAnswer.equalsIgnoreCase(userBean.getAnswer()))
                    {
                        int count = failures + 1;
                        if (count >= this.maxNumberOfAuthenticationFailures)
                        {
                            try
                            {
                                RequestContext rc = SecurityHelper.getRequestContext(actionRequest);
                                User user = userManager.getUser(userBean.getUsername());                                                       
                                PasswordCredential pwc = userManager.getPasswordCredential(user);
                                pwc.setEnabled(false);
                                userManager.storePasswordCredential(pwc);
                                SecurityHelper.updateCredentialInSession(rc, pwc);
                                userBean.setUser(user);
                                userAttributes = userBean.getUser().getSecurityAttributes().getAttributeMap();                               
                                user.getSecurityAttributes().getAttribute("user.question.failures", true).setStringValue("0");                               
                                userManager.updateUser(user);                               
                                audit.logUserActivity(userBean.getUsername(),
                                        rc.getRequest().getRemoteAddr(),
                                        AuditActivity.USER_DISABLE, "Failed question and answer limit reached");                               
                            }
                            catch (Exception e)
                            {
                            }
                            StatusMessage msg = new StatusMessage("Disabling user after too many failed questions.", StatusMessage.ERROR);
                            PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);
                            setView(actionRequest, phase, FAILURE2);                           
                        }
                        else
                        {                           
                            try
                            {
                                userBean.getUser().getSecurityAttributes().getAttribute("user.question.failures", true).setStringValue(Integer.toString(count));                               
                                userManager.updateUser(userBean.getUser());
                            }
                            catch (SecurityException e)
                            {}
                            StatusMessage msg = new StatusMessage("Invalid answer to question.", StatusMessage.ERROR);
                            PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);
                            setView(actionRequest, phase, FAILURE1);
                        }
                    }
                    else
                    {
                        try
                        {
                          userBean.setPassPhrase(getUserAttribute(userAttributes, "user.passphrase", ""));
                            userBean.getUser().getSecurityAttributes().getAttribute("user.question.failures", true).setStringValue("0");                               
                            userManager.updateUser(userBean.getUser());
                        }
                        catch (Exception e)
                        {}
                        setView(actionRequest, phase, SUCCESS1);                               
                    }
                }
            }
            else if (phase.equals("enroll"))
            {
                boolean success = false;
                String password = userBean.getPassword();
                User user = userBean.getUser();
                if (user != null && password != null)
                {
                    AuthenticatedUser authUser = null;
                    try
                    {
                        authUser = authorization.authenticate(userBean.getUsername(), password);
                    }
                    catch (SecurityException e)
                    {
                        RequestContext rc = SecurityHelper.getRequestContext(actionRequest);
                        audit.logUserActivity(userBean.getUsername(), rc.getRequest().getRemoteAddr(),
                                AuditActivity.AUTHENTICATION_FAILURE, "PortalFilter");                   
                    }
                    if (authUser != null)
                    {
                        // validate request parameers, if valid update user preferences
                        String question1 = actionRequest.getParameter("question1");
                        String question2 = actionRequest.getParameter("question2");
                        String question3 = actionRequest.getParameter("question3");
                        String answer1 = actionRequest.getParameter("answer1");
                        String answer2 = actionRequest.getParameter("answer2");
                        String answer3 = actionRequest.getParameter("answer3");
                        String passPhrase = actionRequest.getParameter("passphrase");
                       
                        // validation (SecurityHelper.isEmpty, unique questions)
                        if (SecurityHelper.isEmpty(answer1) || SecurityHelper.isEmpty(answer2) || SecurityHelper.isEmpty(answer3))
                        {
                            StatusMessage msg = new StatusMessage("Please enter a valid answer for all 3 questions.", StatusMessage.ERROR);
                            PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);
                            setView(actionRequest, phase, FAILURE1);                                                                   
                            return;
                        }
                        if (SecurityHelper.isEmpty(passPhrase))
                        {
                            StatusMessage msg = new StatusMessage("Please enter a valid pass phrase.", StatusMessage.ERROR);
                            PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);
                            setView(actionRequest, phase, FAILURE1);                                                                   
                            return;
                        }
                        if (question1.equals(question2) || question1.equals(question3) || question2.equals(question3))
                        {
                            StatusMessage msg = new StatusMessage("Please select a unique question in all cases.", StatusMessage.ERROR);
                            PortletMessaging.publish(actionRequest, STATUS_MESSAGE, msg);
                            setView(actionRequest, phase, FAILURE1);                                                                   
                            return;                   
                        }
       
                        // update the prefs db (we are not logged in yet
                        user = userBean.getUser();
                        try
                        {
                            user.getSecurityAttributes().getAttribute("user.question.1", true).setStringValue(question1);
                            user.getSecurityAttributes().getAttribute("user.question.2", true).setStringValue(question2);
                            user.getSecurityAttributes().getAttribute("user.question.3", true).setStringValue(question3);
                            user.getSecurityAttributes().getAttribute("user.answer.1", true).setStringValue(answer1);
                            user.getSecurityAttributes().getAttribute("user.answer.2", true).setStringValue(answer2);
                            user.getSecurityAttributes().getAttribute("user.answer.3", true).setStringValue(answer3);
                            user.getSecurityAttributes().getAttribute("user.passphrase", true).setStringValue(passPhrase);
                            user.getSecurityAttributes().getAttribute("user.cookie", true).setStringValue(CaptchaImageResource.randomString(8, 16));
                            userManager.updateUser(user);
                            success = true;
                        }
                        catch (SecurityException e)
                        {
View Full Code Here

    }

    private void failedLoginProcessing(ActionRequest actionRequest, String phase, String username, UserBean userBean) throws NotSerializableException, PortletException
    {
        int nextView = FAILURE1;
        User user = null;
        try
        {
            user = userManager.getUser(username);
        }
        catch (Exception e)
View Full Code Here

        actionResponse.sendRedirect(s.toString());
    }
           
    public boolean generateQuestionAndAnswer(UserBean userBean)
    {
        User user = userBean.getUser();
        if (user == null)
        {
            if (userBean.getUsername() == null)
            {
                // hard out of luck
View Full Code Here

        String newPassword = (String) map.get("password");

        // Here's where a break should be.   The following code should be put into the RETURN portlet
        try
        {
            User user = userManager.getUser(userName);
            PasswordCredential pwc = userManager.getPasswordCredential(user);
            pwc.setPassword(null, newPassword);
            pwc.setUpdateRequired(true);
            userManager.storePasswordCredential(pwc);
           
View Full Code Here

        {
            publishRenderMessage(request, MSG_MESSAGE, errors);
            return;
        }

        User user = null;
        try
        {
            user = admin.lookupUserFromEmail(email);
        } catch (Exception e)
        {
            publishRenderMessage(
                    request,
                    MSG_MESSAGE,
                    makeMessage(resource.getString("forgotten.email_address_not_found")));
            return;
        }

        try
        {
            String userName = user.getName();

            String newPassword = admin.generatePassword();

            String urlGUID = makeGUID(userName, newPassword);

            Map<String, String> userAttributes = new HashMap<String, String>();
            Map<String, String> userInfoMap = user.getInfoMap();
           
            for (Map.Entry<String, String> entry : userInfoMap.entrySet())
            {
                userAttributes.put(entry.getKey(), entry.getValue());
            }
View Full Code Here

            if (request.getRemoteUser() != null)
            {
                // Set the prefered locale to user's perferences(persistent storage) if not anon user
                try
                {
                    User user = userManager.getUser(request.getRemoteUser());
                    // TODO if preferred lang or locale is defined in PLT.D, it's better to use it
                    SecurityAttributes secAttrs = user.getSecurityAttributes();
                    secAttrs.getAttribute(PortalReservedParameters.PREFERED_LOCALE_ATTRIBUTE, true).setStringValue(JetspeedLocale.convertLocaleToString(preferedLocale));
                    userManager.updateUser(user);
                }
                catch (SecurityException e)
                {
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.security.User

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.