39

我想要一个 GrantedAuthorityImpl() 类的替代品。我希望在春季安全实施中做到这一点。GrantedAuthorityImpl() 类已弃用。因此,我想要一个替代解决方案。我的代码:

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;
}
4

1 回答 1

79

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;
}
于 2012-12-26T09:08:11.777 回答