fix(mobile-api): read roles services-system sends as bare ids
services-system writes a role already seen in a response as its bare id. The module check missed it, so a role granted two modules was refused the second; the super-admin target guard now reads it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
4c48ebea2e
commit
69e2b4eb7b
4 files changed
+22
-3
No files matched your search
+2
-1
@@ -155,8 +155,9 @@ public class AdminUserService {
|
||||
/** The target admin; a non-super caller may not manage a super admin. */
|
||||
private Map<String, Object> loadManaged(Long id, User caller) {
|
||||
Map<String, Object> user = load(id);
|
||||
// idOf also reads a role services-system sent as a bare id
|
||||
if (!isSuper(caller) && user.get("roles") instanceof List<?> l && l.stream().anyMatch(
|
||||
x -> x instanceof Map<?, ?> m && m.get("id") instanceof Number n && n.longValue() == SUPER_ADMIN_ROLE_ID)) {
|
||||
x -> Long.valueOf(SUPER_ADMIN_ROLE_ID).equals(AdminRoleService.idOf(x)))) {
|
||||
throw superRequired("Only a super admin can manage a super admin");
|
||||
}
|
||||
return user;
|
||||
|
||||
+3
-2
@@ -27,8 +27,9 @@ public final class AdminModuleAccess {
|
||||
List<Map<String, Object>> modules = ent.getBody() != null ? ent.getBody() : List.of();
|
||||
return modules.stream()
|
||||
.filter(m -> m.get("name") instanceof String name && wanted.contains(name))
|
||||
// services-system writes a role already seen in this response as its bare id
|
||||
.anyMatch(m -> m.get("roles") instanceof List<?> roles && roles.stream()
|
||||
.anyMatch(r -> r instanceof Map<?, ?> rm && rm.get("id") instanceof Number n
|
||||
&& roleIds.contains(n.longValue())));
|
||||
.map(r -> r instanceof Map<?, ?> rm ? rm.get("id") : r)
|
||||
.anyMatch(id -> id instanceof Number n && roleIds.contains(n.longValue())));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user