Examples of DirContextOperations


Examples of org.springframework.ldap.core.DirContextOperations

                    "Empty Password"));
        }

        Assert.notNull(password, "Null password was supplied in authentication token");

        DirContextOperations userData = doAuthentication(userToken);

        UserDetails user = userDetailsContextMapper.mapUserFromContext(userData, authentication.getName(),
                    loadUserAuthorities(userData, authentication.getName(), (String)authentication.getCredentials()));

        return createSuccessfulAuthentication(userToken, user);
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

        FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", getContextSource());
        locator.setSearchSubtree(false);
        locator.setSearchTimeLimit(0);
        locator.setDerefLinkFlag(false);

        DirContextOperations bob = locator.searchForUser("bob");
        assertEquals("bob", bob.getStringAttribute("uid"));

        assertEquals(new LdapName("uid=bob,ou=people"), bob.getDn());
    }
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

    @Test
    public void searchForNameWithCommaSucceeds() throws Exception {
        FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", getContextSource());
        locator.setSearchSubtree(false);

        DirContextOperations jerry = locator.searchForUser("jerry");
        assertEquals("jerry", jerry.getStringAttribute("uid"));

        assertEquals(new LdapName("cn=mouse\\, jerry,ou=people"), jerry.getDn());
    }
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

    public void extraFilterPartToExcludeBob() throws Exception {
        FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people",
                "(&(cn=*)(!(|(uid={0})(uid=rod)(uid=jerry)(uid=slashguy)(uid=javadude)(uid=groovydude)(uid=closuredude)(uid=scaladude))))", getContextSource());

        // Search for bob, get back ben...
        DirContextOperations ben = locator.searchForUser("bob");
        assertEquals("Ben Alex", ben.getStringAttribute("cn"));
    }
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

    public void subTreeSearchSucceeds() throws Exception {
        // Don't set the searchBase, so search from the root.
        FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("", "(cn={0})", getContextSource());
        locator.setSearchSubtree(true);

        DirContextOperations ben = locator.searchForUser("Ben Alex");
        assertEquals("ben", ben.getStringAttribute("uid"));

        assertEquals(new LdapName("uid=ben,ou=people"), ben.getDn());
    }
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

    }

    @Test
    public void searchWithDifferentSearchBaseIsSuccessful() throws Exception {
        FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=otherpeople", "(cn={0})", getContextSource());
        DirContextOperations joe = locator.searchForUser("Joe Smeth");
        assertEquals("Joe Smeth", joe.getStringAttribute("cn"));
    }
View Full Code Here

Examples of org.springframework.ldap.core.DirContextOperations

    @Test
    public void testAuthenticationWithCorrectPasswordSucceeds() {
        authenticator.setUserDnPatterns(new String[] {"uid={0},ou=people", "cn={0},ou=people"});

        DirContextOperations user = authenticator.authenticate(bob);
        assertEquals("bob", user.getStringAttribute("uid"));
        authenticator.authenticate(new UsernamePasswordAuthenticationToken("mouse, jerry", "jerryspassword"));
    }
View Full Code Here

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(123L, 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(123L, 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
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.