DBService implements RolesProvider { void executePutGroupMembershipDecision(ResourceContext ctx, final String domainName, Group group, GroupMember groupMember, final String auditRef) { for (int retryCount = defaultRetryCount; ; retryCount--) { try (ObjectStoreConnection con = store.getConnection(false, true)) { String principal = getPrincipalName(ctx); checkObjectAuditEnabled(con, group.getAuditEnabled(), group.getName(), auditRef, ctx.getApiName(), principal); final String groupName = ZMSUtils.extractGroupName(domainName, group.getName()); if (!con.confirmGroupMember(domainName, groupName, groupMember, principal, auditRef)) { con.rollbackChanges(); throw ZMSUtils.requestError("unable to apply group membership decision for member: " + groupMember.getMemberName() + " and group: " + groupName, ctx.getApiName()); } con.updateGroupModTimestamp(domainName, groupName); saveChanges(con, domainName); StringBuilder auditDetails = new StringBuilder(ZMSConsts.STRING_BLDR_SIZE_DEFAULT); auditLogGroupMember(auditDetails, groupMember, true); auditLogRequest(ctx, domainName, auditRef, ctx.getApiName(), ZMSConsts.HTTP_PUT, groupName, auditDetails.toString()); 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 testExecutePutGroupMembershipDecisionFailure() { final String domainName = "put-group-mbr-dec-err"; final String groupName = "group1"; Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.confirmGroupMember(anyString(), anyString(), any(GroupMember.class), anyString(), anyString())).thenReturn(false).thenThrow(new ResourceException(409)); ObjectStore saveStore = zms.dbService.store; zms.dbService.store = mockObjStore; Group group = createGroupObject(domainName, groupName, "user.joe", "user.jane"); GroupMember groupMember = new GroupMember().setMemberName("user.john"); try { zms.dbService.executePutGroupMembershipDecision(mockDomRsrcCtx, domainName, group, groupMember, auditRef); fail(); } catch (ResourceException ex) { assertEquals(ResourceException.BAD_REQUEST, ex.getCode()); } try { zms.dbService.executePutGroupMembershipDecision(mockDomRsrcCtx, domainName, group, groupMember, auditRef); fail(); } catch (ResourceException ex) { assertEquals(ResourceException.CONFLICT, ex.getCode()); } zms.dbService.store = saveStore; }