diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java index c02fe5391..d5756f62c 100644 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/endpoint/PigTokenEndpoint.java @@ -133,7 +133,7 @@ public R logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, requi } String tokenValue = authHeader.replace(OAuth2AccessToken.TokenType.BEARER.getValue(), StrUtil.EMPTY).trim(); - return removeToken(tokenValue); + return removeToken(new String[]{tokenValue}); } /** @@ -170,25 +170,26 @@ public void checkToken(String token, HttpServletResponse response, HttpServletRe * 令牌管理调用 * @param token token */ - @Inner - @DeleteMapping("/{token}") - public R removeToken(@PathVariable("token") String token) { - OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); - if (authorization == null) { - return R.ok(); - } + @DeleteMapping("/delete") + public R removeToken(@RequestBody String[] accessTokens) { + for (String token : accessTokens) { + OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); + if (authorization == null) { + return R.ok(); + } - OAuth2Authorization.Token accessToken = authorization.getAccessToken(); - if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) { - return R.ok(); + OAuth2Authorization.Token accessToken = authorization.getAccessToken(); + if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) { + return R.ok(); + } + // 清空用户信息 + cacheManager.getCache(CacheConstants.USER_DETAILS).evict(authorization.getPrincipalName()); + // 清空access token + authorizationService.remove(authorization); + // 处理自定义退出事件,保存相关日志 + SpringContextHolder.publishEvent(new LogoutSuccessEvent(new PreAuthenticatedAuthenticationToken( + authorization.getPrincipalName(), authorization.getRegisteredClientId()))); } - // 清空用户信息(立即删除) - cacheManager.getCache(CacheConstants.USER_DETAILS).evictIfPresent(authorization.getPrincipalName()); - // 清空access token - authorizationService.remove(authorization); - // 处理自定义退出事件,保存相关日志 - SpringContextHolder.publishEvent(new LogoutSuccessEvent(new PreAuthenticatedAuthenticationToken( - authorization.getPrincipalName(), authorization.getRegisteredClientId()))); return R.ok(); } @@ -197,7 +198,6 @@ public R removeToken(@PathVariable("token") String token) { * @param params 分页参数 * @return */ - @Inner @PostMapping("/page") public R tokenList(@RequestBody Map params) { // 根据分页参数获取对应数据 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysTokenController.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysTokenController.java deleted file mode 100644 index 77c31f03f..000000000 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/SysTokenController.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2018-2025, lengleng All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * Neither the name of the pig4cloud.com developer nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * Author: lengleng (wangiegie@gmail.com) - */ - -package com.pig4cloud.pig.admin.controller; - -import com.pig4cloud.pig.admin.api.feign.RemoteTokenService; -import com.pig4cloud.pig.common.core.constant.SecurityConstants; -import com.pig4cloud.pig.common.core.util.R; -import com.pig4cloud.pig.common.log.annotation.SysLog; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AllArgsConstructor; -import org.springframework.http.HttpHeaders; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -/** - * @author lengleng - * @date 2018/9/4 getTokenPage 管理 - */ -@RestController -@AllArgsConstructor -@RequestMapping("/token") -@Tag(description = "token", name = "令牌管理模块") -@SecurityRequirement(name = HttpHeaders.AUTHORIZATION) -public class SysTokenController { - - private final RemoteTokenService remoteTokenService; - - /** - * 分页token 信息 - * @param params 参数集 - * @return token集合 - */ - @RequestMapping("/page") - public R getTokenPage(@RequestBody Map params) { - return remoteTokenService.getTokenPage(params, SecurityConstants.FROM_IN); - } - - /** - * 删除 - * @param tokens tokens - * @return success/false - */ - @SysLog("删除用户token") - @DeleteMapping("/delete") - @PreAuthorize("@pms.hasPermission('sys_token_del')") - public R removeById(@RequestBody String[] tokens) { - for (String token : tokens) { - remoteTokenService.removeTokenById(token, SecurityConstants.FROM_IN); - } - return R.ok(); - } - -}