Answer the question
In order to leave comments, you need to log in
How to pass Authorities with multiple roles?
Greetings dear forum users.
Can you please tell me how to transfer multiple roles?
public class UserDetail implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
return new org.springframework.security.core.userdetails.User("user", "1234",
true, true, true, true, getAuthorities());
}
private Collection<? extends GrantedAuthority> getAuthorities(){
// Тут я возвращаю роль. Как вернуть несколько ролей?
return Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"));
}
}
Answer the question
In order to leave comments, you need to log in
Java 9+
return List.of(new SimpleGrantedAuthority("ROLE_USER1"),
new SimpleGrantedAuthority("ROLE_USER2"),
new SimpleGrantedAuthority("ROLE_USER3"));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question