|
|
@ -5,12 +5,12 @@ import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.extra.servlet.ServletUtil; |
|
|
|
import com.ccsens.tall.bean.dto.UserDto; |
|
|
|
import com.ccsens.tall.bean.po.SysUser; |
|
|
|
import com.ccsens.tall.bean.vo.UserVo; |
|
|
|
import com.ccsens.tall.exception.UserLoginException; |
|
|
|
import com.ccsens.tall.service.IUserService; |
|
|
|
import com.ccsens.util.JsonResponse; |
|
|
|
import com.ccsens.util.JwtUtil; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.*; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import io.jsonwebtoken.Claims; |
|
|
|
import io.jsonwebtoken.ExpiredJwtException; |
|
|
|
import io.jsonwebtoken.SignatureException; |
|
|
@ -193,8 +193,8 @@ public class UserController { |
|
|
|
@ApiImplicitParams({ |
|
|
|
@ApiImplicitParam(name="token",value = "token",required = true,paramType = "query") |
|
|
|
}) |
|
|
|
@RequestMapping(value = "token",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) |
|
|
|
public JsonResponse<UserVo.TokenToUserId> getNodeMessage(@RequestParam(required = true) String token) throws Exception { |
|
|
|
@RequestMapping(value = "claims",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) |
|
|
|
public JsonResponse<UserVo.TokenToUserId> getNodeMessage(HttpServletRequest request, @RequestParam(required = true) String token) throws Exception { |
|
|
|
//验证token是否有效
|
|
|
|
UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId(); |
|
|
|
Claims claims = null; |
|
|
@ -218,6 +218,43 @@ public class UserController { |
|
|
|
return JsonResponse.newInstance().ok(tokenToUserId); |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation(value = "根据token字符串获取userId",notes = "") |
|
|
|
@ApiImplicitParams({ |
|
|
|
@ApiImplicitParam(name="token",value = "token",required = true,paramType = "query") |
|
|
|
}) |
|
|
|
@RequestMapping(value = "token",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) |
|
|
|
public JsonResponse<UserVo.TokenToUserId> getUserByToken(HttpServletRequest request, @RequestParam(required = true) String token) throws Exception { |
|
|
|
|
|
|
|
UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId(); |
|
|
|
|
|
|
|
// 验证token是否存在
|
|
|
|
String tokenStr = token; |
|
|
|
if (tokenStr == null || !tokenStr.startsWith(WebConstant.HEADER_KEY_TOKEN_PREFIX)) { |
|
|
|
throw new BaseException(CodeEnum.NOT_LOGIN); |
|
|
|
} |
|
|
|
String userToken = tokenStr.substring(WebConstant.HEADER_KEY_TOKEN_PREFIX.length()); |
|
|
|
|
|
|
|
//验证token是否有效
|
|
|
|
Claims claims = null; |
|
|
|
try { |
|
|
|
claims = JwtUtil.parseJWT(userToken, WebConstant.JWT_ACCESS_TOKEN_SECERT); |
|
|
|
}catch(Exception e){ |
|
|
|
throw new BaseException(CodeEnum.NOT_LOGIN); |
|
|
|
} |
|
|
|
//验证用户存根
|
|
|
|
if(userService.tokenNotExistInCache(Long.valueOf(claims.getSubject()))){ |
|
|
|
throw new BaseException(CodeEnum.NOT_LOGIN); |
|
|
|
} |
|
|
|
//验证用户是否禁用
|
|
|
|
SysUser user = userService.getUserById(Long.valueOf(claims.getSubject())); |
|
|
|
if(user.getRecStatus() == WebConstant.REC_STATUS.Disabled.value){ |
|
|
|
throw new BaseException(CodeEnum.NOT_LOGIN); |
|
|
|
} |
|
|
|
|
|
|
|
tokenToUserId.setId(Long.valueOf(claims.getSubject())); |
|
|
|
|
|
|
|
return JsonResponse.newInstance().ok(tokenToUserId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|