| | |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.redis.template.RedisRepository; |
| | | 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> |
| | |
| | | private RedisRepository redisRepository; |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | @Autowired |
| | | private TokenStore tokenStore; |
| | | |
| | | @Override |
| | | public PageResult<TokenVo> listTokens(Map<String, Object> params, String clientId) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户是否登录; |
| | | * @param map |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultBody getBeforLogin(Map<String, Object> map) { |
| | | String name = MapUtils.getString(map, "name"); |
| | |
| | | if (StringUtils.isBlank(webApp)) { |
| | | return ResultBody.failed("请输入应用id"); |
| | | } |
| | | List<Object> objectList = redisUtils.lGet(SecurityConstants.REDIS_UNAME_TO_ACCESS+webApp+":"+name,0,0 |
| | | ); |
| | | if(objectList!=null){ |
| | | if (objectList.size()>0) { |
| | | return ResultBody.ok().data(false); |
| | | }else { |
| | | //获取token |
| | | Collection<OAuth2AccessToken> tokensByClientIdAndUserName = this.tokenStore.findTokensByClientIdAndUserName(webApp, name); |
| | | List<OAuth2AccessToken> collect = tokensByClientIdAndUserName.stream().collect(Collectors.toList()); |
| | | // 验证token |
| | | if(collect!=null){ |
| | | OAuth2AccessToken oAuth2AccessToken = collect.get(collect.size() - 1); |
| | | if(oAuth2AccessToken.isExpired()){ |
| | | return ResultBody.ok().data(true); |
| | | }else { |
| | | return ResultBody.ok().data(false); |
| | | } |
| | | }else { |
| | | return ResultBody.ok().data(true); |