cn.ocoop.shiro.authc.realm.AbstractAuthorizingRealm Maven / Gradle / Ivy
package cn.ocoop.shiro.authc.realm;
import cn.ocoop.shiro.authc.TokenExtendFace;
import cn.ocoop.shiro.authc.realm.resolves.SubjectResolve;
import cn.ocoop.shiro.authz.SimpleAuthorizationInfoOrdered;
import cn.ocoop.shiro.subject.User;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.SimpleByteSource;
import org.apache.shiro.util.StringUtils;
import org.springframework.util.Assert;
/**
* Created by liolay on 2016/12/6.
*/
public abstract class AbstractAuthorizingRealm extends AuthorizingRealm {
@Override
public boolean supports(AuthenticationToken token) {
return super.supports(token) && TokenExtendFace.class.isAssignableFrom(token.getClass());
}
@Override
public void clearCachedAuthorizationInfo(PrincipalCollection principals) {
super.clearCachedAuthorizationInfo(principals);
}
@Override
public void clearCachedAuthenticationInfo(PrincipalCollection principals) {
super.clearCachedAuthenticationInfo(principals);
}
@Override
public AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
return super.getAuthorizationInfo(principals);
}
@Override
public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Assert.isTrue(getSubjectResolve()!=null , "配置错误,子类请先重写getSubjectResolve");
String username = (String) principals.getPrimaryPrincipal();
SimpleAuthorizationInfoOrdered authorizationInfo = new SimpleAuthorizationInfoOrdered();
authorizationInfo.setRoles(getSubjectResolve().findRoles(username));
authorizationInfo.setStringPermissions(getSubjectResolve().findPermissions(username));
return authorizationInfo;
}
protected SubjectResolve getSubjectResolve() {
return null;
}
private Cache
© 2015 - 2025 Weber Informatics LLC | Privacy Policy