Examples of DirContextOperations


Examples of org.springframework.ldap.core.DirContextOperations

                MAIL_ATTRIBUTE_NAME, DISPLAY_NAME_ATTRIBUTE_NAME, "columns_3");
    }

    @Test
    public void testMapUserFromContext_new() throws Exception {
        DirContextOperations ctx = createMock(DirContextOperations.class);

        final String username = "johnldap";
        User user = new UserImpl("123", username);

        expect(userService.getUserByUsername(username)).andReturn(null).once();
        expect(ctx.attributeExists(MAIL_ATTRIBUTE_NAME)).andReturn(true);
        expect(ctx.getStringAttribute(MAIL_ATTRIBUTE_NAME)).andReturn("johnldap@example.com").times(2);
        expect(ctx.attributeExists(DISPLAY_NAME_ATTRIBUTE_NAME)).andReturn(true);
        expect(ctx.getStringAttribute(DISPLAY_NAME_ATTRIBUTE_NAME)).andReturn("John Ldap");
        expect(userService.getUserByUsername(username)).andReturn(user).once();
        expectLastCall();

        replay(userService, ctx);
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        assertEquals(user, userDetails);
    }

    @Test
    public void testMapUserFromContext_new_no_displayname() throws Exception {
        DirContextOperations ctx = createMock(DirContextOperations.class);

        final String username = "johnldap";
        User user = new UserImpl("123", username);

        expect(userService.getUserByUsername(username)).andReturn(null).once();
        expect(ctx.attributeExists(MAIL_ATTRIBUTE_NAME)).andReturn(true);
        expect(ctx.getStringAttribute(MAIL_ATTRIBUTE_NAME)).andReturn("johnldap@example.com").times(2);
        expect(ctx.attributeExists(DISPLAY_NAME_ATTRIBUTE_NAME)).andReturn(false);
        expect(userService.getUserByUsername(username)).andReturn(user).once();
        expectLastCall();

        replay(userService, ctx);
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        assertEquals(user, userDetails);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testMapUserFromContext_new_empty_username() throws Exception {
        DirContextOperations ctx = createMock(DirContextOperations.class);

        final String username = "";

        contextMapper.mapUserFromContext(ctx, username, Collections.<GrantedAuthority>emptyList());
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        assertFalse("Exception thrown", true);
    }

    @Test(expected = RuntimeException.class)
    public void testMapUserFromContext_missing_mail() throws Exception {
        DirContextOperations ctx = createMock(DirContextOperations.class);

        final String username = "johnldap";

        expect(userService.getUserByUsername(username)).andReturn(null).once();
        expect(ctx.attributeExists(MAIL_ATTRIBUTE_NAME)).andReturn(false);

        replay(userService, ctx);

        contextMapper.mapUserFromContext(ctx, username, Collections.<GrantedAuthority>emptyList());
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        assertFalse("Exception thrown", true);
    }

    @Test(expected = RuntimeException.class)
    public void testMapUserFromContext_empty_mail() throws Exception {
        DirContextOperations ctx = createMock(DirContextOperations.class);

        final String username = "johnldap";

        expect(userService.getUserByUsername(username)).andReturn(null).once();
        expect(ctx.attributeExists(MAIL_ATTRIBUTE_NAME)).andReturn(true);
        expect(ctx.getStringAttribute(MAIL_ATTRIBUTE_NAME)).andReturn("").times(1);

        replay(userService, ctx);

        contextMapper.mapUserFromContext(ctx, username, Collections.<GrantedAuthority>emptyList());
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        assertFalse("Exception thrown", true);
    }

    @Test
    public void testMapUserFromContext_existing() throws Exception {
        DirContextOperations ctx = createMock(DirContextOperations.class);

        final String username = "johnldap";
        User user = new UserImpl("123", username);

        expect(userService.getUserByUsername(username)).andReturn(user);
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        return attributes;
    }
   
    public Entity loadEntity(Object providerContext)
    {
        DirContextOperations ctx = (DirContextOperations)((SearchResult)(providerContext)).getObject();
        String entityId = null;
        Entity entity = null;
        String dn = ctx.getNameInNamespace();
        Set<Attribute> attributes = new HashSet<Attribute>();
        Attributes attrs = ctx.getAttributes();
        for (AttributeDef attrDef : searchConfiguration.getEntityAttributeDefinitionsMap().values())
        {
            List<String> values = null;
            values = getStringAttributes(attrs, attrDef.getName(), attrDef.requiresDnDefaultValue());
            if (values != null)
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        this.userSearch = userSearch;
        this.authoritiesPopulator = authoritiesPopulator;
    }

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        DirContextOperations userData = userSearch.searchForUser(username);

        return userDetailsMapper.mapUserFromContext(userData, username,
                authoritiesPopulator.getGrantedAuthorities(userData, username));
    }
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

    public DirContextOperations authenticate(final Authentication authentication) {
        Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,
                "Can only process UsernamePasswordAuthenticationToken objects");
        // locate the user and check the password

        DirContextOperations user = null;
        String username = authentication.getName();
        String password = (String)authentication.getCredentials();

        SpringSecurityLdapTemplate ldapTemplate = new SpringSecurityLdapTemplate(getContextSource());

        for (String userDn : getUserDns(username)) {
            try {
                user = ldapTemplate.retrieveEntry(userDn, getUserAttributes());
            } catch (NameNotFoundException ignore) {
            }
            if (user != null) {
                break;
            }
        }

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

        if (user == null) {
            throw new UsernameNotFoundException("User not found: " + username, username);
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Performing LDAP compare of password attribute '" + passwordAttributeName + "' for user '" +
                    user.getDn() +"'");
        }

        if (usePasswordAttrCompare && isPasswordAttrCompare(user, password)) {
            return user;
        } else if(isLdapPasswordCompare(user, ldapTemplate, password)) {
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

    }

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

    public DirContextOperations authenticate(Authentication authentication) {
        DirContextOperations user = null;
        Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,
                "Can only process UsernamePasswordAuthenticationToken objects");

        String username = authentication.getName();
        String password = (String)authentication.getCredentials();

        if (!StringUtils.hasLength(password)) {
            logger.debug("Rejecting empty password for user " + username);
            throw new BadCredentialsException(messages.getMessage("BindAuthenticator.emptyPassword",
                    "Empty Password"));
        }

        // If DN patterns are configured, try authenticating with them directly
        for (String dn : getUserDns(username)) {
            user = bindWithDn(dn, username, password);

            if (user != null) {
                break;
            }
        }

        // Otherwise use the configured search object to find the user and authenticate with the returned DN.
        if (user == null && getUserSearch() != null) {
            DirContextOperations userFromSearch = getUserSearch().searchForUser(username);
            user = bindWithDn(userFromSearch.getDn().toString(), username, password);
        }

        if (user == null) {
            throw new BadCredentialsException(
                    messages.getMessage("BindAuthenticator.badCredentials", "Bad credentials"));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.