use of org.springframework.security.core.GrantedAuthority in project spring-security by spring-projects.
the class DefaultLdapAuthoritiesPopulatorTests method defaultRoleIsAssignedWhenSet.
@Test
public void defaultRoleIsAssignedWhenSet() {
populator.setDefaultRole("ROLE_USER");
assertThat(populator.getContextSource()).isSameAs(getContextSource());
DirContextAdapter ctx = new DirContextAdapter(new DistinguishedName("cn=notfound"));
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx, "notfound");
assertThat(authorities).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
}
use of org.springframework.security.core.GrantedAuthority in project spring-security by spring-projects.
the class DefaultLdapAuthoritiesPopulatorTests method nullSearchBaseIsAccepted.
@Test
public void nullSearchBaseIsAccepted() throws Exception {
populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), null);
populator.setDefaultRole("ROLE_USER");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
assertThat(authorities).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
}
use of org.springframework.security.core.GrantedAuthority in project spring-security by spring-projects.
the class DefaultLdapAuthoritiesPopulatorTests method extraRolesAreAdded.
@Test
public void extraRolesAreAdded() throws Exception {
populator = new DefaultLdapAuthoritiesPopulator(getContextSource(), null) {
@Override
protected Set<GrantedAuthority> getAdditionalRoles(DirContextOperations user, String username) {
return new HashSet<GrantedAuthority>(AuthorityUtils.createAuthorityList("ROLE_EXTRA"));
}
};
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
assertThat(authorities).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_EXTRA")).isTrue();
}
use of org.springframework.security.core.GrantedAuthority in project spring-security by spring-projects.
the class NestedLdapAuthoritiesPopulatorTests method testScalaDudeJDevelopersAuthoritiesWithSearchLimit.
@Test
public void testScalaDudeJDevelopersAuthoritiesWithSearchLimit() {
populator.setMaxSearchDepth(1);
DirContextAdapter ctx = new DirContextAdapter("uid=scaladude,ou=people,dc=springframework,dc=org");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx, "scaladude");
assertThat(authorities).hasSize(1);
assertThat(authorities).isEqualTo(Arrays.asList(scalaDevelopers));
}
use of org.springframework.security.core.GrantedAuthority in project spring-security by spring-projects.
the class NestedLdapAuthoritiesPopulatorTests method testJavaDudeJDevelopersAuthorities.
@Test
public void testJavaDudeJDevelopersAuthorities() {
DirContextAdapter ctx = new DirContextAdapter("uid=javadude,ou=people,dc=springframework,dc=org");
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx, "javadude");
assertThat(authorities).hasSize(3);
assertThat(authorities).contains(javaDevelopers);
}
Aggregations