DBService implements RolesProvider { void executeDeleteDomainRoleMember(ResourceContext ctx, String domainName, String memberName, String auditRef, String caller) { for (int retryCount = defaultRetryCount; ; retryCount--) { try (ObjectStoreConnection con = store.getConnection(true, true)) { removePrincipalFromDomainRoles(con, domainName, memberName, getPrincipalName(ctx), auditRef); auditLogRequest(ctx, domainName, auditRef, caller, ZMSConsts.HTTP_DELETE, memberName, 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 testExecuteDeleteDomainRoleMember() { String domainName = "deletedomainrolemember1"; TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); Role role1 = createRoleObject(domainName, "role1", null, "user.jack", "user.janie"); zms.putRole(mockDomRsrcCtx, domainName, "role1", auditRef, role1); Role role2 = createRoleObject(domainName, "role2", null, "user.janie", "user.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role2", auditRef, role2); Role role3 = createRoleObject(domainName, "role3", null, "user.jack", "user.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role3", auditRef, role3); Role role4 = createRoleObject(domainName, "role4", null, "user.jack", null); zms.putRole(mockDomRsrcCtx, domainName, "role4", auditRef, role4); Role role5 = createRoleObject(domainName, "role5", null, "user.jack-service", "user.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role5", auditRef, role5); DomainRoleMembers domainRoleMembers = zms.getDomainRoleMembers(mockDomRsrcCtx, domainName); assertEquals(domainName, domainRoleMembers.getDomainName()); List<DomainRoleMember> members = domainRoleMembers.getMembers(); assertNotNull(members); assertEquals(5, members.size()); ZMSTestUtils.verifyDomainRoleMember(members, "user.jack", "role1", "role3", "role4"); ZMSTestUtils.verifyDomainRoleMember(members, "user.janie", "role1", "role2"); ZMSTestUtils.verifyDomainRoleMember(members, "user.jane", "role2", "role3", "role5"); ZMSTestUtils.verifyDomainRoleMember(members, "user.jack-service", "role5"); ZMSTestUtils.verifyDomainRoleMember(members, adminUser, "admin"); try { zms.dbService.executeDeleteDomainRoleMember(mockDomRsrcCtx, domainName, "user.unknown", auditRef, "testExecuteDeleteDomainRoleMember"); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.NOT_FOUND); } domainRoleMembers = zms.getDomainRoleMembers(mockDomRsrcCtx, domainName); members = domainRoleMembers.getMembers(); assertNotNull(members); assertEquals(5, members.size()); ZMSTestUtils.verifyDomainRoleMember(members, "user.jack", "role1", "role3", "role4"); ZMSTestUtils.verifyDomainRoleMember(members, "user.janie", "role1", "role2"); ZMSTestUtils.verifyDomainRoleMember(members, "user.jane", "role2", "role3", "role5"); ZMSTestUtils.verifyDomainRoleMember(members, "user.jack-service", "role5"); ZMSTestUtils.verifyDomainRoleMember(members, adminUser, "admin"); zms.dbService.executeDeleteDomainRoleMember(mockDomRsrcCtx, domainName, "user.jack", auditRef, "testExecuteDeleteDomainRoleMember"); domainRoleMembers = zms.getDomainRoleMembers(mockDomRsrcCtx, domainName); assertEquals(domainName, domainRoleMembers.getDomainName()); members = domainRoleMembers.getMembers(); assertNotNull(members); assertEquals(4, members.size()); ZMSTestUtils.verifyDomainRoleMember(members, "user.janie", "role1", "role2"); ZMSTestUtils.verifyDomainRoleMember(members, "user.jane", "role2", "role3", "role5"); ZMSTestUtils.verifyDomainRoleMember(members, "user.jack-service", "role5"); ZMSTestUtils.verifyDomainRoleMember(members, adminUser, "admin"); zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); }
@Test public void testExecuteDeleteDomainRoleMemberRetryException() { Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.listPrincipalRoles("dom1", "user.joe")) .thenThrow(new ResourceException(410)); ObjectStore saveStore = zms.dbService.store; zms.dbService.store = mockObjStore; int saveRetryCount = zms.dbService.defaultRetryCount; zms.dbService.defaultRetryCount = 3; try { zms.dbService.executeDeleteDomainRoleMember(mockDomRsrcCtx, "dom1", "user.joe", adminUser, "unittest"); fail(); } catch (ResourceException ex) { assertEquals(410, ex.getCode()); } zms.dbService.defaultRetryCount = saveRetryCount; zms.dbService.store = saveStore; }