授权中的java角色概念
我正在写以下内容
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安全性结合起来
或者角色概念是一个严格的脚本概念,因此任何负责授权的安全框架都应该理解角色概念
# 1 楼答案
我强烈建议不要实施你自己的逻辑。只要在这么多失败的尝试中四处搜索就可以了
有很多框架可以让您实现所需的适当级别的访问控制。评论中甚至提到了一些
看看:
这些都是用于身份验证和/或授权的开源解决方案
在更广泛的层面上,阅读两种流行的授权模型: