解决老师账号同步登录失败问题

main
whb 12 months ago
parent 08b714a960
commit a8f6857cc7

@ -16,7 +16,7 @@ public class Constant {
*/
public static final String BASIC = "Basic";
public static final String SYSTEMNAME = "电商互联网产品开发实系统";
public static final String SYSTEMNAME = "电商互联网产品开发实系统";
public static final String PRO_GYQDGL="供应渠道管理";
public static final String MODULE_CGXQYC="采购需求预测";

@ -17,6 +17,7 @@ import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.annotation.Resource;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -44,11 +45,14 @@ public class AuthenticationFilter extends OncePerRequestFilter {
//
// }
private final TokenProvider tokenProvider;
// private final TokenProvider tokenProvider;
//
// public AuthenticationFilter(TokenProvider tokenProvider) {
// this.tokenProvider = tokenProvider;
// }
public AuthenticationFilter(TokenProvider tokenProvider) {
this.tokenProvider = tokenProvider;
}
@Resource
private TokenProvider tokenProvider;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {

@ -49,8 +49,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// @Value("${item.name}")
// private String itemName;
@Resource
private TokenProvider tokenProvider;
@Autowired
private AuthenticationFilter authenticationFilter;
@Override
@ -66,7 +68,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.sessionRegistry(sessionRegistry()) //可以控制会话的生命周期等。
)
// .addFilterBefore(new AuthenticationFilter(redisUtil), UsernamePasswordAuthenticationFilter.class) //自定义过滤链,认证流程中执行
.addFilterBefore(new AuthenticationFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class) //自定义过滤链,认证流程中执行
.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class) //自定义过滤链,认证流程中执行
.cors().and() //启用跨域资源共享CORS支持
//在响应头中添加 Access-Control-Allow-Headers允许浏览器的跨域请求中携带 Authorization 头部信息,这通常用于传递认证信息(如 JWT token
.headers().addHeaderWriter(new StaticHeadersWriter("Access-Control-Allow-Headers", "Authorization"))

@ -265,7 +265,6 @@ public class IndustryDemandAnalysisController {
jzhyfxStuAnswerMapper.insertSelective(jzhyfxStuAnswer);
Boolean aBoolean = scoreService.insertScore(competitiveEnvDTO.getUserId(), Constant.PRO_SCXQWJ, Constant.MODULE_JZHJFX, BigDecimal.valueOf(100 - count), null);
// scoreService.insertScore(userId, Constant.PRO_GYQDGL, Constant.MODULE_CGXQYC, BigDecimal.valueOf(100 - errorCount), null);
if (aBoolean) {
@ -295,7 +294,6 @@ public class IndustryDemandAnalysisController {
}
@ApiOperation("EXCEL下载数据")
@GetMapping("/downloadExcel")
@AnonymousAccess
@ -322,8 +320,6 @@ public class IndustryDemandAnalysisController {
fileUtil.download(response,"竞争环境分析.xls");
}
}
}

@ -118,7 +118,16 @@ public class LoginController {
}
passWord = jwtUser.getPassword();
userName = jwtUser.getStudentId();
userName = jwtUser.getUsername();
if (StringUtils.isBlank(userName)){
userName = jwtUser.getUsername();
}
if (StringUtils.isBlank(userName)){
userName = jwtUser.getName();
}
if (!org.springframework.util.StringUtils.hasText(passWord)) {
throw new UnAuthorizedException("token 中缺少用户密码信息!");
}
@ -128,18 +137,21 @@ public class LoginController {
if (jwtUser == null) {
throw new UnAuthorizedException("登录失败,用户不存在!");
}
if (jwtUser.getRoleId()==4)
{
Date authorizeTime = jwtUser.getAuthorizeTime();
Date authorizeEndTime = jwtUser.getAuthorizeEndTime();
Date authorizeTime = jwtUser.getAuthorizeTime();
Date authorizeEndTime = jwtUser.getAuthorizeEndTime();
if (authorizeTime == null || authorizeEndTime == null) {
throw new UnAuthorizedException("系统未授权!");
}
if (authorizeTime == null || authorizeEndTime == null) {
throw new UnAuthorizedException("系统未授权!");
Date now = new Date();
if (now.before(authorizeTime) || now.after(authorizeEndTime)) {
throw new UnAuthorizedException("系统授权已过期!");
}
}
Date now = new Date();
if (now.before(authorizeTime) || now.after(authorizeEndTime)) {
throw new UnAuthorizedException("系统授权已过期!");
}
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);

@ -1,5 +1,6 @@
package com.sztzjy.linkCommerce.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.IdUtil;
import com.sztzjy.linkCommerce.entity.*;
@ -82,6 +83,32 @@ public class UserInfoServiceImpl implements UserInfoService {
String password = zyUserInfo.getPassword();
Integer roleId = zyUserInfo.getRoleId();
if (roleId == 3)
{
//查询班级名和班级ID
UserinfoExample userInfoExample = new UserinfoExample();
userInfoExample.createCriteria().andSchoolIdEqualTo(String.valueOf(zyUserInfo.getSchoolId())).andRoleEqualTo(4);
List<Userinfo> userInfos = userInfoMapper.selectByExample(userInfoExample);
if (userInfos.isEmpty() || userInfos==null){
//该学校暂未开通考试账号
zyUserInfo.setClassName(zyUserInfo.getSchoolName()+"-默认班级");
String schoolId = zyUserInfo.getSchoolId().toString() + "00";
zyUserInfo.setClassId(Convert.toInt(schoolId));
}else {
Userinfo userinfo = userInfos.get(0);
String schoolClassId = userinfo.getSchoolClassId();
//根据ClassId去查询班级名
SchoolClass existingClass = schoolClassMapper.selectByPrimaryKey(schoolClassId);
String className = existingClass.getClassName();
zyUserInfo.setClassId(Integer.valueOf(schoolClassId));
zyUserInfo.setClassName(className);
}
}
// 检查用户是否已存在
UserinfoExample userInfoExample = new UserinfoExample();
userInfoExample.createCriteria().andUsernameEqualTo(username);

@ -6,7 +6,7 @@
# username: ${DB_USER:root}
# password: ${DB_PWD:sztzjy2017}
# driver-class-name: com.mysql.cj.jdbc.Driver
#120.79.54.255
spring:
datasource:
druid:

@ -20,11 +20,12 @@ spring:
pathmatch:
matching-strategy: ant_path_matcher
redis:
host: 120.79.54.255
host: localhost
# host: 120.79.54.255
port: 6359
password: tzredis
timeout: 1800000
database: 1
database: 2
jedis:
max-active: 500
max-idle: 50

Loading…
Cancel
Save