DBService implements RolesProvider { void executeDeleteMembership(ResourceContext ctx, String domainName, String roleName, String normalizedMember, String auditRef, String caller) { for (int retryCount = defaultRetryCount; ; retryCount--) { try (ObjectStoreConnection con = store.getConnection(true, true)) { String principal = getPrincipalName(ctx); checkDomainAuditEnabled(con, domainName, auditRef, caller, principal, AUDIT_TYPE_ROLE); if (ZMSConsts.ADMIN_ROLE_NAME.equals(roleName)) { List<RoleMember> members = con.listRoleMembers(domainName, roleName, false); if (members.size() == 1 && members.get(0).getMemberName().equals(normalizedMember)) { throw ZMSUtils.forbiddenError(caller + ": Cannot delete last member of 'admin' role", caller); } } if (!con.deleteRoleMember(domainName, roleName, normalizedMember, principal, auditRef)) { con.rollbackChanges(); throw ZMSUtils.notFoundError(caller + ": unable to delete role member: " + normalizedMember + " from role: " + roleName, caller); } con.updateRoleModTimestamp(domainName, roleName); con.updateDomainModTimestamp(domainName); cacheStore.invalidate(domainName); auditLogRequest(ctx, domainName, auditRef, caller, ZMSConsts.HTTP_DELETE, roleName, "{\"member\": \"" + normalizedMember + "\"}"); 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 testExecuteDeleteMembership() { String domainName = "mbrdeldom1"; String roleName = "role1"; TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); Role role1 = createRoleObject(domainName, roleName, null, "user.joe", "user.jane"); zms.putRole(mockDomRsrcCtx, domainName, roleName, auditRef, role1); zms.dbService.executeDeleteMembership(mockDomRsrcCtx, domainName, roleName, "user.joe", auditRef, "deleteMembership"); Role role = zms.getRole(mockDomRsrcCtx, domainName, roleName, true, false, false); assertNotNull(role); List<RoleMember> members = role.getRoleMembers(); assertNotNull(members); assertEquals(members.size(), 1); for (RoleMember member: members) { if (member.getMemberName().equals("user.joe")) { fail("user.joe could not be deleted"); } } List<String> checkList = new ArrayList<>(); checkList.add("user.jane"); checkRoleMember(checkList, members); zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); }