【问题标题】:alternative to GrantedAuthorityImpl() classGrantedAuthorityImpl() 类的替代方案
【发布时间】:2012-12-11 17:42:48
【问题描述】:

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

【问题讨论】:

  • Spring Security 版本 3.1.3

标签: java spring spring-mvc spring-security


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多