use of org.springframework.ldap.core.DirContextOperations in project spring-security by spring-projects.
the class FilterBasedLdapUserSearchTests method extraFilterPartToExcludeBob.
// Try some funny business with filters.
@Test
public void extraFilterPartToExcludeBob() {
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(&(cn=*)(!(|(uid={0})(uid=rod)(uid=jerry)(uid=slashguy)(uid=javadude)(uid=groovydude)(uid=closuredude)(uid=scaladude))))", this.contextSource);
// Search for bob, get back ben...
DirContextOperations ben = locator.searchForUser("bob");
assertThat(ben.getStringAttribute("cn")).isEqualTo("Ben Alex");
}
use of org.springframework.ldap.core.DirContextOperations in project spring-security by spring-projects.
the class FilterBasedLdapUserSearchTests method subTreeSearchSucceeds.
@Test
public void subTreeSearchSucceeds() throws Exception {
// Don't set the searchBase, so search from the root.
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("", "(cn={0})", this.contextSource);
locator.setSearchSubtree(true);
DirContextOperations ben = locator.searchForUser("Ben Alex");
assertThat(ben.getStringAttribute("uid")).isEqualTo("ben");
assertThat(ben.getDn()).isEqualTo(new LdapName("uid=ben,ou=people"));
}
use of org.springframework.ldap.core.DirContextOperations in project spring-security by spring-projects.
the class FilterBasedLdapUserSearchTests method basicSearchSucceeds.
@Test
public void basicSearchSucceeds() throws Exception {
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", this.contextSource);
locator.setSearchSubtree(false);
locator.setSearchTimeLimit(0);
locator.setDerefLinkFlag(false);
DirContextOperations bob = locator.searchForUser("bob");
assertThat(bob.getStringAttribute("uid")).isEqualTo("bob");
assertThat(bob.getDn()).isEqualTo(new LdapName("uid=bob,ou=people"));
}
use of org.springframework.ldap.core.DirContextOperations in project spring-security by spring-projects.
the class FilterBasedLdapUserSearchTests method searchForNameWithCommaSucceeds.
@Test
public void searchForNameWithCommaSucceeds() throws Exception {
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", this.contextSource);
locator.setSearchSubtree(false);
DirContextOperations jerry = locator.searchForUser("jerry");
assertThat(jerry.getStringAttribute("uid")).isEqualTo("jerry");
assertThat(jerry.getDn()).isEqualTo(new LdapName("cn=mouse\\, jerry,ou=people"));
}
use of org.springframework.ldap.core.DirContextOperations in project spring-security by spring-projects.
the class LdapBindAuthenticationManagerFactoryITests method authenticationManagerFactoryWhenCustomUserDetailsContextMapperThenUsed.
@Test
public void authenticationManagerFactoryWhenCustomUserDetailsContextMapperThenUsed() throws Exception {
CustomUserDetailsContextMapperConfig.CONTEXT_MAPPER = new UserDetailsContextMapper() {
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
return User.withUsername("other").password("password").roles("USER").build();
}
@Override
public void mapUserToContext(UserDetails user, DirContextAdapter ctx) {
}
};
this.spring.register(CustomUserDetailsContextMapperConfig.class).autowire();
this.mockMvc.perform(formLogin().user("bob").password("bobspassword")).andExpect(authenticated().withUsername("other"));
}
Aggregations