Package org.acegisecurity.providers.ldap

Examples of org.acegisecurity.providers.ldap.LdapUserInfo


    //~ Methods ================================================================

    public LdapUserInfo authenticate(String username, String password) {

        // locate the user and check the password
        LdapUserInfo user = null;

        DirContext ctx = getInitialDirContextFactory().newInitialDirContext();
        Iterator dns = getUserDns(username).iterator();

        try {
            while(dns.hasNext() && user == null) {
                String userDn = (String)dns.next();
                String relativeName = LdapUtils.getRelativeName(userDn, ctx);

                user = new LdapUserInfo(userDn,
                        ctx.getAttributes(relativeName, getUserAttributes()));
            }

            if (user == null && getUserSearch() != null) {
                user = getUserSearch().searchForUser(username);
            }

            if (user == null) {
                throw new UsernameNotFoundException(username);
            }

            Attribute passwordAttribute = user.getAttributes().get(passwordAttributeName);

            if(passwordAttribute != null) {
                Object retrievedPassword = passwordAttribute.get();

                if (!(retrievedPassword instanceof String)) {
                    // Assume it's binary
                    retrievedPassword = new String((byte[])retrievedPassword);
                }

                if (!verifyPassword(password, (String)retrievedPassword)) {
                    throw new BadCredentialsException(messages.getMessage(
                            "PasswordComparisonAuthenticator.badCredentials",
                            "Bad credentials"));
                }

            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Password attribute " + passwordAttributeName
                            + " wasn't retrieved for user " + username);
                }

                doPasswordCompare(ctx, user.getRelativeName(ctx), password);
            }

            return user;
        } catch(NamingException ne) {
            throw new BadCredentialsException("Authentication failed due to exception ", ne);
View Full Code Here


          authoritiesPopulator.setGroupRoleAttribute(groupRoleAttribute);
           
            System.out.println("***********************************");
          LdapAuthenticationProvider ldapAuthenticationProvider =
            new LdapAuthenticationProvider(authenticator, authoritiesPopulator);
          LdapUserInfo user = authenticator.authenticate(userDetails.getUsername(),
              (String)authentication.getCredentials());
          if (user != null) {
              UserDetails u = ldapAuthenticationProvider.retrieveUser(userDetails.getUsername(),
                  authentication);         
              System.out.println("user " + u);
View Full Code Here

TOP

Related Classes of org.acegisecurity.providers.ldap.LdapUserInfo

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.