From 3b802fd770bbc7e25438e185e0398ec3232a3418 Mon Sep 17 00:00:00 2001 From: ice_cola <53242048+pangyv@users.noreply.github.com> Date: Sun, 14 Mar 2021 12:46:37 +0800 Subject: [PATCH] fix:A custom permission role does not refresh the DataScope cache after adding subdepartments to a department (#608) --- .../modules/security/service/UserDetailsServiceImpl.java | 7 +++++++ .../modules/system/service/impl/DeptServiceImpl.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java index 33435e1d..c3657d1d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java @@ -27,6 +27,8 @@ import me.zhengjie.modules.system.service.dto.UserDto; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; + +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -41,6 +43,7 @@ public class UserDetailsServiceImpl implements UserDetailsService { private final RoleService roleService; private final DataService dataService; private final LoginProperties loginProperties; + public void setEnableCache(boolean enableCache) { this.loginProperties.setCacheEnable(enableCache); } @@ -58,6 +61,10 @@ public class UserDetailsServiceImpl implements UserDetailsService { JwtUserDto jwtUserDto = null; if (loginProperties.isCacheEnable() && userDtoCache.containsKey(username)) { jwtUserDto = userDtoCache.get(username); + // 检查dataScope是否修改 + List dataScopes = jwtUserDto.getDataScopes(); + dataScopes.clear(); + dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser())); searchDb = false; } if (searchDb) { diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java index 657a6074..75754f3b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java @@ -113,6 +113,8 @@ public class DeptServiceImpl implements DeptService { resources.setSubCount(0); // 清理缓存 updateSubCnt(resources.getPid()); + // 清理自定义角色权限的datascope缓存 + delCaches(resources.getPid()); } @Override