refactor(permission): 调整缓存逻辑,过滤逻辑

This commit is contained in:
zhansihu 2023-12-26 17:58:26 +08:00
parent d061dbad4d
commit f482b0370f

View File

@ -687,7 +687,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
@Override
public IdentityAuthRes findIdentityAuthMix(IdentityAuthReq req) {
List<IdentityAuthRes.WorkspacePermission> permissions = null;
if (req.isUseCache() || CollectionUtil.isNotEmpty(req.getSpecifyRoleIds())) {
if (!req.isUseCache() || CollectionUtil.isNotEmpty(req.getSpecifyRoleIds())) {
//不走缓存 或者 角色预览
permissions = findIdentityPermission(req);
} else {
@ -703,6 +703,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
|| CollectionUtil.isNotEmpty(req.getFeatureCode())
|| CollectionUtil.isNotEmpty(req.getFeatureId());
if (!needFilter) {
result.setPermissions(permissions);
return result;
}
Set<String> terminals = req.getTerminal() == null ? null : new HashSet<>(req.getTerminal());
@ -728,7 +729,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
//从缓存取权限并记录缓存中没有的OW
List<IdentityAuthReq.WorkspaceOuPair> needQueryPairs = new ArrayList<>();
req.getWorkspaceOusPairs().forEach(ow -> {
String key = KeyUtil.buildKeyBySeparator("auth", req.getIdentityId(), req.getIdentityType(), ow.getOuId(), ow.getWorkspaceId());
String key = KeyUtil.buildKeyBySeparator("auth", req.getIdentityId(), req.getIdentityType().getCode(), ow.getOuId(), ow.getWorkspaceId());
IdentityAuthRes.WorkspacePermission permission = getIdentityAuthFromCache(key);
if (permission == null) {
needQueryPairs.add(ow);
@ -744,7 +745,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
List<IdentityAuthRes.WorkspacePermission> authPermission = findIdentityPermission(req);
permissions.addAll(authPermission);
authPermission.forEach(p -> {
String key = KeyUtil.buildKeyBySeparator("auth", req.getIdentityId(), req.getIdentityType(), p.getOuId(), p.getWorkspaceId());
String key = KeyUtil.buildKeyBySeparator("auth", req.getIdentityId(), req.getIdentityType().getCode(), p.getOuId(), p.getWorkspaceId());
cacheIdentityAuth(key, p);
});
}
@ -754,7 +755,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
private void cacheIdentityAuth(String key, IdentityAuthRes.WorkspacePermission permission) {
RedisUtil.StringOps.setEx(key, JSONObject.toJSONString(permission, SerializerFeature.DisableCircularReferenceDetect),
60L, TimeUnit.MINUTES);
30L, TimeUnit.MINUTES);
}
private IdentityAuthRes.WorkspacePermission getIdentityAuthFromCache(String key) {