🐛 Fixing a bug. 令牌管理的查询token 为空, 强制删除token 重构

This commit is contained in:
冷冷 2020-01-27 22:44:57 +08:00
parent 35d7908547
commit 59fe6a3345

View File

@ -120,9 +120,21 @@ public class PigTokenEndpoint {
} }
String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StrUtil.EMPTY).trim(); String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StrUtil.EMPTY).trim();
OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue); return removeToken(tokenValue);
}
/**
* 令牌管理调用
*
* @param token token
* @param from 内部调用标志
*/
@Inner
@DeleteMapping("/{token}")
public R<Boolean> removeToken(@PathVariable("token") String token) {
OAuth2AccessToken accessToken = tokenStore.readAccessToken(token);
if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) { if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) {
return R.ok(Boolean.TRUE, "退出失败token 无效"); return R.failed("删除失败token 无效");
} }
OAuth2Authentication auth2Authentication = tokenStore.readAuthentication(accessToken); OAuth2Authentication auth2Authentication = tokenStore.readAuthentication(accessToken);
@ -136,19 +148,7 @@ public class PigTokenEndpoint {
// 清空 refresh token // 清空 refresh token
OAuth2RefreshToken refreshToken = accessToken.getRefreshToken(); OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
tokenStore.removeRefreshToken(refreshToken); tokenStore.removeRefreshToken(refreshToken);
return R.ok(Boolean.TRUE); return R.ok();
}
/**
* 令牌管理调用
*
* @param token token
* @param from 内部调用标志
*/
@Inner
@DeleteMapping("/{token}")
public R<Boolean> removeToken(@PathVariable("token") String token) {
return R.ok(redisTemplate.delete(CacheConstants.PROJECT_OAUTH_ACCESS + token));
} }
@ -162,15 +162,15 @@ public class PigTokenEndpoint {
@PostMapping("/page") @PostMapping("/page")
public R<Page> tokenList(@RequestBody Map<String, Object> params) { public R<Page> tokenList(@RequestBody Map<String, Object> params) {
//根据分页参数获取对应数据 //根据分页参数获取对应数据
List<String> pages = findKeysForPage(CacheConstants.PROJECT_OAUTH_ACCESS String key = String.format("%sauth_to_access:*", CacheConstants.PROJECT_OAUTH_ACCESS);
, MapUtil.getInt(params, CommonConstants.CURRENT) List<String> pages = findKeysForPage(key, MapUtil.getInt(params, CommonConstants.CURRENT)
, MapUtil.getInt(params, CommonConstants.SIZE)); , MapUtil.getInt(params, CommonConstants.SIZE));
redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
Page result = new Page(MapUtil.getInt(params, CommonConstants.CURRENT), MapUtil.getInt(params, CommonConstants.SIZE)); Page result = new Page(MapUtil.getInt(params, CommonConstants.CURRENT), MapUtil.getInt(params, CommonConstants.SIZE));
result.setRecords(redisTemplate.opsForValue().multiGet(pages)); result.setRecords(redisTemplate.opsForValue().multiGet(pages));
result.setTotal((long) redisTemplate.keys(CacheConstants.PROJECT_OAUTH_ACCESS).size()); result.setTotal((long) redisTemplate.keys(key).size());
return R.ok(result); return R.ok(result);
} }