Search in sources :

Example 21 with UserDetails

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");
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) LdapUserDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService) Test(org.junit.Test)

Example 22 with UserDetails

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);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) Test(org.junit.Test)

Example 23 with UserDetails

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();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) Test(org.junit.Test)

Example 24 with UserDetails

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);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) Test(org.junit.Test)

Example 25 with UserDetails

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;
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails)

Aggregations

UserDetails (org.springframework.security.core.userdetails.UserDetails)97 Test (org.junit.Test)37 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)32 Authentication (org.springframework.security.core.Authentication)30 GrantedAuthority (org.springframework.security.core.GrantedAuthority)16 User (org.springframework.security.core.userdetails.User)14 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)14 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)9 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)8 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)6 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)6 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)6 User (org.apache.atlas.web.model.User)4 User (org.hisp.dhis.user.User)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)3