GrantedAuthorityImpl() 类的替代方案

2022-09-01 03:38:30

我想要一个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;
}

答案 1

类 GrantedAuthorityImpl 已被弃用 - 您可以使用 Simple GrantAuthority 代替:

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

答案 2

推荐