IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    spring security 4.0 中GrantedAuthorityImpl 类的替换方法

    asuncool@gmail.com(yihaomen)发表于 2015-12-08 10:12:03
    love 0
    今天想把以前用spring security3.0 做的权限管理系统升级到 spring security 4.0, 但在升级过程中出现了一个错误,提示 GrantedAuthorityImpl  这个类 找不到了。  这个类在spring security 3.0  中应该就已经是过时的 了,当时没注意。 以下是替换方法.

    原来的代码
    程序代码 程序代码

    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 4.0 中的代码如下:
    程序代码 程序代码

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



沪ICP备19023445号-2号
友情链接