Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Mar 20, 2021
2 parents e1c434b + 3b802fd commit e0ea026
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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;

Expand All @@ -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);
}
Expand All @@ -58,6 +61,10 @@ public JwtUserDto loadUserByUsername(String username) {
JwtUserDto jwtUserDto = null;
if (loginProperties.isCacheEnable() && userDtoCache.containsKey(username)) {
jwtUserDto = userDtoCache.get(username);
// 检查dataScope是否修改
List<Long> dataScopes = jwtUserDto.getDataScopes();
dataScopes.clear();
dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
searchDb = false;
}
if (searchDb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public void create(Dept resources) {
resources.setSubCount(0);
// 清理缓存
updateSubCnt(resources.getPid());
// 清理自定义角色权限的datascope缓存
delCaches(resources.getPid());
}

@Override
Expand Down

0 comments on commit e0ea026

Please sign in to comment.