教师端实训操作。代码调整

pull/1/head
陈沅 2 years ago
parent 6895a3b0de
commit e9304484d9

@ -5,6 +5,8 @@ import com.sztzjy.forex.trading_trading.config.Constant;
import com.sztzjy.forex.trading_trading.config.exception.UnAuthorizedException; import com.sztzjy.forex.trading_trading.config.exception.UnAuthorizedException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.AntPathMatcher; import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher; import org.springframework.util.PathMatcher;
@ -17,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -54,7 +57,9 @@ public class AuthenticationFilter extends OncePerRequestFilter {
throw new UnAuthorizedException("令牌错误: 缺失Bearer.."); throw new UnAuthorizedException("令牌错误: 缺失Bearer..");
} }
JwtUser currentUser = TokenProvider.getJWTUser(token); JwtUser currentUser = TokenProvider.getJWTUser(token);
Authentication authentication = new UsernamePasswordAuthenticationToken(currentUser, token == null ? "****" : token, currentUser.getAuthorities()); Authentication authentication = new UsernamePasswordAuthenticationToken(currentUser, token == null ? "****" : token, currentUser.getAuthorities());
request.getUserPrincipal(); request.getUserPrincipal();
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
filterChain.doFilter(request, response); filterChain.doFilter(request, response);

@ -2,24 +2,18 @@ package com.sztzjy.forex.trading_trading.config.security;
import com.sztzjy.forex.trading_trading.config.Constant; import com.sztzjy.forex.trading_trading.config.Constant;
import com.sztzjy.forex.trading_trading.config.exception.UnAuthorizedException; import com.sztzjy.forex.trading_trading.config.exception.UnAuthorizedException;
import com.sztzjy.forex.trading_trading.mappers.RoleAuthorityMapper;
import com.sztzjy.forex.trading_trading.service.RoleAuthorityService;
import io.jsonwebtoken.*; import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.security.Keys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.security.Key; import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.List;
@Component @Component
public class TokenProvider { public class TokenProvider {
@ -55,6 +49,7 @@ public class TokenProvider {
jwtUser.setClassId(Integer.valueOf(claims.get("classId").toString())); jwtUser.setClassId(Integer.valueOf(claims.get("classId").toString()));
jwtUser.setSchoolId(Integer.valueOf(claims.get("schoolId").toString())); jwtUser.setSchoolId(Integer.valueOf(claims.get("schoolId").toString()));
jwtUser.setUsername(claims.get("username").toString()); jwtUser.setUsername(claims.get("username").toString());
jwtUser.setAuthorityCodes((List<String>) claims.get("authorityCodes"));
return jwtUser; return jwtUser;
} catch (Exception e) { } catch (Exception e) {
return null; return null;

@ -20,6 +20,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle; import org.w3c.dom.stylesheets.LinkStyle;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,8 +31,8 @@ import java.util.Map;
@RequiredArgsConstructor @RequiredArgsConstructor
public class TrainingController { public class TrainingController {
TrainingService trainingService; private final TrainingService trainingService;
HttpServletRequest request; private final HttpServletRequest request;
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_ADD) @Permission(codes = PermissionType.TRAINING_MANAGEMENT_ADD)

@ -287,9 +287,10 @@ public class Training extends Base {
long startTime = bo.getStartTime().getTime(); long startTime = bo.getStartTime().getTime();
long endTime = bo.getEndTime().getTime(); long endTime = bo.getEndTime().getTime();
long now = DateTime.now().getTime(); long now = DateTime.now().getTime();
long diff = endTime - startTime;
Assert.isTrue(endTime > now, "结束日期必须大于当前日期"); Assert.isTrue(endTime > now, "结束日期必须大于当前日期");
Assert.isTrue(endTime > startTime, "结束日期必须大于开始日期"); Assert.isTrue(endTime > startTime, "结束日期必须大于开始日期");
Assert.isTrue(diff > 1000 * 60 * 60 * 24 * 1, "实训时间不能小于1天");
training.trainingId = IdUtil.simpleUUID(); training.trainingId = IdUtil.simpleUUID();
training.startTime = bo.getStartTime(); training.startTime = bo.getStartTime();
training.endTime = bo.getEndTime(); training.endTime = bo.getEndTime();

Loading…
Cancel
Save