Commit 56ffd3139a7b7a66370adc0f021cdb74a44bea0f
1 parent
4f6620f4
m
Showing
2 changed files
with
10 additions
and
25 deletions
trash-framework/src/main/java/com/trash/framework/security/filter/JwtAuthenticationTokenFilter.java
| ... | ... | @@ -45,7 +45,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter |
| 45 | 45 | String token = request.getHeader("Authorization"); |
| 46 | 46 | |
| 47 | 47 | if(token == null){ |
| 48 | - token = getTokenFromCookies(request); | |
| 48 | + token = tokenService.getTokenFromCookies(request); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | if(token!= null && !token.equals("undefined")){ |
| ... | ... | @@ -67,17 +67,6 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter |
| 67 | 67 | chain.doFilter(request, response); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - private String getTokenFromCookies(HttpServletRequest request) { | |
| 71 | - | |
| 72 | - for(Cookie cookie : request.getCookies()){ | |
| 73 | - | |
| 74 | - if(("token").equals(cookie.getName())){ | |
| 75 | - return cookie.getValue(); | |
| 76 | - } | |
| 77 | - } | |
| 78 | - | |
| 79 | - return null; | |
| 80 | - } | |
| 81 | 70 | |
| 82 | 71 | private LoginUser requestRemoteUser(String token) { |
| 83 | 72 | return loginService.loginByRemote(token); | ... | ... |
trash-framework/src/main/java/com/trash/framework/web/service/TokenService.java
| ... | ... | @@ -71,25 +71,21 @@ public class TokenService |
| 71 | 71 | LoginUser user = redisCache.getCacheObject(userKey); |
| 72 | 72 | return user; |
| 73 | 73 | } |
| 74 | - | |
| 75 | - token = getTokenFromCookies(request); | |
| 76 | - if(StringUtils.isNotEmpty(token)){ | |
| 77 | - String userKey = getTokenKey(token); | |
| 78 | - LoginUser user = redisCache.getCacheObject(userKey); | |
| 79 | - return user; | |
| 80 | - } | |
| 74 | + | |
| 81 | 75 | return null; |
| 82 | 76 | } |
| 83 | 77 | |
| 84 | 78 | |
| 85 | - private String getTokenFromCookies(HttpServletRequest request) { | |
| 86 | - for(Cookie cookie : request.getCookies()){ | |
| 87 | - | |
| 88 | - if(("token").equals(cookie.getName())){ | |
| 89 | - return cookie.getValue(); | |
| 79 | + public String getTokenFromCookies(HttpServletRequest request) { | |
| 80 | + try { | |
| 81 | + for(Cookie cookie : request.getCookies()){ | |
| 82 | + if(("token").equals(cookie.getName())){ | |
| 83 | + return cookie.getValue(); | |
| 84 | + } | |
| 90 | 85 | } |
| 86 | + } catch (Exception e) { | |
| 87 | + e.printStackTrace(); | |
| 91 | 88 | } |
| 92 | - | |
| 93 | 89 | return null; |
| 94 | 90 | } |
| 95 | 91 | ... | ... |