security loginuser
This commit is contained in:
parent
21909c195e
commit
f9cc1fb291
|
|
@ -14,6 +14,7 @@ import com.bonus.auth.form.LoginBody;
|
||||||
import com.bonus.auth.mapper.AuthCustCasualMapper;
|
import com.bonus.auth.mapper.AuthCustCasualMapper;
|
||||||
import com.bonus.auth.service.*;
|
import com.bonus.auth.service.*;
|
||||||
import com.bonus.domain.SmsCodeVerifyDTO;
|
import com.bonus.domain.SmsCodeVerifyDTO;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import com.bonus.utils.AesEncryptUtil;
|
import com.bonus.utils.AesEncryptUtil;
|
||||||
import com.bonus.utils.id.Id;
|
import com.bonus.utils.id.Id;
|
||||||
import com.bonus.utils.SM4EncryptUtils;
|
import com.bonus.utils.SM4EncryptUtils;
|
||||||
|
|
@ -101,7 +102,7 @@ public class TokenController {
|
||||||
if (keys.size() >= concurrency){
|
if (keys.size() >= concurrency){
|
||||||
return R.fail("当前系统用户并发数超过系统配置,请稍后再试");
|
return R.fail("当前系统用户并发数超过系统配置,请稍后再试");
|
||||||
}
|
}
|
||||||
CustInfoAppIdLoginVO loginUser = custLogin(form);
|
LoginUser loginUser = custLogin(form);
|
||||||
Map<String, Object> map = tokenService.createToken(loginUser);
|
Map<String, Object> map = tokenService.createToken(loginUser);
|
||||||
loginUser.setToken((String) map.get(CustTokenService.ACCESS_TOKEN));
|
loginUser.setToken((String) map.get(CustTokenService.ACCESS_TOKEN));
|
||||||
loginUser.setExpireIn((Long) map.get(CustTokenService.EXPIRES_IN));
|
loginUser.setExpireIn((Long) map.get(CustTokenService.EXPIRES_IN));
|
||||||
|
|
@ -109,7 +110,7 @@ public class TokenController {
|
||||||
return R.ok(loginUser);
|
return R.ok(loginUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CustInfoAppIdLoginVO custLogin(LoginBody content) {
|
private LoginUser custLogin(LoginBody content) {
|
||||||
// if (CharSequenceUtil.isNotBlank(content.getMobile())) {
|
// if (CharSequenceUtil.isNotBlank(content.getMobile())) {
|
||||||
// content.setMobile(AesEncryptUtil.aesDecode(content.getMobile()));
|
// content.setMobile(AesEncryptUtil.aesDecode(content.getMobile()));
|
||||||
// }
|
// }
|
||||||
|
|
@ -136,7 +137,7 @@ public class TokenController {
|
||||||
}
|
}
|
||||||
custInfo.setIdCard(SM4EncryptUtils.sm4Encryptbyconfig(content.getIdCard()));
|
custInfo.setIdCard(SM4EncryptUtils.sm4Encryptbyconfig(content.getIdCard()));
|
||||||
}
|
}
|
||||||
CustInfoAppIdLoginVO result = this.custInfoMapper.selectLoginInfo(custInfo);
|
LoginUser result = this.custInfoMapper.selectLoginInfo(custInfo);
|
||||||
if (Objects.isNull(result)) {
|
if (Objects.isNull(result)) {
|
||||||
throw new ServiceException("未找到用户");
|
throw new ServiceException("未找到用户");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -158,7 +159,7 @@ public class TokenController {
|
||||||
System.out.println(flag);
|
System.out.println(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustInfoAppIdLoginVO addOrUpdateCustCasual(Integer sourceType, CustInfoAppIdLoginVO result) {
|
public LoginUser addOrUpdateCustCasual(Integer sourceType, LoginUser result) {
|
||||||
Long custId = result.getCustId();
|
Long custId = result.getCustId();
|
||||||
CustCasual custCasual = this.authCustCasualMapper.selectCustCasualByCustId(custId, sourceType, DelFlagEnum.DEL_FALSE.key());
|
CustCasual custCasual = this.authCustCasualMapper.selectCustCasualByCustId(custId, sourceType, DelFlagEnum.DEL_FALSE.key());
|
||||||
String openid;
|
String openid;
|
||||||
|
|
@ -239,7 +240,7 @@ public class TokenController {
|
||||||
@PostMapping("refresh")
|
@PostMapping("refresh")
|
||||||
public R<?> refresh(HttpServletRequest request) {
|
public R<?> refresh(HttpServletRequest request) {
|
||||||
try {
|
try {
|
||||||
CustInfoAppIdLoginVO loginUser = tokenService.getLoginUser(request);
|
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||||
if (StringUtils.isNotNull(loginUser)) {
|
if (StringUtils.isNotNull(loginUser)) {
|
||||||
tokenService.refreshToken(loginUser);
|
tokenService.refreshToken(loginUser);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@ package com.bonus.auth.mapper;
|
||||||
|
|
||||||
import com.bonus.domain.CustInfo;
|
import com.bonus.domain.CustInfo;
|
||||||
import com.bonus.domain.CustInfoAppIdLoginVO;
|
import com.bonus.domain.CustInfoAppIdLoginVO;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface AuthCustInfoMapper {
|
public interface AuthCustInfoMapper {
|
||||||
CustInfoAppIdLoginVO selectLoginInfo(CustInfo custInfo);
|
LoginUser selectLoginInfo(CustInfo custInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.config.SystemConfig;
|
import com.bonus.config.SystemConfig;
|
||||||
import com.bonus.system.api.RemoteUserService;
|
import com.bonus.system.api.RemoteUserService;
|
||||||
import com.bonus.domain.CustInfoAppIdLoginVO;
|
import com.bonus.domain.CustInfoAppIdLoginVO;
|
||||||
|
import com.bonus.system.api.domain.SysUser;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -67,7 +69,7 @@ public class CustTokenService {
|
||||||
/**
|
/**
|
||||||
* 创建令牌
|
* 创建令牌
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> createToken(CustInfoAppIdLoginVO loginUser) {
|
public Map<String, Object> createToken(LoginUser loginUser) {
|
||||||
// 检查并删除已有的token
|
// 检查并删除已有的token
|
||||||
delExistingToken(loginUser.getCustId());
|
delExistingToken(loginUser.getCustId());
|
||||||
String token = IdUtils.fastUUID();
|
String token = IdUtils.fastUUID();
|
||||||
|
|
@ -119,7 +121,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
public CustInfoAppIdLoginVO getLoginUser() {
|
public LoginUser getLoginUser() {
|
||||||
return getLoginUser(ServletUtils.getRequest());
|
return getLoginUser(ServletUtils.getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +130,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
public CustInfoAppIdLoginVO getLoginUser(HttpServletRequest request) {
|
public LoginUser getLoginUser(HttpServletRequest request) {
|
||||||
// 获取请求携带的令牌
|
// 获取请求携带的令牌
|
||||||
String token = SecurityUtils.getToken(request);
|
String token = SecurityUtils.getToken(request);
|
||||||
return getLoginUser(token);
|
return getLoginUser(token);
|
||||||
|
|
@ -139,8 +141,8 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
public CustInfoAppIdLoginVO getLoginUser(String token) {
|
public LoginUser getLoginUser(String token) {
|
||||||
CustInfoAppIdLoginVO user = null;
|
LoginUser user = null;
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isNotEmpty(token)) {
|
if (StringUtils.isNotEmpty(token)) {
|
||||||
String userkey = JwtUtils.getUserKey(token);
|
String userkey = JwtUtils.getUserKey(token);
|
||||||
|
|
@ -156,7 +158,7 @@ public class CustTokenService {
|
||||||
/**
|
/**
|
||||||
* 设置用户身份信息
|
* 设置用户身份信息
|
||||||
*/
|
*/
|
||||||
public void setLoginUser(CustInfoAppIdLoginVO loginUser) {
|
public void setLoginUser(LoginUser loginUser) {
|
||||||
if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) {
|
if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) {
|
||||||
refreshToken(loginUser);
|
refreshToken(loginUser);
|
||||||
}
|
}
|
||||||
|
|
@ -177,7 +179,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @param loginUser
|
* @param loginUser
|
||||||
*/
|
*/
|
||||||
public void verifyToken(CustInfoAppIdLoginVO loginUser) {
|
public void verifyToken(LoginUser loginUser) {
|
||||||
long expireTime = loginUser.getExpireTime();
|
long expireTime = loginUser.getExpireTime();
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
|
if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
|
||||||
|
|
@ -190,7 +192,7 @@ public class CustTokenService {
|
||||||
*
|
*
|
||||||
* @param loginUser 登录信息
|
* @param loginUser 登录信息
|
||||||
*/
|
*/
|
||||||
public void refreshToken(CustInfoAppIdLoginVO loginUser) {
|
public void refreshToken(LoginUser loginUser) {
|
||||||
long tokenTime = getTokenTime();
|
long tokenTime = getTokenTime();
|
||||||
loginUser.setLoginTime(System.currentTimeMillis());
|
loginUser.setLoginTime(System.currentTimeMillis());
|
||||||
loginUser.setExpireTime(loginUser.getLoginTime() + tokenTime * MILLIS_MINUTE);
|
loginUser.setExpireTime(loginUser.getLoginTime() + tokenTime * MILLIS_MINUTE);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.bonus.auth.mapper.AuthCustInfoMapper">
|
<mapper namespace="com.bonus.auth.mapper.AuthCustInfoMapper">
|
||||||
<!--根据人员id集合获取人员信息-->
|
<!--根据人员id集合获取人员信息-->
|
||||||
<select id="selectLoginInfo" resultType="com.bonus.domain.CustInfoAppIdLoginVO">
|
<select id="selectLoginInfo" resultType="com.bonus.system.api.model.LoginUser">
|
||||||
select cust_id, cust_name, cust_num, cust_photo_url, mobile, pwd
|
select cust_id, cust_name, cust_num, cust_photo_url, mobile, pwd
|
||||||
from cust_info
|
from cust_info
|
||||||
<where>
|
<where>
|
||||||
|
|
|
||||||
Reference in New Issue