我正在为RBAC开发一个带有shiro的分布式系统。我不使用Servlet,但是在我的SecurityFilter中有自定义过滤附在Servlet上。
我的问题是,是否有一种方法可以实现来自某些节点(在我的例子中,是分布式系统中的对等节点)的白列表(自动身份验证)请求,而不必经过整个身份验证过程。
发布于 2014-07-09 11:09:55
我们使用一种方法,当我们有一些由系统启动的代码,而不是一个用户,我们使用一个系统用户令牌的想法,我们把它耦合到一个拥有所有权限的用户。你也可以采取类似的方法。我们有一个自定义的领域实现来检查这些情况,因为我们有多个领域,我们需要向令牌注册。如果没有,您只需删除realmName内容即可。
public class SystemAuthenticationToken implements AuthenticationToken {
private String realmName;
public SystemAuthenticationToken(String realmName) {
this.realmName = realmName;
}
public String getRealmName() {
return realmName;
}
@Override
public Object getPrincipal() {
return null;
}
@Override
public Object getCredentials() {
return null;
}
}在我们的自定义领域实现中:
public class OurRealmImpl extends AuthorizingRealm {
@Override
public AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
if (token instanceof SystemAuthenticationToken) {
login = //..get the special login
} else {
login = //..get normal login
}
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(login, realmName);
if (token instanceof SystemAuthenticationToken) {
principalCollection.add(token, realmName);
}
return new SimpleAuthenticationInfo(principalCollection, login.getPasswordHash());
}我们扩展了一个密码匹配器,您需要在安全管理器上设置它:
public class PasswordAndSystemCredentialsMatcher extends PasswordMatcher {
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
if (token instanceof SystemAuthenticationToken){
return true;
}
return super.doCredentialsMatch(token, info);
}然后,安全过滤器将调用登录以设置令牌:
Subject currentUser = SecurityUtils.getSubject();
SystemAuthenticationToken token = new SystemAuthenticationToken(realmName);
currentUser.login(token);这不是你所希望的那么简单,但对我们来说,它完成了任务。
https://stackoverflow.com/questions/24564517
复制相似问题