From b623970db89ccd9a904248cb3031a4b9b774b10e Mon Sep 17 00:00:00 2001
From: "DESKTOP-BE1EA0I\\14194" <1419499670@qq.com>
Date: Wed, 21 Sep 2022 17:50:01 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E5=90=88jwt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
nladmin-common/pom.xml | 4 +-
.../handler/GlobalExceptionHandler.java | 14 ++++
.../config/bean/SecurityProperties.java | 74 -------------------
.../rest/AuthorizationController.java | 5 +-
.../security/satoken/SaTokenConfigure.java | 14 +++-
.../security/service/OnlineUserService.java | 53 +++++++------
.../service/impl/MonitorServiceImpl.java | 18 +++--
.../main/resources/config/application-dev.yml | 1 +
pom.xml | 10 ++-
9 files changed, 79 insertions(+), 114 deletions(-)
delete mode 100644 nladmin-system/src/main/java/org/nl/modules/security/config/bean/SecurityProperties.java
diff --git a/nladmin-common/pom.xml b/nladmin-common/pom.xml
index 5b0968196..37871f1b2 100644
--- a/nladmin-common/pom.xml
+++ b/nladmin-common/pom.xml
@@ -9,9 +9,11 @@
4.0.0
- 5.3.4
+ 5.7.14
+
+
nladmin-common
公共模块
diff --git a/nladmin-common/src/main/java/org/nl/exception/handler/GlobalExceptionHandler.java b/nladmin-common/src/main/java/org/nl/exception/handler/GlobalExceptionHandler.java
index 878c80447..fc8384044 100644
--- a/nladmin-common/src/main/java/org/nl/exception/handler/GlobalExceptionHandler.java
+++ b/nladmin-common/src/main/java/org/nl/exception/handler/GlobalExceptionHandler.java
@@ -15,6 +15,7 @@
*/
package org.nl.exception.handler;
+import cn.dev33.satoken.exception.NotLoginException;
import lombok.extern.slf4j.Slf4j;
import org.nl.exception.BadRequestException;
import org.nl.exception.EntityExistException;
@@ -59,6 +60,19 @@ public class GlobalExceptionHandler {
// return buildResponseEntity(ApiError.error(message));
// }
+ /**
+ * token 无效的异常拦截
+ * @param e
+ * @return
+ */
+ @ExceptionHandler(value = NotLoginException.class)
+ public ResponseEntity notLoginException(Exception e) {
+// e.printStackTrace();
+ log.error(ThrowableUtil.getStackTrace(e));
+ return buildResponseEntity(ApiError.error("Token 无效"));
+ }
+
+
/**
* 处理自定义异常
*/
diff --git a/nladmin-system/src/main/java/org/nl/modules/security/config/bean/SecurityProperties.java b/nladmin-system/src/main/java/org/nl/modules/security/config/bean/SecurityProperties.java
deleted file mode 100644
index df1d691ef..000000000
--- a/nladmin-system/src/main/java/org/nl/modules/security/config/bean/SecurityProperties.java
+++ /dev/null
@@ -1,74 +0,0 @@
-///*
-// * Copyright 2019-2020 Zheng Jie
-// *
-// * Licensed under the Apache License, Version 2.0 (the "License");
-// * you may not use this file except in compliance with the License.
-// * You may obtain a copy of the License at
-// *
-// * http://www.apache.org/licenses/LICENSE-2.0
-// *
-// * Unless required by applicable law or agreed to in writing, software
-// * distributed under the License is distributed on an "AS IS" BASIS,
-// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// * See the License for the specific language governing permissions and
-// * limitations under the License.
-// */
-//package org.nl.modules.security.config.bean;
-//
-//import lombok.Data;
-//import org.springframework.boot.context.properties.ConfigurationProperties;
-//import org.springframework.context.annotation.Configuration;
-//
-///**
-// * Jwt参数配置
-// *
-// * @author Zheng Jie
-// * @date 2019年11月28日
-// */
-//@Data
-//public class SecurityProperties {
-//
-// /**
-// * Request Headers : Authorization
-// */
-// private String header;
-//
-// /**
-// * 令牌前缀,最后留个空格 Bearer
-// */
-// private String tokenStartWith;
-//
-// /**
-// * 必须使用最少88位的Base64对该令牌进行编码
-// */
-// private String base64Secret;
-//
-// /**
-// * 令牌过期时间 此处单位/毫秒
-// */
-// private Long tokenValidityInSeconds;
-//
-// /**
-// * 在线用户 key,根据 key 查询 redis 中在线用户的数据
-// */
-// private String onlineKey;
-//
-// /**
-// * 验证码 key
-// */
-// private String codeKey;
-//
-// /**
-// * token 续期检查
-// */
-// private Long detect;
-//
-// /**
-// * 续期时间
-// */
-// private Long renew;
-//
-// public String getTokenStartWith() {
-// return tokenStartWith + " ";
-// }
-//}
diff --git a/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java b/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java
index bd68760c4..6f4e058f7 100644
--- a/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java
+++ b/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java
@@ -119,7 +119,7 @@ public class AuthorizationController {
}};
// 保存在线信息
-// onlineUserService.save(jwtUserDto, token, request);
+ onlineUserService.save(userDto, StpUtil.getTokenValue(), request);
return ResponseEntity.ok(authInfo);
}
@@ -160,7 +160,8 @@ public class AuthorizationController {
@AnonymousDeleteMapping(value = "/logout")
public ResponseEntity