From e1d498a6e753efbc94fe3ea5ffcf92db1e4d9ff3 Mon Sep 17 00:00:00 2001
From: zhaoxiaohao <279049017@qq.com>
Date: Wed, 31 Mar 2021 18:45:00 +0800
Subject: [PATCH] 添加clientid glssz

---
 kidgrow-uaa/kidgrow-uaa-biz/src/main/java/com/kidgrow/oauth2/service/impl/RedisTokensServiceImpl.java |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/kidgrow-uaa/kidgrow-uaa-biz/src/main/java/com/kidgrow/oauth2/service/impl/RedisTokensServiceImpl.java b/kidgrow-uaa/kidgrow-uaa-biz/src/main/java/com/kidgrow/oauth2/service/impl/RedisTokensServiceImpl.java
index 0d931f5..74d1ccc 100644
--- a/kidgrow-uaa/kidgrow-uaa-biz/src/main/java/com/kidgrow/oauth2/service/impl/RedisTokensServiceImpl.java
+++ b/kidgrow-uaa/kidgrow-uaa-biz/src/main/java/com/kidgrow/oauth2/service/impl/RedisTokensServiceImpl.java
@@ -4,20 +4,27 @@
 import cn.hutool.core.util.StrUtil;
 import com.kidgrow.common.constant.SecurityConstants;
 import com.kidgrow.common.model.PageResult;
-import com.kidgrow.redis.template.RedisRepository;
+import com.kidgrow.common.model.ResultBody;
+import com.kidgrow.common.utils.StringUtils;
 import com.kidgrow.oauth2.model.TokenVo;
 import com.kidgrow.oauth2.service.ITokensService;
+import com.kidgrow.redis.template.RedisRepository;
+import com.kidgrow.redis.util.RedisUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
+import org.springframework.security.oauth2.common.OAuth2AccessToken;
 import org.springframework.security.oauth2.provider.OAuth2Authentication;
 import org.springframework.security.oauth2.provider.OAuth2Request;
+import org.springframework.security.oauth2.provider.token.TokenStore;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
@@ -32,6 +39,10 @@
 public class RedisTokensServiceImpl implements ITokensService {
     @Autowired
     private RedisRepository redisRepository;
+    @Autowired
+    private RedisUtils redisUtils;
+    @Autowired
+    private TokenStore tokenStore;
 
     @Override
     public PageResult<TokenVo> listTokens(Map<String, Object> params, String clientId) {
@@ -81,4 +92,36 @@
         }
         return result;
     }
+
+    /**
+     * 获取用户是否登录;
+     * @param map
+     * @return
+     */
+    @Override
+    public ResultBody getBeforLogin(Map<String, Object> map) {
+        String name = MapUtils.getString(map, "name");
+        if (StringUtils.isBlank(name)) {
+            return ResultBody.failed("请输入用户名");
+        }
+        String webApp = MapUtils.getString(map, "webApp");
+        if (StringUtils.isBlank(webApp)) {
+            return ResultBody.failed("请输入应用id");
+        }
+        Collection<OAuth2AccessToken> tokensByClientIdAndUserName = tokenStore.findTokensByClientIdAndUserName(webApp, name);
+        List<OAuth2AccessToken> collect = tokensByClientIdAndUserName.stream().collect(Collectors.toList());
+        if(collect!=null&&collect.size()>0){
+            //获取最后一次token
+            OAuth2AccessToken oAuth2AccessToken = collect.get(collect.size() - 1);
+            //获取最亲的token
+            OAuth2AccessToken oAuth2AccessTokenNew = tokenStore.readAccessToken(oAuth2AccessToken.getValue());
+            if(oAuth2AccessTokenNew!=null&&oAuth2AccessTokenNew.isExpired()){
+                return ResultBody.ok().data(true);
+            }else if (oAuth2AccessTokenNew!=null&&!oAuth2AccessTokenNew.isExpired()){
+                return ResultBody.ok().data(false);
+            }
+            return ResultBody.ok().data(true);
+        }
+        return ResultBody.ok().data(true);
+    }
 }

--
Gitblit v1.8.0