From 8a590d5c39f0f8bb1a4bfab427deb9483f780f4b Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 30 三月 2023 09:01:36 +0800
Subject: [PATCH] Merge pull request #800 from yjkhtddx/wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java | 16 +++++++++++++---
1 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java
index 8fdcee1..e50a8b0 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java
@@ -1,7 +1,9 @@
package com.genersoft.iot.vmp.conf.security;
+import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.security.dto.JwtUser;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
@@ -22,12 +24,23 @@
public class JwtAuthenticationFilter extends OncePerRequestFilter {
+ @Autowired
+ private UserSetting userSetting;
+
+
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
// 蹇界暐鐧诲綍璇锋眰鐨則oken楠岃瘉
String requestURI = request.getRequestURI();
if (requestURI.equalsIgnoreCase("/api/user/login")) {
+ chain.doFilter(request, response);
+ return;
+ }
+ if (!userSetting.isInterfaceAuthentication()) {
+ // 鏋勫缓UsernamePasswordAuthenticationToken,杩欓噷瀵嗙爜涓簄ull锛屾槸鍥犱负鎻愪緵浜嗘纭殑JWT,瀹炵幇鑷姩鐧诲綍
+ UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(null, null, new ArrayList<>() );
+ SecurityContextHolder.getContext().setAuthentication(token);
chain.doFilter(request, response);
return;
}
@@ -61,9 +74,6 @@
// return;
default:
}
-
-// String password = SecurityUtils.encryptPassword(jwtUser.getPassword());
-// user.setPassword(password);
// 鏋勫缓UsernamePasswordAuthenticationToken,杩欓噷瀵嗙爜涓簄ull锛屾槸鍥犱负鎻愪緵浜嗘纭殑JWT,瀹炵幇鑷姩鐧诲綍
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, jwtUser.getPassword(), new ArrayList<>() );
--
Gitblit v1.8.0