use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class LdapUserServiceBeanDefinitionParserTests method rolePrefixIsSupported.
@Test
public void rolePrefixIsSupported() throws Exception {
setContext("<ldap-user-service id='ldapUDS' " + " user-search-filter='(uid={0})' " + " group-search-filter='member={0}' role-prefix='PREFIX_'/>" + "<ldap-user-service id='ldapUDSNoPrefix' " + " user-search-filter='(uid={0})' " + " group-search-filter='member={0}' role-prefix='none'/><ldap-server ldif='classpath:test-server.ldif'/>");
UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
UserDetails ben = uds.loadUserByUsername("ben");
assertThat(AuthorityUtils.authorityListToSet(ben.getAuthorities())).contains("PREFIX_DEVELOPERS");
uds = (UserDetailsService) appCtx.getBean("ldapUDSNoPrefix");
ben = uds.loadUserByUsername("ben");
assertThat(AuthorityUtils.authorityListToSet(ben.getAuthorities())).contains("DEVELOPERS");
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class JdbcDaoImplTests method testDuplicateGroupAuthoritiesAreRemoved.
@Test
public void testDuplicateGroupAuthoritiesAreRemoved() throws Exception {
JdbcDaoImpl dao = makePopulatedJdbcDao();
dao.setEnableAuthorities(false);
dao.setEnableGroups(true);
// Tom has roles A, B, C and B, C duplicates
UserDetails tom = dao.loadUserByUsername("tom");
assertThat(tom.getAuthorities()).hasSize(3);
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class JdbcDaoImplTests method testCheckDaoReturnsCorrectDisabledProperty.
@Test
public void testCheckDaoReturnsCorrectDisabledProperty() throws Exception {
JdbcDaoImpl dao = makePopulatedJdbcDao();
UserDetails user = dao.loadUserByUsername("peter");
assertThat(user.isEnabled()).isFalse();
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class JdbcDaoImplTests method testGroupAuthoritiesAreLoadedCorrectly.
@Test
public void testGroupAuthoritiesAreLoadedCorrectly() throws Exception {
JdbcDaoImpl dao = makePopulatedJdbcDao();
dao.setEnableAuthorities(false);
dao.setEnableGroups(true);
UserDetails jerry = dao.loadUserByUsername("jerry");
assertThat(jerry.getAuthorities()).hasSize(3);
}
use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.
the class CachingUserDetailsService method loadUserByUsername.
public UserDetails loadUserByUsername(String username) {
UserDetails user = userCache.getUserFromCache(username);
if (user == null) {
user = delegate.loadUserByUsername(username);
}
Assert.notNull(user, "UserDetailsService " + delegate + " returned null for username " + username + ". " + "This is an interface contract violation");
userCache.putUserInCache(user);
return user;
}
Aggregations