我想要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;
}
答案 0 :(得分:75)
不推荐使用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;
}