|
@@ -1,10 +1,13 @@
|
|
|
package com.jzg.config;
|
|
package com.jzg.config;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.jzg.commons.constants.RedisKeyConstants;
|
|
|
import com.jzg.commons.constants.SystemConstants;
|
|
import com.jzg.commons.constants.SystemConstants;
|
|
|
import com.jzg.commons.entity.po.SysRoleDataScope;
|
|
import com.jzg.commons.entity.po.SysRoleDataScope;
|
|
|
import com.jzg.commons.entity.po.SysRoleDataScopeLink;
|
|
import com.jzg.commons.entity.po.SysRoleDataScopeLink;
|
|
|
import com.jzg.commons.entity.po.SysSystem;
|
|
import com.jzg.commons.entity.po.SysSystem;
|
|
|
|
|
+import com.jzg.commons.entity.po.SysUserJzgApp;
|
|
|
import com.jzg.commons.entity.vo.SysRoleDataScopeVo;
|
|
import com.jzg.commons.entity.vo.SysRoleDataScopeVo;
|
|
|
import com.jzg.commons.util.MinioUtils;
|
|
import com.jzg.commons.util.MinioUtils;
|
|
|
import com.jzg.commons.util.StringUtils;
|
|
import com.jzg.commons.util.StringUtils;
|
|
@@ -14,6 +17,7 @@ import com.jzg.entity.vo.SysUserJzgVo;
|
|
|
import com.jzg.commons.exception.SystemException;
|
|
import com.jzg.commons.exception.SystemException;
|
|
|
import com.jzg.mapper.SysRoleDataScopeLinkMapper;
|
|
import com.jzg.mapper.SysRoleDataScopeLinkMapper;
|
|
|
import com.jzg.mapper.SysRoleDataScopeMapper;
|
|
import com.jzg.mapper.SysRoleDataScopeMapper;
|
|
|
|
|
+import com.jzg.mapper.SysUserJzgAppMapper;
|
|
|
import com.jzg.service.SysSystemService;
|
|
import com.jzg.service.SysSystemService;
|
|
|
import com.jzg.service.SysUserRoleService;
|
|
import com.jzg.service.SysUserRoleService;
|
|
|
import com.jzg.service.SysUserService;
|
|
import com.jzg.service.SysUserService;
|
|
@@ -26,6 +30,7 @@ import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -47,7 +52,11 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
|
|
|
|
|
|
|
|
private SysRoleDataScopeLinkMapper sysRoleDataScopeLinkMapper;
|
|
private SysRoleDataScopeLinkMapper sysRoleDataScopeLinkMapper;
|
|
|
|
|
|
|
|
- public JzgAuthenticationProvider(UserDetailsService userDetailsService, SysUserService sysUserService, SysUserRoleService sysUserRoleService, RedissonClient redissonClient, SysRoleDataScopeMapper sysRoleDataScopeMapper, SysRoleDataScopeLinkMapper sysRoleDataScopeLinkMapper, SysSystemService sysSystemService) {
|
|
|
|
|
|
|
+ private SysUserJzgAppMapper sysUserJzgAppMapper;
|
|
|
|
|
+
|
|
|
|
|
+ public JzgAuthenticationProvider(UserDetailsService userDetailsService, SysUserService sysUserService, SysUserRoleService sysUserRoleService,
|
|
|
|
|
+ RedissonClient redissonClient, SysRoleDataScopeMapper sysRoleDataScopeMapper, SysRoleDataScopeLinkMapper sysRoleDataScopeLinkMapper,
|
|
|
|
|
+ SysSystemService sysSystemService, SysUserJzgAppMapper sysUserJzgAppMapper) {
|
|
|
this.userDetailsService = userDetailsService;
|
|
this.userDetailsService = userDetailsService;
|
|
|
this.sysUserService = sysUserService;
|
|
this.sysUserService = sysUserService;
|
|
|
this.sysUserRoleService = sysUserRoleService;
|
|
this.sysUserRoleService = sysUserRoleService;
|
|
@@ -55,6 +64,7 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
|
|
|
this.sysRoleDataScopeMapper = sysRoleDataScopeMapper;
|
|
this.sysRoleDataScopeMapper = sysRoleDataScopeMapper;
|
|
|
this.sysRoleDataScopeLinkMapper = sysRoleDataScopeLinkMapper;
|
|
this.sysRoleDataScopeLinkMapper = sysRoleDataScopeLinkMapper;
|
|
|
this.sysSystemService = sysSystemService;
|
|
this.sysSystemService = sysSystemService;
|
|
|
|
|
+ this.sysUserJzgAppMapper = sysUserJzgAppMapper;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -67,15 +77,27 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
|
|
|
String system = ((JzgUsernamePasswordAuthenticationToken)authentication).getSystem();
|
|
String system = ((JzgUsernamePasswordAuthenticationToken)authentication).getSystem();
|
|
|
String captchaId = ((JzgUsernamePasswordAuthenticationToken)authentication).getCaptchaId();
|
|
String captchaId = ((JzgUsernamePasswordAuthenticationToken)authentication).getCaptchaId();
|
|
|
String captcha = ((JzgUsernamePasswordAuthenticationToken)authentication).getCaptcha();
|
|
String captcha = ((JzgUsernamePasswordAuthenticationToken)authentication).getCaptcha();
|
|
|
-
|
|
|
|
|
|
|
+ String smsCode = ((JzgUsernamePasswordAuthenticationToken)authentication).getSmsCode();
|
|
|
|
|
+ boolean isFirst = false;
|
|
|
//调试时注销验证码
|
|
//调试时注销验证码
|
|
|
-// if(Objects.isNull(redissonClient.getBucket(RedisKeyConstants.VERIFICATION_CODE + captchaId).get())){
|
|
|
|
|
-// throw new SystemException("验证码已过期");
|
|
|
|
|
-// }
|
|
|
|
|
-// String systemCaptcha = redissonClient.getBucket(RedisKeyConstants.VERIFICATION_CODE + captchaId).get().toString();
|
|
|
|
|
-// if(!captcha.toLowerCase().equals(systemCaptcha.toLowerCase())){
|
|
|
|
|
-// throw new SystemException("验证码错误,请重新输入");
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ //验证码校验
|
|
|
|
|
+ if(Objects.nonNull(captchaId)) {
|
|
|
|
|
+ if(Objects.isNull(redissonClient.getBucket(RedisKeyConstants.VERIFICATION_CODE + captchaId).get())){
|
|
|
|
|
+ throw new SystemException("验证码已过期");
|
|
|
|
|
+ }
|
|
|
|
|
+ String systemCaptcha = redissonClient.getBucket(RedisKeyConstants.VERIFICATION_CODE + captchaId).get().toString();
|
|
|
|
|
+ if(!captcha.toLowerCase().equals(systemCaptcha.toLowerCase())){
|
|
|
|
|
+ throw new SystemException("验证码错误,请重新输入");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //检验短信验证码
|
|
|
|
|
+ if(Objects.nonNull(smsCode)){
|
|
|
|
|
+ String systemSmsCode = redissonClient.getBucket(RedisKeyConstants.SMS_CODE + system + username).get().toString();
|
|
|
|
|
+ if(!smsCode.equals(systemSmsCode)){
|
|
|
|
|
+ throw new SystemException("短信验证码错误,请重新输入");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
SysSystem sysSystem = sysSystemService.getBySystemCode(system);
|
|
SysSystem sysSystem = sysSystemService.getBySystemCode(system);
|
|
|
if(StringUtils.isNull(sysSystem)){
|
|
if(StringUtils.isNull(sysSystem)){
|
|
@@ -99,7 +121,15 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String name = "",workNumber = "",headSculpture = "";
|
|
String name = "",workNumber = "",headSculpture = "";
|
|
|
- if(!system.equals(SystemConstants.SYSTEM_PLATFORM.getCode())){
|
|
|
|
|
|
|
+ if(system.equals(SystemConstants.SYSTEM_JZG_APP.getCode())){
|
|
|
|
|
+ SysUserJzgApp jzgUserApp = sysUserJzgAppMapper.selectOne(new LambdaQueryWrapper<SysUserJzgApp>().eq(SysUserJzgApp::getUserId, byId.getId()));
|
|
|
|
|
+ if(Objects.isNull(jzgUserApp.getLastLoginTime())){
|
|
|
|
|
+ isFirst = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ //更新用户登录时间
|
|
|
|
|
+ jzgUserApp.setLastLoginTime(LocalDateTime.now());
|
|
|
|
|
+ sysUserJzgAppMapper.updateById(jzgUserApp);
|
|
|
|
|
+ }else if(!system.equals(SystemConstants.SYSTEM_PLATFORM.getCode())){
|
|
|
SysUserJzgVo jzgUserInfo = sysUserService.getJzgUserInfo(byId.getId(),system);
|
|
SysUserJzgVo jzgUserInfo = sysUserService.getJzgUserInfo(byId.getId(),system);
|
|
|
name = jzgUserInfo.getName();
|
|
name = jzgUserInfo.getName();
|
|
|
workNumber = jzgUserInfo.getWorkNumber();
|
|
workNumber = jzgUserInfo.getWorkNumber();
|
|
@@ -120,7 +150,12 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
|
|
|
}
|
|
}
|
|
|
SysUserJzgVo jzgUserInfo = new SysUserJzgVo();
|
|
SysUserJzgVo jzgUserInfo = new SysUserJzgVo();
|
|
|
//获取用户头像
|
|
//获取用户头像
|
|
|
- if(SystemConstants.SYSTEM_PLATFORM.getCode().equals(system)){
|
|
|
|
|
|
|
+ if(SystemConstants.SYSTEM_JZG_APP.getCode().equals(system)){
|
|
|
|
|
+ SysUser user = sysUserService.getById(byId.getId());
|
|
|
|
|
+ if(!Objects.isNull(user.getHeadSculpture()) && !user.getHeadSculpture().isEmpty()) {
|
|
|
|
|
+ jzgUserInfo.setHeadSculpture(MinioUtils.getPresignedObjectUrl("jzg", user.getHeadSculpture()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if(SystemConstants.SYSTEM_PLATFORM.getCode().equals(system)){
|
|
|
SysUser user = sysUserService.getById(byId.getId());
|
|
SysUser user = sysUserService.getById(byId.getId());
|
|
|
if(!Objects.isNull(user.getHeadSculpture()) && !user.getHeadSculpture().isEmpty()) {
|
|
if(!Objects.isNull(user.getHeadSculpture()) && !user.getHeadSculpture().isEmpty()) {
|
|
|
jzgUserInfo.setHeadSculpture(MinioUtils.getPresignedObjectUrl("jzg", user.getHeadSculpture()));
|
|
jzgUserInfo.setHeadSculpture(MinioUtils.getPresignedObjectUrl("jzg", user.getHeadSculpture()));
|
|
@@ -176,6 +211,7 @@ public class JzgAuthenticationProvider implements AuthenticationProvider {
|
|
|
detailMap.put("id",byId.getId());
|
|
detailMap.put("id",byId.getId());
|
|
|
detailMap.put("username",byId.getUsername());
|
|
detailMap.put("username",byId.getUsername());
|
|
|
detailMap.put("headSculpture",jzgUserInfo.getHeadSculpture());
|
|
detailMap.put("headSculpture",jzgUserInfo.getHeadSculpture());
|
|
|
|
|
+ detailMap.put("isFirst",isFirst);
|
|
|
details = detailMap;
|
|
details = detailMap;
|
|
|
|
|
|
|
|
Object finalDetails = details;
|
|
Object finalDetails = details;
|