Подтвердить что ты не робот

Альтернатива классу GrantedAuthorityImpl()

Я хочу альтернативу GrantedAuthorityImpl() классу. Я хочу это в реализации безопасности spring.  GrantedAuthorityImpl() класс Depricated.hence я хочу альтернативное решение для него.

Мой код:

public Collection<GrantedAuthority> getAuthorities(Integer access) {
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);

    if (access.compareTo(1) == 0) {
        authList.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
    }
    else{
        authList.add(new GrantedAuthorityImpl("ROLE_USER"));
    }
    return authList;
}
4b9b3361

Ответ 1

Класс GrantedAuthorityImpl устарел - вместо этого вы можете использовать SimpleGrantedAuthority:

public Collection<GrantedAuthority> getAuthorities(Integer access) {
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(2);

    if (access.compareTo(1) == 0) {
        authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
    }
    else{
        authList.add(new SimpleGrantedAuthority("ROLE_USER"));
    }
    return authList;
}