|
@@ -18,6 +18,7 @@ import io.swagger.annotations.Api; |
|
@@ -18,6 +18,7 @@ import io.swagger.annotations.Api; |
18
|
import io.swagger.annotations.ApiImplicitParam;
|
18
|
import io.swagger.annotations.ApiImplicitParam;
|
19
|
import io.swagger.annotations.ApiImplicitParams;
|
19
|
import io.swagger.annotations.ApiImplicitParams;
|
20
|
import io.swagger.annotations.ApiOperation;
|
20
|
import io.swagger.annotations.ApiOperation;
|
|
|
21
|
+import lombok.extern.slf4j.Slf4j;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.security.core.context.SecurityContextHolder;
|
23
|
import org.springframework.security.core.context.SecurityContextHolder;
|
23
|
import org.springframework.security.core.userdetails.UserDetails;
|
24
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
@@ -32,6 +33,7 @@ import java.util.List; |
|
@@ -32,6 +33,7 @@ import java.util.List; |
32
|
import java.util.Map;
|
33
|
import java.util.Map;
|
33
|
|
34
|
|
34
|
@RestController
|
35
|
@RestController
|
|
|
36
|
+@Slf4j
|
35
|
@RequestMapping("/user")
|
37
|
@RequestMapping("/user")
|
36
|
@Api("swaggerDemoController相关的api")
|
38
|
@Api("swaggerDemoController相关的api")
|
37
|
public class UserController {
|
39
|
public class UserController {
|
|
@@ -133,18 +135,27 @@ public class UserController { |
|
@@ -133,18 +135,27 @@ public class UserController { |
133
|
String authHeader = request.getHeader("Authorization");
|
135
|
String authHeader = request.getHeader("Authorization");
|
134
|
if (authHeader != null && authHeader.startsWith("Bearer ")) {
|
136
|
if (authHeader != null && authHeader.startsWith("Bearer ")) {
|
135
|
final String authToken = authHeader.substring("Bearer ".length());
|
137
|
final String authToken = authHeader.substring("Bearer ".length());
|
|
|
138
|
+ try {
|
|
|
139
|
+ String userJson = redisUtils.get(authToken);
|
|
|
140
|
+ if (userJson != null) {
|
|
|
141
|
+ USERS u = JSON.parseObject(userJson, USERS.class);
|
|
|
142
|
+ String username = u.getUsername();
|
136
|
|
143
|
|
137
|
- String username = JwtTokenUtil.parseToken(authToken);
|
|
|
138
|
- //有JWT 没有登录,去JWT的 信息 获取用户信息,赋予登录
|
144
|
+// String username = JwtTokenUtil.parseToken(authToken);
|
139
|
if (username != null) {
|
145
|
if (username != null) {
|
140
|
UserDetails userDetails = userDetailService.loadUserByUsername(username);
|
146
|
UserDetails userDetails = userDetailService.loadUserByUsername(username);
|
141
|
if (userDetails != null) {
|
147
|
if (userDetails != null) {
|
142
|
String json = JSON.toJSONString(userDetails);
|
148
|
String json = JSON.toJSONString(userDetails);
|
143
|
- redisUtils.set(authToken, json);
|
|
|
144
|
- return new ResultJson("200","缓存更新成功");
|
149
|
+ redisUtils.set(authToken, json, 3600 * 24 * 7);
|
|
|
150
|
+ return new ResultJson("200", "缓存更新成功");
|
145
|
}
|
151
|
}
|
146
|
}
|
152
|
}
|
147
|
}
|
153
|
}
|
|
|
154
|
+ }catch (Exception e){
|
|
|
155
|
+ log.error(e.toString());
|
|
|
156
|
+ return new ResultJson("500","缓存更新失败");
|
|
|
157
|
+ }
|
|
|
158
|
+ }
|
148
|
return new ResultJson("500","缓存更新失败");
|
159
|
return new ResultJson("500","缓存更新失败");
|
149
|
}
|
160
|
}
|
150
|
} |
161
|
} |