Package org.springframework.ldap.core

Examples of org.springframework.ldap.core.DistinguishedName


    private void modifyAuthorities(final DistinguishedName userDn, final Collection<? extends GrantedAuthority> authorities, final int modType) {
        template.executeReadWrite(new ContextExecutor() {
            public Object executeWithContext(DirContext ctx) throws NamingException {
                for(GrantedAuthority authority : authorities) {
                    String group = convertAuthorityToGroup(authority);
                    DistinguishedName fullDn = LdapUtils.getFullDn(userDn, ctx);
                    ModificationItem addGroup = new ModificationItem(modType,
                            new BasicAttribute(groupMemberAttributeName, fullDn.toUrl()));

                    ctx.modifyAttributes(buildGroupDn(group), new ModificationItem[] {addGroup});
                }
                return null;
            }
View Full Code Here


    public void setPasswordAttributeName(String passwordAttributeName) {
        this.passwordAttributeName = passwordAttributeName;
    }

    public void setGroupSearchBase(String groupSearchBase) {
        this.groupSearchBase = new DistinguishedName(groupSearchBase);
    }
View Full Code Here

        mapper.setRoleAttributes(new String[] {"userRole", "nonRetrievedAttribute"});

        BasicAttributes attrs = new BasicAttributes();
        attrs.put(new BasicAttribute("userRole", "x"));

        DirContextAdapter ctx = new DirContextAdapter(attrs, new DistinguishedName("cn=someName"));
        ctx.setAttributeValue("uid", "ani");

        LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES);

        assertEquals(1, user.getAuthorities().size());
View Full Code Here

        mapper.setPasswordAttributeName("myappsPassword");
        BasicAttributes attrs = new BasicAttributes();
        attrs.put(new BasicAttribute("myappsPassword", "mypassword".getBytes()));

        DirContextAdapter ctx = new DirContextAdapter(attrs, new DistinguishedName("cn=someName"));
        ctx.setAttributeValue("uid", "ani");

        LdapUserDetails user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES);

        assertEquals("mypassword", user.getPassword());
View Full Code Here

        new LdapUserDetailsService(new MockUserSearch(), null);
    }

    @Test
    public void correctAuthoritiesAreReturned() {
        DirContextAdapter userData = new DirContextAdapter(new DistinguishedName("uid=joe"));

        LdapUserDetailsService service =
                new LdapUserDetailsService(new MockUserSearch(userData), new MockAuthoritiesPopulator());
        service.setUserDetailsMapper(new LdapUserDetailsMapper());
View Full Code Here

        assertTrue(authorities.contains("ROLE_FROM_POPULATOR"));
    }

    @Test
    public void nullPopulatorConstructorReturnsEmptyAuthoritiesList() throws Exception {
        DirContextAdapter userData = new DirContextAdapter(new DistinguishedName("uid=joe"));

        LdapUserDetailsService service = new LdapUserDetailsService(new MockUserSearch(userData));
        UserDetails user = service.loadUserByUsername("doesntmatterwegetjoeanyway");
        assertEquals(0, user.getAuthorities().size());
    }
View Full Code Here

    @Test
    public void mappingBackToContextMatchesOriginalData() {
        DirContextAdapter ctx1 = createUserContext();
        DirContextAdapter ctx2 = new DirContextAdapter();
        ctx1.setAttributeValues("objectclass", new String[] {"top", "person", "organizationalPerson", "inetOrgPerson"});
        ctx2.setDn(new DistinguishedName("ignored=ignored"));
        InetOrgPerson p = (InetOrgPerson) (new InetOrgPerson.Essence(ctx1)).createUserDetails();
        p.populateContext(ctx2);

        assertEquals(ctx1, ctx2);
    }
View Full Code Here

    @Test
    public void copyMatchesOriginalData() {
        DirContextAdapter ctx1 = createUserContext();
        DirContextAdapter ctx2 = new DirContextAdapter();
        ctx2.setDn(new DistinguishedName("ignored=ignored"));
        ctx1.setAttributeValues("objectclass", new String[] {"top", "person", "organizationalPerson", "inetOrgPerson"});
        InetOrgPerson p = (InetOrgPerson) (new InetOrgPerson.Essence(ctx1)).createUserDetails();
        InetOrgPerson p2 = (InetOrgPerson) new InetOrgPerson.Essence(p).createUserDetails();
        p2.populateContext(ctx2);
View Full Code Here

    }

    private DirContextAdapter createUserContext() {
        DirContextAdapter ctx = new DirContextAdapter();

        ctx.setDn(new DistinguishedName("ignored=ignored"));
        ctx.setAttributeValue("uid", "ghengis");
        ctx.setAttributeValue("userPassword", "pillage");
        ctx.setAttributeValue("carLicense", "HORS1");
        ctx.setAttributeValue("cn", "Ghengis Khan");
        ctx.setAttributeValue("description", "Scary");
View Full Code Here

    @Test
    public void defaultRoleIsAssignedWhenSet() {
        populator.setDefaultRole("ROLE_USER");
        assertSame(getContextSource(), populator.getContextSource());

        DirContextAdapter ctx = new DirContextAdapter(new DistinguishedName("cn=notfound"));

        Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx, "notfound");
        assertEquals(1, authorities.size());
        assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
    }
View Full Code Here

TOP

Related Classes of org.springframework.ldap.core.DistinguishedName

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.