Search in sources :

Example 1 with DistinguishedName

use of org.springframework.ldap.core.DistinguishedName in project trainning by fernandotomasio.

the class LDAPNetworkGroupDAO method findOrganization.

@Override
public NetworkGroupDTO findOrganization(String uid) throws DAOException {
    NetworkGroupDTO group = null;
    try {
        DistinguishedName dn = new DistinguishedName();
        dn.add("ou", "groups");
        dn.add("ou", APPLICATION_GROUP_BRANCH);
        dn.add("ou", ORGANIZATIONS_GROUP_BRANCH);
        dn.add("cn", uid);
        group = (NetworkGroupDTO) ldapTemplate.lookup(dn, getGroupContextMapper());
    } catch (AuthenticationException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, null, e);
        throw new DAOException(MessageHelper.getMessage("systemUsers.find.error"));
    } catch (org.springframework.ldap.NameNotFoundException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, null, e);
    }
    return group;
}
Also used : NetworkGroupDTO(com.tomasio.projects.trainning.dto.NetworkGroupDTO) DAOException(com.tomasio.projects.trainning.exception.DAOException) DistinguishedName(org.springframework.ldap.core.DistinguishedName) AuthenticationException(org.springframework.ldap.AuthenticationException)

Example 2 with DistinguishedName

use of org.springframework.ldap.core.DistinguishedName in project trainning by fernandotomasio.

the class LDAPNetworkGroupDAO method buildOrganizationsGroupDn.

private Name buildOrganizationsGroupDn(final NetworkGroupDTO group) {
    DistinguishedName dn = new DistinguishedName();
    dn.add("ou", "groups");
    dn.add("ou", APPLICATION_GROUP_BRANCH);
    dn.add("ou", ORGANIZATIONS_GROUP_BRANCH);
    dn.add("cn", group.getNome());
    return dn;
}
Also used : DistinguishedName(org.springframework.ldap.core.DistinguishedName)

Example 3 with DistinguishedName

use of org.springframework.ldap.core.DistinguishedName in project trainning by fernandotomasio.

the class LDAPNetworkUserDAO method buildDn.

private Name buildDn(final NetworkUserDTO user) {
    DistinguishedName dn = new DistinguishedName();
    dn.add("ou", "people");
    dn.add("uid", user.getLogin());
    return dn;
}
Also used : DistinguishedName(org.springframework.ldap.core.DistinguishedName)

Example 4 with DistinguishedName

use of org.springframework.ldap.core.DistinguishedName in project spring-security by spring-projects.

the class SpringSecurityAuthenticationSourceTests method expectedPrincipalIsReturned.

@Test
public void expectedPrincipalIsReturned() {
    LdapUserDetailsImpl.Essence user = new LdapUserDetailsImpl.Essence();
    user.setUsername("joe");
    user.setDn(new DistinguishedName("uid=joe,ou=users"));
    AuthenticationSource source = new SpringSecurityAuthenticationSource();
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(user.createUserDetails(), null));
    assertThat(source.getPrincipal()).isEqualTo("uid=joe,ou=users");
}
Also used : DistinguishedName(org.springframework.ldap.core.DistinguishedName) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) LdapUserDetailsImpl(org.springframework.security.ldap.userdetails.LdapUserDetailsImpl) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) SpringSecurityAuthenticationSource(org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource) AuthenticationSource(org.springframework.ldap.core.AuthenticationSource) Test(org.junit.jupiter.api.Test)

Example 5 with DistinguishedName

use of org.springframework.ldap.core.DistinguishedName in project spring-security by spring-projects.

the class DefaultLdapAuthoritiesPopulatorTests method defaultRoleIsAssignedWhenSet.

@Test
public void defaultRoleIsAssignedWhenSet() {
    this.populator.setDefaultRole("ROLE_USER");
    assertThat(this.populator.getContextSource()).isSameAs(this.contextSource);
    DirContextAdapter ctx = new DirContextAdapter(new DistinguishedName("cn=notfound"));
    Collection<GrantedAuthority> authorities = this.populator.getGrantedAuthorities(ctx, "notfound");
    assertThat(authorities).hasSize(1);
    assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
}
Also used : DistinguishedName(org.springframework.ldap.core.DistinguishedName) GrantedAuthority(org.springframework.security.core.GrantedAuthority) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) Test(org.junit.jupiter.api.Test)

Aggregations

DistinguishedName (org.springframework.ldap.core.DistinguishedName)42 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)28 Test (org.junit.jupiter.api.Test)18 GrantedAuthority (org.springframework.security.core.GrantedAuthority)9 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)5 BasicAttribute (javax.naming.directory.BasicAttribute)4 DirContext (javax.naming.directory.DirContext)4 SearchResult (javax.naming.directory.SearchResult)3 Authentication (org.springframework.security.core.Authentication)3 NetworkGroupDTO (com.tomasio.projects.trainning.dto.NetworkGroupDTO)2 DAOException (com.tomasio.projects.trainning.exception.DAOException)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Attribute (javax.naming.directory.Attribute)2 BasicAttributes (javax.naming.directory.BasicAttributes)2 ModificationItem (javax.naming.directory.ModificationItem)2 SearchControls (javax.naming.directory.SearchControls)2 LdapTemplate (org.springframework.ldap.core.LdapTemplate)2 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2