mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
🐛 Fixing a bug. closed #3159 关于uname_to_access_z的疑问
🐛 Fixing a bug. closed #3159 关于uname_to_access_z的疑问
This commit is contained in:
1 parent
f00d7fd59e
commit
c448dbe832
7 files changed
+60
-18
No files matched your search
+10
-14
@@ -2,6 +2,8 @@ package com.pig4cloud.pigx.auth.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteClientDetailsService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.KeyStrResolver;
|
||||
@@ -46,6 +48,8 @@ public class PigxTokenDealServiceImpl {
|
||||
|
||||
private final KeyStrResolver keyStrResolver;
|
||||
|
||||
private final RemoteClientDetailsService clientDetailsService;
|
||||
|
||||
/**
|
||||
* 删除 请求令牌 和 刷新令牌
|
||||
* @param token 请求令牌
|
||||
@@ -81,20 +85,12 @@ public class PigxTokenDealServiceImpl {
|
||||
* @return R
|
||||
*/
|
||||
public R queryTokenByUsername(Page page, String username) {
|
||||
String key = keyStrResolver.extract(
|
||||
SecurityConstants.PIGX_PREFIX + SecurityConstants.OAUTH_PREFIX + "uname_to_access_z:", StrUtil.COLON);
|
||||
|
||||
Object collect = redisTemplate.keys("*:" + username).stream().filter(k -> ((String) k).contains(key))
|
||||
.flatMap(k -> {
|
||||
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
|
||||
return redisTemplate.opsForZSet().range(k, 0, System.currentTimeMillis()).stream();
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (collect instanceof List) {
|
||||
List objSet = (List<?>) collect;
|
||||
page.setRecords(objSet);
|
||||
page.setTotal(objSet.size());
|
||||
}
|
||||
List<OAuth2AccessToken> oAuth2AccessTokenList = clientDetailsService
|
||||
.listClientDetails(SecurityConstants.FROM_IN).getData().stream().map(SysOauthClientDetails::getClientId)
|
||||
.flatMap(clientId -> tokenStore.findTokensByClientIdAndUserName(clientId, username).stream()).distinct()
|
||||
.collect(Collectors.toList());
|
||||
page.setRecords(oAuth2AccessTokenList);
|
||||
page.setTotal(oAuth2AccessTokenList.size());
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -1,9 +1,8 @@
|
||||
package com.pig4cloud.pigx.common.security.serializer;
|
||||
package com.pig4cloud.pigx.common.security.component;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.KeyStrResolver;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxRedisTokenStore;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.pig4cloud.pigx.common.security.component;
|
||||
|
||||
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2021/10/3
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableScheduling
|
||||
@ConditionalOnBean(AuthorizationServerConfigurerAdapter.class)
|
||||
public class PigxTokenStoreCleanSchedule {
|
||||
|
||||
@Scheduled(cron = "@hourly")
|
||||
public void doMaintenance() {
|
||||
PigxRedisTokenStore tokenStore = SpringContextHolder.getBean(PigxRedisTokenStore.class);
|
||||
long maintenance = tokenStore.doMaintenance();
|
||||
log.debug("清理Redis ZADD 过期 token 数量: {}", maintenance);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,8 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.pig4cloud.pigx.common.security.component.PigxTokenEnhancer,\
|
||||
com.pig4cloud.pigx.common.security.component.PigxSecurityInnerAspect,\
|
||||
com.pig4cloud.pigx.common.security.service.PigxUserDetailsServiceImpl,\
|
||||
com.pig4cloud.pigx.common.security.serializer.PigxTokenStoreAutoConfiguration,\
|
||||
com.pig4cloud.pigx.common.security.component.PigxTokenStoreAutoConfiguration,\
|
||||
com.pig4cloud.pigx.common.security.component.PigxTokenStoreCleanSchedule,\
|
||||
com.pig4cloud.pigx.common.security.listener.AuthenticationFailureEventListener,\
|
||||
com.pig4cloud.pigx.common.security.listener.AuthenticationSuccessEventListener,\
|
||||
com.pig4cloud.pigx.common.security.listener.AuthenticationLogoutSuccessEventListener
|
||||
|
||||
+10
@@ -28,6 +28,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/12/05
|
||||
@@ -45,4 +47,12 @@ public interface RemoteClientDetailsService {
|
||||
R<SysOauthClientDetails> getClientDetailsById(@PathVariable("clientId") String clientId,
|
||||
@RequestHeader(SecurityConstants.FROM) String from);
|
||||
|
||||
/**
|
||||
* 查询全部客户端
|
||||
* @param from 调用标识
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/client/list")
|
||||
R<List<SysOauthClientDetails>> listClientDetails(@RequestHeader(SecurityConstants.FROM) String from);
|
||||
|
||||
}
|
||||
+10
@@ -115,4 +115,14 @@ public class SysClientController {
|
||||
Wrappers.<SysOauthClientDetails>lambdaQuery().eq(SysOauthClientDetails::getClientId, clientId), false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部客户端
|
||||
* @return
|
||||
*/
|
||||
@Inner(false)
|
||||
@GetMapping("/list")
|
||||
public R listClients() {
|
||||
return R.ok(clientDetailsService.list());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class TokenFilter implements Filter {
|
||||
|
||||
String method = request.getMethod();
|
||||
|
||||
if (request.getRequestURI().contains("reportDashboard")){
|
||||
if (request.getRequestURI().contains("reportDashboard")) {
|
||||
// 执行
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user