Package org.apache.jetspeed.security

Examples of org.apache.jetspeed.security.PasswordCredential


        this.upcpm = upcpm;
    }

    public PasswordCredential getPasswordCredential(User user) throws SecurityException
    {
        PasswordCredential credential = upcsm.getPasswordCredential(user);
        if (!credential.isNew() && upcpm != null)
        {
            if (upcpm.onLoad(credential, user.getName()))
            {
                upcsm.storePasswordCredential(credential);
            }
View Full Code Here


        upcsm.storePasswordCredential(credential);
    }

    public PasswordCredential getAuthenticatedPasswordCredential(String userName, String password) throws SecurityException
    {
        PasswordCredential credential = upcam.getPasswordCredential(userName);
        if (credential == null)
        {
            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
        }
       
        if (upcpm != null)
        {
            if (upcpm.onLoad(credential, userName))
            {
                upcsm.storePasswordCredential(credential);
            }
            if (credential.isEnabled() && !credential.isExpired())
            {
                if (upcpm.authenticate(credential, userName, password))
                {
                    upcsm.storePasswordCredential(credential);
                }
                if (!credential.isEnabled() || credential.isExpired())
                {
                    throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
                }
                else if (credential.getAuthenticationFailures() != 0)
                {
                    throw new SecurityException(SecurityException.INVALID_PASSWORD);
                }
            }
        }
        else
        {
            if (password == null)
            {
                throw new SecurityException(SecurityException.PASSWORD_REQUIRED);
            }
            else if (credential.getPassword() == null || !password.equals(new String(credential.getPassword())))
            {
                throw new SecurityException(SecurityException.INVALID_PASSWORD);
            }
            if (!credential.isEnabled() || credential.isExpired())
            {
                throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
            }
        }
       
        try
        {
            upcam.loadPasswordCredentialUser(credential);
        }
        catch (Exception e)
        {
            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName), e);
        }
       
        if (credential.getUser() == null || !credential.getUser().isEnabled())
        {
            throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
        }
        return credential;
    }
View Full Code Here

        this.um = um;
    }

    public AuthenticatedUser authenticate(String userName, String password) throws SecurityException
    {
        PasswordCredential credential = upcm.getAuthenticatedPasswordCredential(userName, password);
        User user = credential.getUser();
        if (user == null)
        {
            user = um.getUser(credential.getUserName());
        }
        return new AuthenticatedUserImpl(user, new UserCredentialImpl(credential));
    }
View Full Code Here

    {
        try
        {
            // create the user
            User user =  userManager.addUser(userName);
            PasswordCredential pwc = userManager.getPasswordCredential(user);
            pwc.setPassword(null, password);
            userManager.storePasswordCredential(pwc);
                      
            // assign roles to user
            if (roles == null || roles.isEmpty())
            {
View Full Code Here

        Iterator<SSOUser> ruIter = ssoManager.getUsersForSite(s).iterator();
        while (ruIter.hasNext())
        {
            SSOUser ru = ruIter.next();
            PasswordCredential ruCredential = ssoManager.getCredentials(ru);
            if (ruCredential != null)
            {
                String ruName = ru.getName();
                String rupType = null;
                String rupName = null;
                Collection<JetspeedPrincipal> ruPrincipals = ssoManager.getPortalPrincipals(ru);
                if ((ruPrincipals != null) && !ruPrincipals.isEmpty())
                {
                    JetspeedPrincipal rup = ruPrincipals.iterator().next();
                    rupName = rup.getName();
                    if (rup.getType().getName().equals("user"))
                    {
                        rupType = "user";
                    }
                    else if (rup.getType().getName().equals("group"))
                    {
                        rupType = "group";
                    }
                }
                if ((rupName != null) && (rupType != null))
                {
                    String ruPassword = SSOUtils.scramble(ruCredential.getPassword());
                    JSSSOSiteRemoteUser siteRemoteUser = new JSSSOSiteRemoteUser();
                    siteRemoteUser.setPrincipalName(rupName);
                    siteRemoteUser.setPrincipalType(rupType);
                    siteRemoteUser.setUserCredential(ruName, ruPassword.toCharArray());
                    site.addRemoteUser(siteRemoteUser);
View Full Code Here

  public Subject getSubject(User user) throws SecurityException
  {
    if (!getAnonymousUser().equals(user.getName()) && credentialManager != null)
    {
      PasswordCredential pwc = getPasswordCredential(user);
      if (pwc != null)
      {
        UserCredential credential = new UserCredentialImpl(pwc);
        HashSet<Object> privateCred = new HashSet<Object>();
        privateCred.add(credential);
View Full Code Here

                            char [] pwdChars = (pwdString != null ? pwdString.toCharArray() : null);
                            String password = recreatePassword(pwdChars);
                           
                            if (password != null && password.length() > 0)
                            {
                                PasswordCredential pwc = userManager.getPasswordCredential(user);
                                pwc.setPassword(password, (passwordEncoding == JetspeedSerializer.PASSTHRU_REQUIRED));
                                log.debug("storing password for User " + jsuser.getName());
                                userManager.storePasswordCredential(pwc);
                            }
                        }
                        log.debug("add User done ");
                    }
                    if (doPwData)
                    {
                        try
                        {
                            PasswordCredential pwc = userManager.getPasswordCredential(user);
                            pwc.setEnabled(jsuser.getPwDataValueAsBoolean("enabled"));
                            pwc.setUpdateRequired(jsuser.getPwDataValueAsBoolean("requiresUpdate"));
                            java.sql.Date d = jsuser.getPwExpirationDate();
                            if (d != null)
                                pwc.setExpirationDate(d);
                            userManager.storePasswordCredential(pwc);
                        }
                        catch (Exception e)
                        {
                            // most likely caused by protected users (like "guest")
View Full Code Here

                        char [] pwdChars = (pwdString != null ? pwdString.toCharArray() : null);
                        String password = recreatePassword(pwdChars);
                       
                        if (password != null && password.length() > 0)
                        {
                            PasswordCredential pwc = userManager.getPasswordCredential(user);
                            pwc.setPassword(password, (passwordEncoding == JetspeedSerializer.PASSTHRU_REQUIRED));
                            log.debug("storing password for " + jsuser.getName());
                            userManager.storePasswordCredential(pwc);
                        }
                    }
                    log.debug("add User done ");
                }
                if (doPwData)
                {
                    try
                    {
                        PasswordCredential pwc = userManager.getPasswordCredential(user);
                        pwc.setEnabled(jsuser.getPwDataValueAsBoolean("enabled"));
                        pwc.setUpdateRequired(jsuser.getPwDataValueAsBoolean("requiresUpdate"));
                        java.sql.Date d = jsuser.getPwDataValueAsDate("expirationDate");
                        if (d != null)
                            pwc.setExpirationDate(d);
                        userManager.storePasswordCredential(pwc);
                    }
                    catch (Exception e)
                    {
                        // most likely caused by protected users (like "guest")
View Full Code Here

    {
        if (credential == null)
            return;
        if (credential instanceof PasswordCredential)
        {
            PasswordCredential pw = (PasswordCredential) credential;
            char [] pwdChars = (pw.getPassword() != null ? pw.getPassword().toCharArray() : null);
            newPrincipal.setCredential(pw.getUserName(), pwdChars, pw.getExpirationDate(), pw.isEnabled(),
                                      pw.isExpired(), pw.isUpdateRequired());
            return;
        }
        else if (isPublic)
            newPrincipal.addPublicCredential(credential);
        else
View Full Code Here

                if ( password != null && password.trim().length() > 0 )
                {
                    userManager.setPassword(userName, null, password);
                    updated = true;
                }
                PasswordCredential credential = getCredential(userName);
                if ( credential != null )
                {
                    String updateRequiredStr = actionRequest.getParameter("user_cred_updreq");
                    if (updateRequiredStr != null)
                    {
                        boolean updateRequired = Boolean.valueOf(updateRequiredStr).booleanValue();
                        if (updateRequired != credential.isUpdateRequired())
                        {
                            userManager.setPasswordUpdateRequired(userName,updateRequired);
                            updated = true;
                        }
                    }
                    String enabledStr = actionRequest.getParameter("user_cred_enabled");
                    if (enabledStr != null)
                    {
                        boolean enabled = Boolean.valueOf(enabledStr).booleanValue();
                        if (enabled != credential.isEnabled())
                        {
                            userManager.setPasswordEnabled(userName,enabled);
                            updated = true;
                        }
                    }
View Full Code Here

TOP

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

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.