|
|
|
1
|
+package com.zhonglai.luhui.login.config;
|
|
|
|
2
|
+
|
|
|
|
3
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
|
4
|
+import com.zhonglai.luhui.security.dto.BaseLoginUser;
|
|
|
|
5
|
+import com.zhonglai.luhui.security.filter.JwtAuthenticationTokenFilter;
|
|
|
|
6
|
+import com.zhonglai.luhui.security.service.TokenService;
|
|
|
|
7
|
+import com.zhonglai.luhui.security.utils.SecurityUtils;
|
|
|
|
8
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
9
|
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
|
10
|
+import org.springframework.stereotype.Component;
|
|
|
|
11
|
+
|
|
|
|
12
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
13
|
+
|
|
|
|
14
|
+@Component
|
|
|
|
15
|
+public class JwtAuthenticationTokenFilterImpl extends JwtAuthenticationTokenFilter {
|
|
|
|
16
|
+ @Autowired
|
|
|
|
17
|
+ private TokenService tokenService;
|
|
|
|
18
|
+
|
|
|
|
19
|
+ @Override
|
|
|
|
20
|
+ public BaseLoginUser getBaseLoginUser(HttpServletRequest request) {
|
|
|
|
21
|
+ return tokenService.getLoginUser(request);
|
|
|
|
22
|
+ }
|
|
|
|
23
|
+
|
|
|
|
24
|
+ @Override
|
|
|
|
25
|
+ public boolean verifyToken(BaseLoginUser baseLoginUser) {
|
|
|
|
26
|
+ if (StringUtils.isNotNull(baseLoginUser) && StringUtils.isNull(SecurityUtils.getAuthentication()))
|
|
|
|
27
|
+ {
|
|
|
|
28
|
+ tokenService.verifyToken(baseLoginUser);
|
|
|
|
29
|
+ return true;
|
|
|
|
30
|
+ }
|
|
|
|
31
|
+ return false;
|
|
|
|
32
|
+ }
|
|
|
|
33
|
+
|
|
|
|
34
|
+ @Override
|
|
|
|
35
|
+ public UsernamePasswordAuthenticationToken getUsernamePasswordAuthenticationToken(BaseLoginUser loginUser) {
|
|
|
|
36
|
+ return new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
|
|
|
|
37
|
+ }
|
|
|
|
38
|
+} |