DBService implements RolesProvider { public void executePutRoleMeta(ResourceContext ctx, String domainName, String roleName, Role originalRole, RoleMeta meta, String auditRef, String caller) { for (int retryCount = defaultRetryCount; ; retryCount--) { try (ObjectStoreConnection con = store.getConnection(false, true)) { checkObjectAuditEnabled(con, originalRole.getAuditEnabled(), originalRole.getName(), auditRef, caller, getPrincipalName(ctx)); Role updatedRole = new Role() .setName(originalRole.getName()) .setAuditEnabled(originalRole.getAuditEnabled()) .setTrust(originalRole.getTrust()) .setSelfServe(originalRole.getSelfServe()) .setMemberExpiryDays(originalRole.getMemberExpiryDays()) .setServiceExpiryDays(originalRole.getServiceExpiryDays()) .setGroupExpiryDays(originalRole.getGroupExpiryDays()) .setTokenExpiryMins(originalRole.getTokenExpiryMins()) .setCertExpiryMins(originalRole.getCertExpiryMins()) .setMemberReviewDays(originalRole.getMemberReviewDays()) .setServiceReviewDays(originalRole.getServiceReviewDays()) .setSignAlgorithm(originalRole.getSignAlgorithm()) .setReviewEnabled(originalRole.getReviewEnabled()) .setNotifyRoles(originalRole.getNotifyRoles()) .setUserAuthorityFilter(originalRole.getUserAuthorityFilter()) .setUserAuthorityExpiration(originalRole.getUserAuthorityExpiration()); updateRoleMetaFields(updatedRole, meta); con.updateRole(domainName, updatedRole); saveChanges(con, domainName); StringBuilder auditDetails = new StringBuilder(ZMSConsts.STRING_BLDR_SIZE_DEFAULT); auditLogRoleMeta(auditDetails, updatedRole, roleName); auditLogRequest(ctx, domainName, auditRef, caller, ZMSConsts.HTTP_PUT, domainName, auditDetails.toString()); updateRoleMembersDueDates(ctx, con, domainName, roleName, originalRole, updatedRole, auditRef, caller); updateRoleMembersSystemDisabledState(ctx, con, domainName, roleName, originalRole, updatedRole, auditRef, caller); 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 testExecutePutRoleMeta() { final String domainName = "metadom1"; final String roleName = "metarole1"; List<String> admins = new ArrayList<>(); admins.add(adminUser); zms.dbService.makeDomain(mockDomRsrcCtx, ZMSTestUtils.makeDomainObject(domainName, "test desc", "testOrg", false, "", 1234, "", 0), admins, null, auditRef); Role role = createRoleObject(domainName, roleName, null, "user.john", "user.jane"); zms.dbService.executePutRole(mockDomRsrcCtx, domainName, roleName, role, "test", "putrole"); RoleMeta rm = new RoleMeta(); rm.setSelfServe(true); Role originalRole = zms.dbService.getRole(domainName, roleName, false, false, false); zms.dbService.executePutRoleMeta(mockDomRsrcCtx, domainName, roleName, originalRole, rm, auditRef, "putrolemeta"); Role resRole1 = zms.dbService.getRole(domainName, roleName, false, true, false); assertTrue(resRole1.getSelfServe()); rm = new RoleMeta(); rm.setSelfServe(true); rm.setMemberExpiryDays(10); rm.setServiceExpiryDays(15); rm.setGroupExpiryDays(25); rm.setTokenExpiryMins(20); rm.setReviewEnabled(true); rm.setNotifyRoles("role1,role2"); rm.setMemberReviewDays(30); rm.setServiceReviewDays(35); rm.setUserAuthorityFilter("employee"); rm.setUserAuthorityExpiration("elevated-clearance"); originalRole = zms.dbService.getRole(domainName, roleName, false, false, false); zms.dbService.executePutRoleMeta(mockDomRsrcCtx, domainName, roleName, originalRole, rm, auditRef, "putrolemeta"); resRole1 = zms.dbService.getRole(domainName, roleName, false, true, false); assertTrue(resRole1.getSelfServe()); assertNull(resRole1.getCertExpiryMins()); assertEquals(resRole1.getMemberExpiryDays(), Integer.valueOf(10)); assertEquals(resRole1.getServiceExpiryDays(), Integer.valueOf(15)); assertEquals(resRole1.getGroupExpiryDays(), Integer.valueOf(25)); assertEquals(resRole1.getTokenExpiryMins(), Integer.valueOf(20)); assertTrue(resRole1.getReviewEnabled()); assertEquals(resRole1.getNotifyRoles(), "role1,role2"); assertEquals(resRole1.getMemberReviewDays(), Integer.valueOf(30)); assertEquals(resRole1.getServiceReviewDays(), Integer.valueOf(35)); assertEquals(resRole1.getUserAuthorityFilter(), "employee"); assertEquals(resRole1.getUserAuthorityExpiration(), "elevated-clearance"); rm = new RoleMeta(); rm.setSelfServe(false); rm.setCertExpiryMins(10); rm.setTokenExpiryMins(25); rm.setServiceExpiryDays(15); rm.setGroupExpiryDays(20); rm.setSignAlgorithm("rsa"); rm.setReviewEnabled(false); rm.setServiceReviewDays(35); rm.setUserAuthorityFilter("contractor"); originalRole = zms.dbService.getRole(domainName, roleName, false, false, false); zms.dbService.executePutRoleMeta(mockDomRsrcCtx, domainName, roleName, originalRole, rm, auditRef, "putrolemeta"); resRole1 = zms.dbService.getRole(domainName, roleName, false, true, false); assertNull(resRole1.getSelfServe()); assertEquals(resRole1.getCertExpiryMins(), Integer.valueOf(10)); assertEquals(resRole1.getMemberExpiryDays(), Integer.valueOf(10)); assertEquals(resRole1.getServiceExpiryDays(), Integer.valueOf(15)); assertEquals(resRole1.getGroupExpiryDays(), Integer.valueOf(20)); assertEquals(resRole1.getTokenExpiryMins(), Integer.valueOf(25)); assertEquals(resRole1.getMemberReviewDays(), Integer.valueOf(30)); assertEquals(resRole1.getServiceReviewDays(), Integer.valueOf(35)); assertEquals(resRole1.getSignAlgorithm(), "rsa"); assertNull(resRole1.getReviewEnabled()); assertEquals(resRole1.getNotifyRoles(), "role1,role2"); assertEquals(resRole1.getUserAuthorityFilter(), "contractor"); assertEquals(resRole1.getUserAuthorityExpiration(), "elevated-clearance"); zms.dbService.executeDeleteDomain(mockDomRsrcCtx, domainName, auditRef, "deletedomain"); }