Skip to content

Commit 9dde37b

Browse files
committed
🐛 Fixing a bug. token endpoint 问题
1 parent 99384b2 commit 9dde37b

File tree

2 files changed

+19
-93
lines changed

2 files changed

+19
-93
lines changed

pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public R<Boolean> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, requi
133133
}
134134

135135
String tokenValue = authHeader.replace(OAuth2AccessToken.TokenType.BEARER.getValue(), StrUtil.EMPTY).trim();
136-
return removeToken(tokenValue);
136+
return removeToken(new String[]{tokenValue});
137137
}
138138

139139
/**
@@ -170,25 +170,26 @@ public void checkToken(String token, HttpServletResponse response, HttpServletRe
170170
* 令牌管理调用
171171
* @param token token
172172
*/
173-
@Inner
174-
@DeleteMapping("/{token}")
175-
public R<Boolean> removeToken(@PathVariable("token") String token) {
176-
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
177-
if (authorization == null) {
178-
return R.ok();
179-
}
173+
@DeleteMapping("/delete")
174+
public R<Boolean> removeToken(@RequestBody String[] accessTokens) {
175+
for (String token : accessTokens) {
176+
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
177+
if (authorization == null) {
178+
return R.ok();
179+
}
180180

181-
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = authorization.getAccessToken();
182-
if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) {
183-
return R.ok();
181+
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = authorization.getAccessToken();
182+
if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) {
183+
return R.ok();
184+
}
185+
// 清空用户信息
186+
cacheManager.getCache(CacheConstants.USER_DETAILS).evict(authorization.getPrincipalName());
187+
// 清空access token
188+
authorizationService.remove(authorization);
189+
// 处理自定义退出事件,保存相关日志
190+
SpringContextHolder.publishEvent(new LogoutSuccessEvent(new PreAuthenticatedAuthenticationToken(
191+
authorization.getPrincipalName(), authorization.getRegisteredClientId())));
184192
}
185-
// 清空用户信息(立即删除)
186-
cacheManager.getCache(CacheConstants.USER_DETAILS).evictIfPresent(authorization.getPrincipalName());
187-
// 清空access token
188-
authorizationService.remove(authorization);
189-
// 处理自定义退出事件,保存相关日志
190-
SpringContextHolder.publishEvent(new LogoutSuccessEvent(new PreAuthenticatedAuthenticationToken(
191-
authorization.getPrincipalName(), authorization.getRegisteredClientId())));
192193
return R.ok();
193194
}
194195

@@ -197,7 +198,6 @@ public R<Boolean> removeToken(@PathVariable("token") String token) {
197198
* @param params 分页参数
198199
* @return
199200
*/
200-
@Inner
201201
@PostMapping("/page")
202202
public R<Page> tokenList(@RequestBody Map<String, Object> params) {
203203
// 根据分页参数获取对应数据

pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysTokenController.java

-74
This file was deleted.

0 commit comments

Comments
 (0)