Search in sources :

Example 96 with SimpleGrantedAuthority

use of org.springframework.security.core.authority.SimpleGrantedAuthority in project av-service by dvoraka.

the class BasicUserDetailsService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String username) {
    if ("JOHN".equals(username)) {
        List<GrantedAuthority> authorities = new ArrayList<>();
        authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
        return new User("JOHN", "PASS", true, true, true, true, authorities);
    } else {
        throw new UsernameNotFoundException("User not found: " + username);
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList)

Aggregations

SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)96 GrantedAuthority (org.springframework.security.core.GrantedAuthority)56 Test (org.junit.Test)45 ArrayList (java.util.ArrayList)24 Authentication (org.springframework.security.core.Authentication)23 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)16 HashSet (java.util.HashSet)13 User (org.springframework.security.core.userdetails.User)11 ObjectIdentity (org.springframework.security.acls.model.ObjectIdentity)8 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)7 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)7 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)7 Before (org.junit.Before)6 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)6 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)6 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)6 DBUnitTest (org.orcid.test.DBUnitTest)5 UserDetails (org.springframework.security.core.userdetails.UserDetails)5 HashMap (java.util.HashMap)4