|
@@ -0,0 +1,49 @@
|
|
|
+package com.dayou.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.dayou.bo.LoginCacheUserBO;
|
|
|
+import com.dayou.constants.JwtConstants;
|
|
|
+import com.dayou.utils.JwtTokenUtil;
|
|
|
+import com.google.common.cache.Cache;
|
|
|
+import io.jsonwebtoken.Claims;
|
|
|
+import io.jsonwebtoken.MalformedJwtException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/auth")
|
|
|
+@Slf4j
|
|
|
+public class AuthController extends BaseController{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("loginCache")
|
|
|
+ private Cache<Long, LoginCacheUserBO> loginCache;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断token是否有效
|
|
|
+ * @param token token
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @PostMapping("/checkOaToken")
|
|
|
+ public Boolean checkOaToken(String token) {
|
|
|
+ // 判断token是否过期(true:有效,false:无效)
|
|
|
+ if (StringUtils.isNotBlank(token)) {
|
|
|
+ try {
|
|
|
+ Claims claims = JwtTokenUtil.getClaimFromToken(token, JwtConstants.SECRET);
|
|
|
+ String subject = claims.getSubject();
|
|
|
+ Long userId = Long.valueOf(subject);
|
|
|
+ return ObjectUtil.isNotNull(loginCache.getIfPresent(userId));
|
|
|
+ }catch (MalformedJwtException exception){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|