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);
}
}
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"))));
}
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"));
}
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");
}
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"));
}
Aggregations