parent
c65a1d735c
commit
762458a1d5
@ -0,0 +1,55 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.auth.realm.strategy.name;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
||||||
|
import cn.estsh.i3plus.pojo.base.shirotoken.AdminToken;
|
||||||
|
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 NameAdminAuthRealm extends AuthorizingRealm {
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger(NameAdminAuthRealm.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISystemLoginService systemLoginService;
|
||||||
|
|
||||||
|
public NameAdminAuthRealm() {
|
||||||
|
//添加支持的token
|
||||||
|
this.setAuthenticationTokenClass(AdminToken.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//权限验证
|
||||||
|
@Override
|
||||||
|
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
|
||||||
|
return new SimpleAuthorizationInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
//令牌确认
|
||||||
|
@Override
|
||||||
|
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||||
|
try {
|
||||||
|
//管理员令牌
|
||||||
|
SessionUser sessionUser = systemLoginService.queryCheckNameAdminLogin((AdminToken) authenticationToken);
|
||||||
|
LOGGER.info("管理员令牌验证:{}", sessionUser);
|
||||||
|
return new SimpleAuthenticationInfo(sessionUser, ((AdminToken) authenticationToken).getLoginName(), this.getName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new AuthenticationException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.auth.realm.strategy.name;
|
||||||
|
|
||||||
|
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 NameSaAuthRealm extends AuthorizingRealm {
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger(NameSaAuthRealm.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISystemLoginService systemLoginService;
|
||||||
|
|
||||||
|
public NameSaAuthRealm() {
|
||||||
|
//添加支持的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.queryCheckNameSaAdminLogin((SaAdminToken) authenticationToken);
|
||||||
|
LOGGER.info("超级管理员令牌验证:{}", sessionUser);
|
||||||
|
return new SimpleAuthenticationInfo(sessionUser, ((SaAdminToken) authenticationToken).getLoginName(), this.getName());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.auth.realm.strategy.name;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description : 验证规则
|
||||||
|
* @Reference :-
|
||||||
|
* @Author : alwaysfrin
|
||||||
|
* @CreateDate : 2018-10-13 14:04
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
public class NameUserAuthRealm extends AuthorizingRealm {
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger(NameUserAuthRealm.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISystemLoginService systemLoginService;
|
||||||
|
|
||||||
|
public NameUserAuthRealm() {
|
||||||
|
//添加支持的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.queryCheckNameUserLogin((UserToken) authenticationToken);
|
||||||
|
LOGGER.info("用户令牌验证:{}", sessionUser);
|
||||||
|
return new SimpleAuthenticationInfo(sessionUser, ((UserToken) authenticationToken).getLoginName(), this.getName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new AuthenticationException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.serviceimpl.base.login.strategy;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginStrategyService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ILicenseClickService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysUserService;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.ServletRequestTool;
|
||||||
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||||
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
||||||
|
import cn.estsh.i3plus.pojo.base.bean.BaseThreadLocal;
|
||||||
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||||
|
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
||||||
|
import cn.estsh.i3plus.pojo.model.platform.SysLoginModel;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
||||||
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
||||||
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
||||||
|
import cn.estsh.impp.framework.boot.util.RedisCacheTool;
|
||||||
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
import static cn.estsh.i3plus.platform.common.util.CommonConstWords.DEFAULT_LANGUAGE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Wynne.Lu
|
||||||
|
* @date 2021/1/18 上午10:53
|
||||||
|
* @desc
|
||||||
|
*/
|
||||||
|
@Lazy
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class NameLoginStrategy implements ISystemLoginStrategyService {
|
||||||
|
|
||||||
|
@Resource(name = "redisCore")
|
||||||
|
protected ImppRedis redisCore;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ILicenseClickService licenseClickService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysUserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISystemLoginService loginService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiFunction<HttpServletRequest, SysLoginModel, ResultBean> login() {
|
||||||
|
return (request, loginModel) -> {
|
||||||
|
licenseClickService.checkLicenseNumberLogin();
|
||||||
|
|
||||||
|
// TODO 后期移除,暂时用于避免自动登录后前台没有正确的传输组织代码信息
|
||||||
|
if ("null".equals(loginModel.getLanguageCode())|| StringUtils.isEmpty(loginModel.getLanguageCode())) {
|
||||||
|
loginModel.setLanguageCode(DEFAULT_LANGUAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置语言代码
|
||||||
|
BaseThreadLocal.setData(BaseThreadLocal.LANGUAGE_CODE, loginModel.getLanguageCode());
|
||||||
|
BaseThreadLocal.setData(PlatformConstWords.AUTH_LOGIN_STRATEGY, ImppEnumUtil.AUTH_LOGIN_STRATEGY.NAME.getCode());
|
||||||
|
|
||||||
|
int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT);
|
||||||
|
if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) {
|
||||||
|
AuthUtil.logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionUser user = userService.loginUser(
|
||||||
|
loginModel.getLoginName().trim(),
|
||||||
|
loginModel.getLoginName().trim(),
|
||||||
|
loginModel.getLanguageCode(),
|
||||||
|
loginService.getLoginPlatform(request).getValue(),
|
||||||
|
loginModel.getDeviceId()
|
||||||
|
);
|
||||||
|
|
||||||
|
String redisKey = CommonConstWords.USER_LOGIN_ERROR + "_" + user.getUser().getId();
|
||||||
|
redisCore.deleteKey(redisKey);
|
||||||
|
|
||||||
|
ResultBean result = new ResultBean(true, AuthUtil.getSession().getId().toString(), AuthUtil.getSessionUser());
|
||||||
|
result.setUrl("/");
|
||||||
|
|
||||||
|
AuthUtil.setOrganize(user.getUser().getOrganize());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue