Skip to content
Snippets Groups Projects
Commit 80b2b166 authored by juanf's avatar juanf
Browse files

SSDM-13940: Prevent deletions of role asignments and groups not created by system

parent bca8fe63
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
...@@ -310,6 +310,7 @@ public class UserManager ...@@ -310,6 +310,7 @@ public class UserManager
searchCriteria.withCodes().setFieldValue(adminGroupsByGroupId.keySet()); searchCriteria.withCodes().setFieldValue(adminGroupsByGroupId.keySet());
AuthorizationGroupFetchOptions fetchOptions = new AuthorizationGroupFetchOptions(); AuthorizationGroupFetchOptions fetchOptions = new AuthorizationGroupFetchOptions();
fetchOptions.withUsers(); fetchOptions.withUsers();
fetchOptions.withRegistrator();
List<AuthorizationGroup> groups = service.searchAuthorizationGroups(sessionToken, searchCriteria, List<AuthorizationGroup> groups = service.searchAuthorizationGroups(sessionToken, searchCriteria,
fetchOptions).getObjects(); fetchOptions).getObjects();
List<AuthorizationGroup> removedGroups = new ArrayList<>(); List<AuthorizationGroup> removedGroups = new ArrayList<>();
...@@ -321,7 +322,10 @@ public class UserManager ...@@ -321,7 +322,10 @@ public class UserManager
Set<String> users = extractUserIds(group); Set<String> users = extractUserIds(group);
if (users.containsAll(extractUserIds(adminGroup))) if (users.containsAll(extractUserIds(adminGroup)))
{ {
removedGroups.add(group); if (group.getRegistrator().getUserId().equals("system"))
{
removedGroups.add(group);
}
} }
} }
} }
...@@ -334,6 +338,7 @@ public class UserManager ...@@ -334,6 +338,7 @@ public class UserManager
searchCriteria.withCode().thatEndsWith(ADMIN_POSTFIX); searchCriteria.withCode().thatEndsWith(ADMIN_POSTFIX);
AuthorizationGroupFetchOptions fetchOptions = new AuthorizationGroupFetchOptions(); AuthorizationGroupFetchOptions fetchOptions = new AuthorizationGroupFetchOptions();
fetchOptions.withUsers(); fetchOptions.withUsers();
fetchOptions.withRegistrator();
List<AuthorizationGroup> adminGroups = service.searchAuthorizationGroups(sessionToken, searchCriteria, List<AuthorizationGroup> adminGroups = service.searchAuthorizationGroups(sessionToken, searchCriteria,
fetchOptions).getObjects(); fetchOptions).getObjects();
Map<String, AuthorizationGroup> adminGroupsByGroupId = new HashMap<>(); Map<String, AuthorizationGroup> adminGroupsByGroupId = new HashMap<>();
...@@ -893,7 +898,7 @@ public class UserManager ...@@ -893,7 +898,7 @@ public class UserManager
{ {
if (role != null) if (role != null)
{ {
context.delete(roleAssignment.getId()); context.delete(roleAssignment);
context.report.unassignRoleFrom(groupId, roleAssignment.getRole(), permId); context.report.unassignRoleFrom(groupId, roleAssignment.getRole(), permId);
} }
if (userSpaceRole != null) if (userSpaceRole != null)
...@@ -1011,7 +1016,7 @@ public class UserManager ...@@ -1011,7 +1016,7 @@ public class UserManager
String userSpace = createCommonSpaceCode(groupCode, userId.toUpperCase()); String userSpace = createCommonSpaceCode(groupCode, userId.toUpperCase());
if (space != null && space.getCode().startsWith(userSpace)) if (space != null && space.getCode().startsWith(userSpace))
{ {
context.delete(roleAssignment.getId()); context.delete(roleAssignment);
context.report.unassignRoleFrom(userId, roleAssignment.getRole(), space.getPermId()); context.report.unassignRoleFrom(userId, roleAssignment.getRole(), space.getPermId());
} }
} }
...@@ -1478,9 +1483,15 @@ public class UserManager ...@@ -1478,9 +1483,15 @@ public class UserManager
groupUpdates.add(groupUpdate); groupUpdates.add(groupUpdate);
} }
public void delete(IRoleAssignmentId roleAssignmentId) public void delete(RoleAssignment roleAssignment)
{ {
roleDeletions.add(roleAssignmentId); /*\
* The maintenance task should only remove role assignments created by itself
*/
if (roleAssignment.getRegistrator().getUserId().equals("system"))
{
roleDeletions.add(roleAssignment.getId());
}
} }
public void executeOperations() public void executeOperations()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment