From 3f187634e9d6446fcee3d848dea2a83403a80693 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 2 Mar 2022 12:53:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=84=E7=BB=87=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=BA=A7=E8=81=94=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataease/plugins/server/XAuthServer.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java b/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java index b6e71bdf5f..7538a59e38 100644 --- a/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java +++ b/backend/src/main/java/io/dataease/plugins/server/XAuthServer.java @@ -1,6 +1,5 @@ package io.dataease.plugins.server; - import io.dataease.auth.api.dto.CurrentUserDto; import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.utils.AuthUtils; @@ -20,6 +19,8 @@ import io.dataease.plugins.xpack.auth.service.AuthXpackService; import springfox.documentation.annotations.ApiIgnore; import java.util.*; +import java.util.stream.Collectors; + @ApiIgnore @RequestMapping("/plugin/auth") @RestController @@ -74,11 +75,31 @@ public class XAuthServer { } String authCacheKey = getAuthCacheKey(request); if (StringUtils.isNotBlank(authCacheKey)) { - CacheUtils.remove(authCacheKey, request.getAuthTargetType() + request.getAuthTarget()); + if (StringUtils.equals("dept", request.getAuthTargetType())) { + List authTargets = getAuthModels(request.getAuthTarget(), request.getAuthTargetType(), + user.getUserId(), user.getIsAdmin()); + if (CollectionUtils.isNotEmpty(authTargets)) { + authTargets.forEach(deptId -> { + CacheUtils.remove(authCacheKey, request.getAuthTargetType() + deptId); + }); + } + } else { + CacheUtils.remove(authCacheKey, request.getAuthTargetType() + request.getAuthTarget()); + } + } }); } + private List getAuthModels(String id, String type, Long userId, Boolean isAdmin) { + AuthXpackService sysAuthService = SpringContextUtil.getBean(AuthXpackService.class); + List vAuthModelDTOS = sysAuthService + .searchAuthModelTree(new XpackBaseTreeRequest(id, type, "children"), userId, isAdmin); + List authSources = Optional.ofNullable(vAuthModelDTOS).orElse(new ArrayList<>()).stream() + .map(XpackVAuthModelDTO::getId) + .collect(Collectors.toList()); + return authSources; + } private String getAuthCacheKey(XpackSysAuthRequest request) { if (CollectionUtils.isEmpty(cacheTypes)) {