Package org.acegisecurity.ldap

Examples of org.acegisecurity.ldap.LdapTemplate


        } catch (FileNotFoundException e) {
            throw new Error("Failed to load "+fileName,e);
        }
        WebApplicationContext appContext = builder.createApplicationContext();

        ldapTemplate = new LdapTemplate(findBean(InitialDirContextFactory.class, appContext));

        return new SecurityComponents(
            findBean(AuthenticationManager.class, appContext),
            new LDAPUserDetailsService(appContext));
    }
View Full Code Here


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

        Iterator dns = getUserDns(username).iterator();

        LdapTemplate ldapTemplate = new LdapTemplate(getInitialDirContextFactory());

        while (dns.hasNext() && (user == null)) {
            final String userDn = (String) dns.next();

            if (ldapTemplate.nameExists(userDn)) {
                LdapUserDetailsImpl.Essence userEssence = (LdapUserDetailsImpl.Essence)
                        ldapTemplate.retrieveEntry(userDn, getUserDetailsMapper(), getUserAttributes());
                userEssence.setUsername(username);
                user = userEssence.createUserDetails();
            }
        }

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

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

        String retrievedPassword = user.getPassword();

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

            return user;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Password attribute wasn't retrieved for user '" + username + "' using mapper "
                + getUserDetailsMapper() + ". Performing LDAP compare of password attribute '" + passwordAttributeName
                + "'");
        }

        String encodedPassword = passwordEncoder.encodePassword(password, null);
        byte[] passwordBytes = LdapUtils.getUtf8Bytes(encodedPassword);

        if (!ldapTemplate.compare(user.getDn(), passwordAttributeName, passwordBytes)) {
            throw new BadCredentialsException(messages.getMessage("PasswordComparisonAuthenticator.badCredentials",
                    "Bad credentials"));
        }

        return user;
View Full Code Here

        return user;
    }

    private LdapUserDetails bindWithDn(String userDn, String username, String password) {
        LdapTemplate template = new LdapTemplate(getInitialDirContextFactory(), userDn, password);

        try {
            LdapUserDetailsImpl.Essence user = (LdapUserDetailsImpl.Essence) template.retrieveEntry(userDn,
                    getUserDetailsMapper(), getUserAttributes());
            user.setUsername(username);
            user.setPassword(password);

            return user.createUserDetails();
View Full Code Here

     */
    private void setInitialDirContextFactory(InitialDirContextFactory initialDirContextFactory) {
        Assert.notNull(initialDirContextFactory, "InitialDirContextFactory must not be null");
        this.initialDirContextFactory = initialDirContextFactory;

        ldapTemplate = new LdapTemplate(initialDirContextFactory);
        ldapTemplate.setSearchControls(searchControls);
    }
View Full Code Here

        if (logger.isDebugEnabled()) {
            logger.debug("Searching for user '" + username + "', with user search "
                + this.toString());
        }

        LdapTemplate template = new LdapTemplate(initialDirContextFactory);

        template.setSearchControls(searchControls);

        try {
            LdapUserDetailsImpl.Essence user = (LdapUserDetailsImpl.Essence) template.searchForSingleEntry(searchBase,
                    searchFilter, new String[] {username}, userDetailsMapper);
            user.setUsername(username);

            return user.createUserDetails();
        } catch (IncorrectResultSizeDataAccessException notFound) {
View Full Code Here

        BeanBuilder builder = new BeanBuilder();
        builder.parse(Hudson.getInstance().servletContext.getResourceAsStream("/WEB-INF/security/LDAPBindSecurityRealm.groovy"),binding);
        WebApplicationContext appContext = builder.createApplicationContext();

        ldapTemplate = new LdapTemplate(findBean(InitialDirContextFactory.class, appContext));

        return new SecurityComponents(
            findBean(AuthenticationManager.class, appContext),
            new LDAPUserDetailsService(appContext));
    }
View Full Code Here

TOP

Related Classes of org.acegisecurity.ldap.LdapTemplate

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.