|
|
@@ -37,42 +37,42 @@ public class AuthHandlerAspectJ {
|
|
|
|
|
|
@Before("execution(public * cn.seecoder.data.server.controller.*.*(..)) && @annotation(auth)")
|
|
|
public void authCheck(JoinPoint joinPoint, Auth auth) {
|
|
|
- HttpServletRequest httpServletRequest =
|
|
|
- ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes()))
|
|
|
- .getRequest();
|
|
|
- String token = Optional.ofNullable(httpServletRequest.getHeader("Authorization"))
|
|
|
- .orElseThrow(() -> new GlobalException(ErrorCodeEnum.USER_ERROR_A0001));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(jwtSecret)).build();
|
|
|
- JWTVerifier jwtVerifierSys = JWT.require(Algorithm.HMAC256(jwtSysSecret)).build();
|
|
|
-
|
|
|
- DecodedJWT decodedJWT;
|
|
|
-
|
|
|
-
|
|
|
- // token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJza3kiOiJXb0JpU2hlWWFvWGllQnVXYW5MZSEhIn0.QDF9l3beb2vodPMH87adsT4DZL60NU6Zf4uYAxelzg8
|
|
|
- for(UserRole role : auth.roles()) {
|
|
|
- if(role == UserRole.SYS) {
|
|
|
- try {
|
|
|
- decodedJWT = jwtVerifierSys.verify(token);
|
|
|
- String decodedString = decodedJWT.getClaim("sky").asString();
|
|
|
- if (decodedString.equals("WoBiSheYaoXieBuWanLe!!")) return;
|
|
|
- } catch (JWTVerificationException ignored) {}
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- decodedJWT = jwtVerifier.verify(token);
|
|
|
- } catch (JWTVerificationException e) {
|
|
|
- throw new GlobalException(ErrorCodeEnum.USER_ERROR_A0002);
|
|
|
- }
|
|
|
-
|
|
|
- UserInfo userInfo = decodedJWT.getClaim("user_info").as(UserInfo.class);
|
|
|
-
|
|
|
- for (UserRole role : auth.roles()) {
|
|
|
- if (role == userInfo.getRole()) return;
|
|
|
- }
|
|
|
- throw new GlobalException(ErrorCodeEnum.USER_ERROR_A0003);
|
|
|
+// HttpServletRequest httpServletRequest =
|
|
|
+// ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes()))
|
|
|
+// .getRequest();
|
|
|
+// String token = Optional.ofNullable(httpServletRequest.getHeader("Authorization"))
|
|
|
+// .orElseThrow(() -> new GlobalException(ErrorCodeEnum.USER_ERROR_A0001));
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(jwtSecret)).build();
|
|
|
+// JWTVerifier jwtVerifierSys = JWT.require(Algorithm.HMAC256(jwtSysSecret)).build();
|
|
|
+//
|
|
|
+// DecodedJWT decodedJWT;
|
|
|
+//
|
|
|
+//
|
|
|
+// // token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJza3kiOiJXb0JpU2hlWWFvWGllQnVXYW5MZSEhIn0.QDF9l3beb2vodPMH87adsT4DZL60NU6Zf4uYAxelzg8
|
|
|
+// for(UserRole role : auth.roles()) {
|
|
|
+// if(role == UserRole.SYS) {
|
|
|
+// try {
|
|
|
+// decodedJWT = jwtVerifierSys.verify(token);
|
|
|
+// String decodedString = decodedJWT.getClaim("sky").asString();
|
|
|
+// if (decodedString.equals("WoBiSheYaoXieBuWanLe!!")) return;
|
|
|
+// } catch (JWTVerificationException ignored) {}
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// try {
|
|
|
+// decodedJWT = jwtVerifier.verify(token);
|
|
|
+// } catch (JWTVerificationException e) {
|
|
|
+// throw new GlobalException(ErrorCodeEnum.USER_ERROR_A0002);
|
|
|
+// }
|
|
|
+//
|
|
|
+// UserInfo userInfo = decodedJWT.getClaim("user_info").as(UserInfo.class);
|
|
|
+//
|
|
|
+// for (UserRole role : auth.roles()) {
|
|
|
+// if (role == userInfo.getRole()) return;
|
|
|
+// }
|
|
|
+// throw new GlobalException(ErrorCodeEnum.USER_ERROR_A0003);
|
|
|
}
|
|
|
}
|