Skip to content

Commit 8e3adc1

Browse files
committed
refactor(auth): 统一策略锁目标解析为扫描式并清理死代码
- SaExtensionInterceptor 删除租户校验后无用的 getExtraContext() 调用 - TenantArgumentPolicyLockTargetResolver / ClientPolicyLockTargetResolver 由按位置 args[0]/args[1] 取参改为遍历参数扫描式解析,与 UserArgumentPolicyLockTargetResolver 保持一致,避免给多参方法加注解时踩坑 - Client 解析器抽取 resolveClientIds 复用 clientId 映射逻辑
1 parent 3763ec7 commit 8e3adc1

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

continew-auth-refresh/src/main/java/top/continew/admin/auth/support/TenantArgumentPolicyLockTargetResolver.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ public class TenantArgumentPolicyLockTargetResolver implements AuthPolicyLockTar
2929

3030
@Override
3131
public Collection<AuthPolicyLockTarget> resolve(Object[] args) {
32-
Object value = args.length > 0 && args[0] instanceof Collection<?> ? args[0]
33-
: args.length > 1 ? args[1] : null;
34-
if (value instanceof Long tenantId) {
35-
return List.of(AuthPolicyLockTarget.tenant(tenantId));
36-
}
37-
if (value instanceof Collection<?> values) {
38-
return values.stream().filter(Long.class::isInstance).map(Long.class::cast)
39-
.map(AuthPolicyLockTarget::tenant).toList();
32+
for (Object value : args) {
33+
if (value instanceof Long tenantId) {
34+
return List.of(AuthPolicyLockTarget.tenant(tenantId));
35+
}
36+
if (value instanceof Collection<?> values) {
37+
List<AuthPolicyLockTarget> targets = values.stream().filter(Long.class::isInstance)
38+
.map(Long.class::cast).map(AuthPolicyLockTarget::tenant).toList();
39+
if (!targets.isEmpty()) {
40+
return targets;
41+
}
42+
}
4043
}
4144
throw new IllegalArgumentException("认证租户策略锁参数无效");
4245
}

continew-server/src/main/java/top/continew/admin/config/satoken/SaExtensionInterceptor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public boolean preHandle(HttpServletRequest request,
100100
return false;
101101
}
102102
}
103-
UserContextHolder.getExtraContext();
104103
return true;
105104
}
106105

continew-system/src/main/java/top/continew/admin/auth/adapter/ClientPolicyLockTargetResolver.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,22 @@ public class ClientPolicyLockTargetResolver implements AuthPolicyLockTargetResol
3636

3737
@Override
3838
public Collection<AuthPolicyLockTarget> resolve(Object[] args) {
39-
Object value = args.length > 0 && args[0] instanceof Collection<?> ? args[0]
40-
: args.length > 1 ? args[1] : null;
41-
List<Long> ids = value instanceof Long id ? List.of(id)
42-
: value instanceof Collection<?> values ? values.stream().filter(Long.class::isInstance)
43-
.map(Long.class::cast).toList() : null;
44-
if (ids == null) {
45-
throw new IllegalArgumentException("认证客户端策略锁参数无效");
46-
}
47-
if (ids.isEmpty()) {
48-
return List.of();
39+
for (Object value : args) {
40+
if (value instanceof Long id) {
41+
return resolveClientIds(List.of(id));
42+
}
43+
if (value instanceof Collection<?> values) {
44+
List<Long> ids = values.stream().filter(Long.class::isInstance)
45+
.map(Long.class::cast).toList();
46+
if (!ids.isEmpty()) {
47+
return resolveClientIds(ids);
48+
}
49+
}
4950
}
51+
throw new IllegalArgumentException("认证客户端策略锁参数无效");
52+
}
53+
54+
private Collection<AuthPolicyLockTarget> resolveClientIds(List<Long> ids) {
5055
return clientMapper
5156
.selectList(Wrappers.<ClientDO>lambdaQuery().select(ClientDO::getClientId)
5257
.in(ClientDO::getId, ids))

0 commit comments

Comments
 (0)