单点登录完成
parent
1f2b304968
commit
4193e956ab
@ -0,0 +1,50 @@
|
||||
package cn.estsh.i3plus.core.apiservice.auth.realm.strategy.e9;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
||||
import cn.estsh.i3plus.pojo.base.shirotoken.SaAdminToken;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
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.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @Description : 验证规则
|
||||
* @Reference :
|
||||
* @Author : alwaysfrin
|
||||
* @CreateDate : 2018-10-13 14:04
|
||||
* @Modify:
|
||||
**/
|
||||
public class E9SaAuthRealm extends AuthorizingRealm {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(E9SaAuthRealm.class);
|
||||
|
||||
@Autowired
|
||||
private ISystemLoginService systemLoginService;
|
||||
|
||||
public E9SaAuthRealm() {
|
||||
//添加支持的token
|
||||
this.setAuthenticationTokenClass(SaAdminToken.class);
|
||||
}
|
||||
|
||||
//权限验证
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
|
||||
return new SimpleAuthorizationInfo();
|
||||
}
|
||||
|
||||
//令牌确认
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||
//管理员令牌
|
||||
SessionUser sessionUser = systemLoginService.queryCheckE9SaAdminLogin((SaAdminToken) authenticationToken);
|
||||
LOGGER.info("超级管理员令牌验证:{}", sessionUser);
|
||||
return new SimpleAuthenticationInfo(sessionUser, ((SaAdminToken) authenticationToken).getLoginName(), this.getName());
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package cn.estsh.i3plus.core.apiservice.auth.realm.strategy.e9;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
||||
import cn.estsh.i3plus.pojo.base.shirotoken.AdminToken;
|
||||
import cn.estsh.i3plus.pojo.base.shirotoken.UserToken;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
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.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Description : 验证规则
|
||||
* @Reference :-
|
||||
* @Author : alwaysfrin
|
||||
* @CreateDate : 2018-10-13 14:04
|
||||
* @Modify:
|
||||
**/
|
||||
public class E9UserAuthRealm extends AuthorizingRealm {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(E9UserAuthRealm.class);
|
||||
|
||||
@Autowired
|
||||
private ISystemLoginService systemLoginService;
|
||||
|
||||
public E9UserAuthRealm() {
|
||||
//添加支持的token
|
||||
this.setAuthenticationTokenClass(UserToken.class);
|
||||
}
|
||||
|
||||
//权限验证
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
|
||||
return new SimpleAuthorizationInfo();
|
||||
}
|
||||
|
||||
//令牌确认
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||
try {
|
||||
//管理员令牌
|
||||
SessionUser sessionUser = systemLoginService.queryCheckE9UserLogin((UserToken) authenticationToken);
|
||||
LOGGER.info("用户令牌验证:{}", sessionUser);
|
||||
return new SimpleAuthenticationInfo(sessionUser, ((UserToken) authenticationToken).getLoginName(), this.getName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new AuthenticationException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue