...
|
...
|
@@ -18,6 +18,7 @@ import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
...
|
...
|
@@ -32,6 +33,7 @@ import java.util.List; |
|
|
import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@Slf4j
|
|
|
@RequestMapping("/user")
|
|
|
@Api("swaggerDemoController相关的api")
|
|
|
public class UserController {
|
...
|
...
|
@@ -133,16 +135,25 @@ public class UserController { |
|
|
String authHeader = request.getHeader("Authorization");
|
|
|
if (authHeader != null && authHeader.startsWith("Bearer ")) {
|
|
|
final String authToken = authHeader.substring("Bearer ".length());
|
|
|
|
|
|
String username = JwtTokenUtil.parseToken(authToken);
|
|
|
//有JWT 没有登录,去JWT的 信息 获取用户信息,赋予登录
|
|
|
if (username != null) {
|
|
|
UserDetails userDetails = userDetailService.loadUserByUsername(username);
|
|
|
if (userDetails != null) {
|
|
|
String json = JSON.toJSONString(userDetails);
|
|
|
redisUtils.set(authToken, json);
|
|
|
return new ResultJson("200","缓存更新成功");
|
|
|
try {
|
|
|
String userJson = redisUtils.get(authToken);
|
|
|
if (userJson != null) {
|
|
|
USERS u = JSON.parseObject(userJson, USERS.class);
|
|
|
String username = u.getUsername();
|
|
|
|
|
|
// String username = JwtTokenUtil.parseToken(authToken);
|
|
|
if (username != null) {
|
|
|
UserDetails userDetails = userDetailService.loadUserByUsername(username);
|
|
|
if (userDetails != null) {
|
|
|
String json = JSON.toJSONString(userDetails);
|
|
|
redisUtils.set(authToken, json, 3600 * 24 * 7);
|
|
|
return new ResultJson("200", "缓存更新成功");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.error(e.toString());
|
|
|
return new ResultJson("500","缓存更新失败");
|
|
|
}
|
|
|
}
|
|
|
return new ResultJson("500","缓存更新失败");
|
...
|
...
|
|