DBService implements RolesProvider { void executeDeleteUser(ResourceContext ctx, String userName, String domainName, String auditRef, String caller) { for (int retryCount = defaultRetryCount; ; retryCount--) { try (ObjectStoreConnection con = store.getConnection(true, true)) { removePrincipalDomains(con, domainName); List<String> userSvcPrincipals = con.listPrincipals(domainName); final String adminPrincipal = getPrincipalName(ctx); removePrincipalFromAllRoles(con, userName, adminPrincipal, auditRef); for (String userSvcPrincipal : userSvcPrincipals) { removePrincipalFromAllRoles(con, userSvcPrincipal, adminPrincipal, auditRef); } if (!con.deletePrincipal(userName, true)) { throw ZMSUtils.notFoundError(caller + ": unable to delete user: " + userName, caller); } auditLogRequest(ctx, userName, auditRef, caller, ZMSConsts.HTTP_DELETE, userName, null); return; } catch (ResourceException ex) { if (!shouldRetryOperation(ex, retryCount)) { throw ex; } } } } DBService(ObjectStore store, AuditLogger auditLogger, ZMSConfig zmsConfig, AuditReferenceValidator auditReferenceValidator); DomainRoleMembers listOverdueReviewRoleMembers(String domainName); @Override List<Role> getRolesByDomain(String domain); ResourceAccessList getResourceAccessList(String principal, String action); AthenzDomain getAthenzDomain(final String domainName, boolean masterCopy); Quota getQuota(String domainName); void executePutRoleSystemMeta(ResourceContext ctx, final String domainName, final String roleName,
           RoleSystemMeta meta, final String attribute, final String auditRef, final String caller); void executePutGroupSystemMeta(ResourceContext ctx, final String domainName, final String groupName,
                                          GroupSystemMeta meta, final String attribute, final String auditRef); void executePutServiceIdentitySystemMeta(ResourceContext ctx, String domainName, String serviceName,
            ServiceIdentitySystemMeta meta, String attribute, String auditRef, String caller); void executePutRoleMeta(ResourceContext ctx, String domainName, String roleName, Role originalRole,
                                   RoleMeta meta, String auditRef, String caller); void executePutGroupMeta(ResourceContext ctx, final String domainName, final String groupName,
                                    GroupMeta meta, final String auditRef); Set<String> getPendingMembershipApproverRoles(int delayDays); Set<String> getPendingGroupMembershipApproverRoles(int delayDays); Map<String, DomainRoleMember> getRoleExpiryMembers(int delayDays); Map<String, DomainRoleMember> getRoleReviewMembers(int delayDays); Map<String, DomainGroupMember> getGroupExpiryMembers(int delayDays); void processExpiredPendingMembers(int pendingRoleMemberLifespan, final String monitorIdentity); void processExpiredPendingGroupMembers(int pendingGroupMemberLifespan, final String monitorIdentity); static int AUDIT_TYPE_ROLE; static int AUDIT_TYPE_POLICY; static int AUDIT_TYPE_SERVICE; static int AUDIT_TYPE_DOMAIN; static int AUDIT_TYPE_ENTITY; static int AUDIT_TYPE_TENANCY; static int AUDIT_TYPE_TEMPLATE; static int AUDIT_TYPE_GROUP; }
@Test public void testExecuteDeleteUser() { String domainName = "deleteuser1"; ZMSTestUtils.cleanupNotAdminUsers(zms, adminUser, mockDomRsrcCtx); TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); TopLevelDomain dom2 = createTopLevelDomainObject("deleteusersports", "Test Domain2", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom2); TopLevelDomain dom3 = createTopLevelDomainObject("deleteuserweather", "Test Domain3", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom3); SubDomain subDom1 = createSubDomainObject("jack", "user", "Test SubDomain2", "testOrg", adminUser); zms.postSubDomain(mockDomRsrcCtx, "user", auditRef, subDom1); SubDomain subDom2 = createSubDomainObject("jane", "user", "Test SubDomain2", "testOrg", adminUser); zms.postSubDomain(mockDomRsrcCtx, "user", auditRef, subDom2); Role role1 = createRoleObject(domainName, "role1", null, "user.joe", "user.janie"); zms.putRole(mockDomRsrcCtx, domainName, "role1", auditRef, role1); Role role2 = createRoleObject(domainName, "role2", null, "user.joe", "deleteusersports.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role2", auditRef, role2); Role role3 = createRoleObject(domainName, "role3", null, "user.jack", "deleteuserweather.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role3", auditRef, role3); Role role4 = createRoleObject("deleteusersports", "role4", null, "user.ana", "user.janie"); zms.putRole(mockDomRsrcCtx, "deleteusersports", "role4", auditRef, role4); Role role5 = createRoleObject("deleteusersports", "role5", null, "user.jack.service", "user.jane.storage"); zms.putRole(mockDomRsrcCtx, "deleteusersports", "role5", auditRef, role5); List<String> users = zms.dbService.listPrincipals("user", true); assertEquals(users.size(), 5); assertTrue(users.contains("user.testadminuser")); assertTrue(users.contains("user.janie")); assertTrue(users.contains("user.ana")); assertTrue(users.contains("user.jack")); assertTrue(users.contains("user.joe")); zms.dbService.executeDeleteUser(mockDomRsrcCtx, "user.jack", "user.jack", auditRef, "testExecuteDeleteUser"); users = zms.dbService.listPrincipals("user", true); assertEquals(users.size(), 4); assertTrue(users.contains("user.testadminuser")); assertTrue(users.contains("user.janie")); assertTrue(users.contains("user.ana")); assertTrue(users.contains("user.joe")); assertFalse(users.contains("user.jack")); Role testRole = zms.dbService.getRole("deleteusersports", "role5", false, false, false); assertEquals(testRole.getRoleMembers().size(), 1); RoleMember roleMember = testRole.getRoleMembers().get(0); assertEquals(roleMember.getMemberName(), "user.jane.storage"); try { zms.getDomain(mockDomRsrcCtx, "user.jack"); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.NOT_FOUND); } zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); zms.deleteSubDomain(mockDomRsrcCtx, "user", "jane", auditRef); zms.deleteTopLevelDomain(mockDomRsrcCtx, "deleteusersports", auditRef); zms.deleteTopLevelDomain(mockDomRsrcCtx, "deleteuserweather", auditRef); }