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

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 BASIC = "Basic";
public static final String SYSTEMNAME = "电商互联网产品开发实系统"; public static final String SYSTEMNAME = "电商互联网产品开发实系统";
public static final String PRO_GYQDGL="供应渠道管理"; public static final String PRO_GYQDGL="供应渠道管理";
public static final String MODULE_CGXQYC="采购需求预测"; public static final String MODULE_CGXQYC="采购需求预测";

@ -17,6 +17,7 @@ import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
import javax.annotation.Resource;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; 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) { @Resource
this.tokenProvider = tokenProvider; private TokenProvider tokenProvider;
}
@Override @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {

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

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

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

@ -1,5 +1,6 @@
package com.sztzjy.linkCommerce.service.impl; package com.sztzjy.linkCommerce.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.UUID; import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.sztzjy.linkCommerce.entity.*; import com.sztzjy.linkCommerce.entity.*;
@ -82,6 +83,32 @@ public class UserInfoServiceImpl implements UserInfoService {
String password = zyUserInfo.getPassword(); String password = zyUserInfo.getPassword();
Integer roleId = zyUserInfo.getRoleId(); 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 userInfoExample = new UserinfoExample();
userInfoExample.createCriteria().andUsernameEqualTo(username); userInfoExample.createCriteria().andUsernameEqualTo(username);

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

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

Loading…
Cancel
Save