DBService implements RolesProvider { void updateSystemMetaFields(Domain domain, final String attribute, boolean deleteAllowed, DomainMeta meta) { final String caller = "putdomainsystemmeta"; switch (attribute) { case ZMSConsts.SYSTEM_META_ACCOUNT: if (!isDeleteSystemMetaAllowed(deleteAllowed, domain.getAccount(), meta.getAccount())) { throw ZMSUtils.forbiddenError("unauthorized to reset system meta attribute: " + attribute, caller); } domain.setAccount(meta.getAccount()); break; case ZMSConsts.SYSTEM_META_PRODUCT_ID: if (!isDeleteSystemMetaAllowed(deleteAllowed, domain.getYpmId(), meta.getYpmId())) { throw ZMSUtils.forbiddenError("unauthorized to reset system meta attribute: " + attribute, caller); } domain.setYpmId(meta.getYpmId()); break; case ZMSConsts.SYSTEM_META_CERT_DNS_DOMAIN: if (!isDeleteSystemMetaAllowed(deleteAllowed, domain.getCertDnsDomain(), meta.getCertDnsDomain())) { throw ZMSUtils.forbiddenError("unauthorized to reset system meta attribute: " + attribute, caller); } domain.setCertDnsDomain(meta.getCertDnsDomain()); break; case ZMSConsts.SYSTEM_META_ORG: if (!isDeleteSystemMetaAllowed(deleteAllowed, domain.getOrg(), meta.getOrg())) { throw ZMSUtils.forbiddenError("unauthorized to reset system meta attribute: " + attribute, caller); } domain.setOrg(meta.getOrg()); break; case ZMSConsts.SYSTEM_META_AUDIT_ENABLED: domain.setAuditEnabled(meta.getAuditEnabled()); break; case ZMSConsts.SYSTEM_META_USER_AUTH_FILTER: domain.setUserAuthorityFilter(meta.getUserAuthorityFilter()); break; case ZMSConsts.SYSTEM_META_ENABLED: domain.setEnabled(meta.getEnabled()); break; default: throw ZMSUtils.requestError("unknown system meta attribute: " + attribute, caller); } } 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 testUpdateSystemMetaFields() { Domain domain = new Domain(); DomainMeta meta = new DomainMeta() .setAccount("acct") .setYpmId(1234) .setCertDnsDomain("athenz.cloud"); zms.dbService.updateSystemMetaFields(domain, "account", true, meta); assertEquals(domain.getAccount(), "acct"); zms.dbService.updateSystemMetaFields(domain, "productid", true, meta); assertEquals(domain.getYpmId().intValue(), 1234); zms.dbService.updateSystemMetaFields(domain, "certdnsdomain", true, meta); assertEquals(domain.getCertDnsDomain(), "athenz.cloud"); try { zms.dbService.updateSystemMetaFields(domain, "unknown", true, meta); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), 400); } Domain domain1 = new Domain(); DomainMeta meta1 = new DomainMeta() .setAccount("acct") .setYpmId(1234) .setCertDnsDomain("athenz.cloud"); zms.dbService.updateSystemMetaFields(domain1, "account", false, meta1); assertEquals(domain1.getAccount(), "acct"); zms.dbService.updateSystemMetaFields(domain1, "productid", false, meta1); assertEquals(domain1.getYpmId().intValue(), 1234); zms.dbService.updateSystemMetaFields(domain1, "certdnsdomain", false, meta1); assertEquals(domain1.getCertDnsDomain(), "athenz.cloud"); Domain domain2 = new Domain() .setAccount("acct") .setYpmId(1234) .setCertDnsDomain("athenz.cloud"); DomainMeta meta2 = new DomainMeta() .setAccount("acct-new") .setYpmId(1235) .setCertDnsDomain("athenz.cloud.new"); try { zms.dbService.updateSystemMetaFields(domain2, "account", false, meta2); } catch (ResourceException ex) { assertEquals(ex.getCode(), 403); assertTrue(ex.getMessage().contains("reset system meta attribute")); } try { zms.dbService.updateSystemMetaFields(domain2, "productid", false, meta2); } catch (ResourceException ex) { assertEquals(ex.getCode(), 403); assertTrue(ex.getMessage().contains("reset system meta attribute")); } try { zms.dbService.updateSystemMetaFields(domain2, "certdnsdomain", false, meta2); } catch (ResourceException ex) { assertEquals(ex.getCode(), 403); assertTrue(ex.getMessage().contains("reset system meta attribute")); } Domain domain3 = new Domain() .setAccount("acct") .setYpmId(1234) .setCertDnsDomain("athenz.cloud"); DomainMeta meta3 = new DomainMeta() .setAccount("acct") .setYpmId(1234) .setCertDnsDomain("athenz.cloud"); zms.dbService.updateSystemMetaFields(domain3, "account", false, meta3); assertEquals(domain3.getAccount(), "acct"); zms.dbService.updateSystemMetaFields(domain3, "productid", false, meta3); assertEquals(domain3.getYpmId().intValue(), 1234); zms.dbService.updateSystemMetaFields(domain3, "certdnsdomain", false, meta3); assertEquals(domain3.getCertDnsDomain(), "athenz.cloud"); }