feat:(REQ-2720) 增加权限查询db的开关

This commit is contained in:
lilong 2024-08-01 10:42:24 +08:00
parent 9e49be1100
commit 98f76501b9
3 changed files with 47 additions and 7 deletions

View File

@ -66,4 +66,10 @@ public interface TyrSaasAuthService {
* @return
*/
boolean authNewPermission(PermissionCheckReq req);
/**
* 增加统一的开关权限是否从数据库查询
* @return
*/
boolean permissionFromDB();
}

View File

@ -119,6 +119,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
private final WorkspaceProductService workspaceProductService;
private final RoleSaasFeatureResourceCacheService roleSaasFeatureResourceCacheService;
private final ProductSaasFeatureResourceCacheService productSaasFeatureResourceCacheService;
private final TyrSaasAuthService tyrSaasAuthService;
@Qualifier("authExecutor")
@ -436,17 +437,13 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
return workspaceProductService.listWorkspaceProduct(workspaceProductParam);
}
@Override
public List<TreePermissionResp> treePermission(TreePermissionReq req) {
Set<Long> allFeatureIds = Sets.newHashSet();
Set<Long> featureIds;
try {
featureIds = listUserPermissionFeatureIds(req);
} catch (Exception ex) {
log.error("查询权限异常,执行降级处理");
featureIds = listUserPermissionFeatureIdsFromDB(req);
}
Set<Long> featureIds = resovlePermission(req);
Set<Long> defaultFeatureIds = listNotAuthFeatureIds();
allFeatureIds.addAll(featureIds);
@ -506,6 +503,20 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
return result;
}
private Set<Long> resovlePermission(TreePermissionReq req) {
if (tyrSaasAuthService.permissionFromDB()) {
return listUserPermissionFeatureIdsFromDB(req);
}
try {
return listUserPermissionFeatureIds(req);
} catch (Exception ex) {
log.error("查询权限异常,执行降级处理");
return listUserPermissionFeatureIdsFromDB(req);
}
}
private List<SaasFeatureResourceResp> filterFeature(List<SaasFeatureResourceResp> saasFeatureResources) {
if (CollectionUtils.isEmpty(saasFeatureResources)) {
return Collections.emptyList();

View File

@ -97,6 +97,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -156,6 +157,14 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
private final RolePermissionCacheService rolePermissionCacheService;
private final SaasRoleUserRelationMapper saasRoleUserRelationMapper;
@Value("${permission:from:db:false}")
private boolean PERMISSION_FROM_DB;
@Override
public boolean permissionFromDB() {
return BooleanUtil.isTrue(PERMISSION_FROM_DB);
}
/**
* 通过身份查询人员权限
*
@ -525,6 +534,11 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
@Override
public ListIdentityFromPermissionResp listIdentityFromPermission(ListIdentityFromPermissionReq req) {
if (this.permissionFromDB()) {
return listIdentityFromPermissionFromDB(req);
}
try {
return listIdentityFromPermissionResp(req);
} catch (Exception ex) {
@ -794,6 +808,11 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
}
private List<IdentityAuthRes.WorkspacePermission> findIdentityPermission(IdentityAuthReq req) {
if (this.permissionFromDB()) {
return findIdentityAuth(req).getPermissions();
}
try {
return findIdentityAuthV2(req).getPermissions();
} catch (Exception ex) {
@ -978,6 +997,10 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
@Override
public List<ListIdentityFromPermissionResp> listWorkspacePermissionIdentity(WorkspacePermissionIdentityReq req) {
if (this.permissionFromDB()) {
return listWorkspacePermissionIdentityFromDB(req);
}
try {
Set<String> newFeatureCodes = featureCodeUtil.resolveFeatureCode(Sets.newHashSet(req.getFeatureCodes()));