Search in sources :

Example 11 with DirContextOperations

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

the class LDAPNetworkGroupDAO method update.

@Override
public void update(NetworkGroupDTO group) throws DAOException {
    try {
        DirContextOperations context = ldapTemplate.lookupContext(group.getId());
        mapToContext(group, context);
        ldapTemplate.modifyAttributes(context);
    } catch (org.springframework.ldap.NameNotFoundException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, null, e);
    }
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations)

Example 12 with DirContextOperations

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

the class LdapBindAuthenticationManagerFactoryITests method ldapAuthenticationProviderCustomLdapAuthoritiesPopulator.

@Test
public void ldapAuthenticationProviderCustomLdapAuthoritiesPopulator() throws Exception {
    CustomAuthoritiesPopulatorConfig.LAP = new DefaultLdapAuthoritiesPopulator(mock(LdapContextSource.class), null) {

        @Override
        protected Set<GrantedAuthority> getAdditionalRoles(DirContextOperations user, String username) {
            return new HashSet<>(AuthorityUtils.createAuthorityList("ROLE_EXTRA"));
        }
    };
    this.spring.register(CustomAuthoritiesPopulatorConfig.class).autowire();
    this.mockMvc.perform(formLogin().user("bob").password("bobspassword")).andExpect(authenticated().withAuthorities(Collections.singleton(new SimpleGrantedAuthority("ROLE_EXTRA"))));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) HashSet(java.util.HashSet) Set(java.util.Set) DirContextOperations(org.springframework.ldap.core.DirContextOperations) DefaultLdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator) Test(org.junit.jupiter.api.Test)

Example 13 with DirContextOperations

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

the class BindAuthenticatorTests method testAuthenticationWithCorrectPasswordSucceeds.

@Test
public void testAuthenticationWithCorrectPasswordSucceeds() {
    this.authenticator.setUserDnPatterns(new String[] { "uid={0},ou=people", "cn={0},ou=people" });
    DirContextOperations user = this.authenticator.authenticate(this.bob);
    assertThat(user.getStringAttribute("uid")).isEqualTo("bob");
    this.authenticator.authenticate(new UsernamePasswordAuthenticationToken("mouse, jerry", "jerryspassword"));
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 14 with DirContextOperations

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

the class FilterBasedLdapUserSearchTests method searchWithDifferentSearchBaseIsSuccessful.

@Test
public void searchWithDifferentSearchBaseIsSuccessful() {
    FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=otherpeople", "(cn={0})", this.contextSource);
    DirContextOperations joe = locator.searchForUser("Joe Smeth");
    assertThat(joe.getStringAttribute("cn")).isEqualTo("Joe Smeth");
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) Test(org.junit.jupiter.api.Test)

Example 15 with DirContextOperations

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

the class FilterBasedLdapUserSearchWithSpacesTests method searchForUserWhenSpacesInBaseDnThenSuccess.

// gh-9742
@Test
public void searchForUserWhenSpacesInBaseDnThenSuccess() throws Exception {
    FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=space cadets", "(uid={0})", this.contextSource);
    locator.setSearchSubtree(false);
    locator.setSearchTimeLimit(0);
    locator.setDerefLinkFlag(false);
    DirContextOperations bob = locator.searchForUser("space cadet");
    assertThat(bob.getStringAttribute("uid")).isEqualTo("space cadet");
    assertThat(bob.getDn()).isEqualTo(new LdapName("uid=space cadet,ou=space cadets"));
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) LdapName(javax.naming.ldap.LdapName) Test(org.junit.jupiter.api.Test)

Aggregations

DirContextOperations (org.springframework.ldap.core.DirContextOperations)89 Name (javax.naming.Name)20 Test (org.junit.jupiter.api.Test)13 Test (org.junit.Test)9 UserDetails (org.springframework.security.core.userdetails.UserDetails)9 HashSet (java.util.HashSet)8 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)8 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)8 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)7 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)7 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)7 LdapConfig (com.thoughtworks.go.config.LdapConfig)6 BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)6 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)6 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 NameNotFoundException (org.springframework.ldap.NameNotFoundException)6 GrantedAuthority (org.springframework.security.core.GrantedAuthority)5 PerunAttribute (cz.metacentrum.perun.ldapc.model.PerunAttribute)4 List (java.util.List)4