授权中的角色概念

Role concept in the authorization

我正在写以下内容

public interface SecurityService{

    public Error tryLogin(String usr, String psw);

    public String getRoleCurrentUser(); //Attention here
}

当然,会有一些实现。例如,现在我有

public SpringSecurityService{

     @Autowired
     AuthenticationManager authenticationManager;

     public Error tryLogin(String usr, String psw){
         //Implementation here
     }

     public String getRoleCurrentUser(){
           String role = null;
          //Getting the role of the current user
          //and if the user authorized 
          //assigning it to the role local variable
          return role;
     }
}

SecurityService界面中我使用了角色概念。我的问题是角色概念的使用是否将代码耦合到 spring-安全性?

或者角色概念是一个严格的密码学概念,所以任何负责授权的安全框架都应该理解角色概念。

我强烈建议不要实施您自己的逻辑。只需在 SO 中搜索许多失败的尝试。

有很多框架可以让您实现所需的适当级别的访问控制。有些甚至在评论中提到了。

看看:

  • Spring 安全性
  • Apache Shiro
  • WSO2 IS

这些都是用于身份验证和/或授权的开源解决方案。

在更广泛的层面上,阅读两种流行的授权模型: