DBService implements RolesProvider { void executePutPolicy(ResourceContext ctx, String domainName, String policyName, Policy policy, String auditRef, String caller) { for (int retryCount = defaultRetryCount; ; retryCount--) { try (ObjectStoreConnection con = store.getConnection(false, true)) { checkDomainAuditEnabled(con, domainName, auditRef, caller, getPrincipalName(ctx), AUDIT_TYPE_POLICY); quotaCheck.checkPolicyQuota(con, domainName, policy, caller); Policy originalPolicy = getPolicy(con, domainName, policyName); StringBuilder auditDetails = new StringBuilder(ZMSConsts.STRING_BLDR_SIZE_DEFAULT); if (!processPolicy(con, originalPolicy, domainName, policyName, policy, false, auditDetails)) { con.rollbackChanges(); throw ZMSUtils.internalServerError("unable to put policy: " + policy.getName(), caller); } saveChanges(con, domainName); auditLogRequest(ctx, domainName, auditRef, caller, ZMSConsts.HTTP_PUT, policyName, 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 testExecutePutPolicyMissingAuditRef() { String domain = "testreplacepolicymissingauditref"; TopLevelDomain dom = createTopLevelDomainObject( domain, null, null, adminUser); dom.setAuditEnabled(true); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom); Policy policy = createPolicyObject(domain, "policy1"); try { zms.dbService.executePutPolicy(mockDomRsrcCtx, domain, "policy1", policy, null, "testExecutePutPolicyMissingAuditRef"); fail("requesterror not thrown by replacePolicy."); } catch (ResourceException ex) { assertEquals(400, ex.getCode()); assertTrue(ex.getMessage().contains("Audit reference required")); } finally { zms.deleteTopLevelDomain(mockDomRsrcCtx, domain, auditRef); } }
@Test public void testExecutePutPolicy() { String domainName = "policyadddom1"; String policyName = "policy1"; TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); Policy policy1 = createPolicyObject(domainName, policyName); zms.dbService.executePutPolicy(mockDomRsrcCtx, domainName, policyName, policy1, auditRef, "putPolicy"); Policy policyRes2 = zms.getPolicy(mockDomRsrcCtx, domainName, policyName); assertNotNull(policyRes2); assertEquals(policyRes2.getName(), domainName + ":policy." + policyName); zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); }
@Test public void testExecutePutPolicyInvalidDomain() { TopLevelDomain dom1 = createTopLevelDomainObject("PolicyAddDom1", "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); Policy policy1 = createPolicyObject("PolicyAddDom1", "Policy1"); try { zms.dbService.executePutPolicy(mockDomRsrcCtx, "PolicyAddDom1Invalid", "Policy1", policy1, auditRef, "putPolicy"); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), 404); } zms.deleteTopLevelDomain(mockDomRsrcCtx, "PolicyAddDom1", auditRef); }