feat: add origin-aware managed/direct assignment methods to RbacService
- Add clearManagedAssignments, assignManagedRole, addUserToManagedGroup to interface - Update assignRoleToUser and addUserToGroup to explicitly set origin='direct' - Update getDirectRolesForUser to filter by origin='direct' - Implement managed assignment methods with ON CONFLICT upsert Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -54,8 +54,11 @@ public class RbacServiceImpl implements RbacService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void assignRoleToUser(String userId, UUID roleId) {
|
public void assignRoleToUser(String userId, UUID roleId) {
|
||||||
jdbc.update("INSERT INTO user_roles (user_id, role_id) VALUES (?, ?) ON CONFLICT DO NOTHING",
|
jdbc.update("""
|
||||||
userId, roleId);
|
INSERT INTO user_roles (user_id, role_id, origin)
|
||||||
|
VALUES (?, ?, 'direct')
|
||||||
|
ON CONFLICT (user_id, role_id, origin) DO NOTHING
|
||||||
|
""", userId, roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,8 +68,11 @@ public class RbacServiceImpl implements RbacService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addUserToGroup(String userId, UUID groupId) {
|
public void addUserToGroup(String userId, UUID groupId) {
|
||||||
jdbc.update("INSERT INTO user_groups (user_id, group_id) VALUES (?, ?) ON CONFLICT DO NOTHING",
|
jdbc.update("""
|
||||||
userId, groupId);
|
INSERT INTO user_groups (user_id, group_id, origin)
|
||||||
|
VALUES (?, ?, 'direct')
|
||||||
|
ON CONFLICT (user_id, group_id, origin) DO NOTHING
|
||||||
|
""", userId, groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -243,7 +249,8 @@ public class RbacServiceImpl implements RbacService {
|
|||||||
public List<RoleSummary> getDirectRolesForUser(String userId) {
|
public List<RoleSummary> getDirectRolesForUser(String userId) {
|
||||||
return jdbc.query("""
|
return jdbc.query("""
|
||||||
SELECT r.id, r.name, r.system FROM user_roles ur
|
SELECT r.id, r.name, r.system FROM user_roles ur
|
||||||
JOIN roles r ON r.id = ur.role_id WHERE ur.user_id = ?
|
JOIN roles r ON r.id = ur.role_id
|
||||||
|
WHERE ur.user_id = ? AND ur.origin = 'direct'
|
||||||
""", (rs, rowNum) -> new RoleSummary(rs.getObject("id", UUID.class),
|
""", (rs, rowNum) -> new RoleSummary(rs.getObject("id", UUID.class),
|
||||||
rs.getString("name"), rs.getBoolean("system"), "direct"), userId);
|
rs.getString("name"), rs.getBoolean("system"), "direct"), userId);
|
||||||
}
|
}
|
||||||
@@ -255,4 +262,28 @@ public class RbacServiceImpl implements RbacService {
|
|||||||
""", (rs, rowNum) -> new GroupSummary(rs.getObject("id", UUID.class),
|
""", (rs, rowNum) -> new GroupSummary(rs.getObject("id", UUID.class),
|
||||||
rs.getString("name")), userId);
|
rs.getString("name")), userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearManagedAssignments(String userId) {
|
||||||
|
jdbc.update("DELETE FROM user_roles WHERE user_id = ? AND origin = 'managed'", userId);
|
||||||
|
jdbc.update("DELETE FROM user_groups WHERE user_id = ? AND origin = 'managed'", userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void assignManagedRole(String userId, UUID roleId, UUID mappingId) {
|
||||||
|
jdbc.update("""
|
||||||
|
INSERT INTO user_roles (user_id, role_id, origin, mapping_id)
|
||||||
|
VALUES (?, ?, 'managed', ?)
|
||||||
|
ON CONFLICT (user_id, role_id, origin) DO UPDATE SET mapping_id = EXCLUDED.mapping_id
|
||||||
|
""", userId, roleId, mappingId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addUserToManagedGroup(String userId, UUID groupId, UUID mappingId) {
|
||||||
|
jdbc.update("""
|
||||||
|
INSERT INTO user_groups (user_id, group_id, origin, mapping_id)
|
||||||
|
VALUES (?, ?, 'managed', ?)
|
||||||
|
ON CONFLICT (user_id, group_id, origin) DO UPDATE SET mapping_id = EXCLUDED.mapping_id
|
||||||
|
""", userId, groupId, mappingId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,7 @@ public interface RbacService {
|
|||||||
List<UserSummary> getEffectivePrincipalsForRole(UUID roleId);
|
List<UserSummary> getEffectivePrincipalsForRole(UUID roleId);
|
||||||
List<String> getSystemRoleNames(String userId);
|
List<String> getSystemRoleNames(String userId);
|
||||||
RbacStats getStats();
|
RbacStats getStats();
|
||||||
|
void clearManagedAssignments(String userId);
|
||||||
|
void assignManagedRole(String userId, UUID roleId, UUID mappingId);
|
||||||
|
void addUserToManagedGroup(String userId, UUID groupId, UUID mappingId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user