R
R
Romanov19812020-10-07 20:09:01
Java
Romanov1981, 2020-10-07 20:09:01

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

1 answer(s)
D
Dmitry Roo, 2020-10-07
@Romanov1981

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 question

Ask a Question

731 491 924 answers to any question