替代GrantedAuthorityImpl()类

时间:2012-12-26 04:17:23

标签: java spring spring-mvc spring-security

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

1 个答案:

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