DBService implements RolesProvider { boolean processRole(ObjectStoreConnection con, Role originalRole, String domainName, String roleName, Role role, String admin, String auditRef, boolean ignoreDeletes, StringBuilder auditDetails) { boolean requestSuccess; if (originalRole == null) { role.setAuditEnabled(false); requestSuccess = con.insertRole(domainName, role); } else { role.setAuditEnabled(originalRole.getAuditEnabled()); requestSuccess = con.updateRole(domainName, role); } if (!requestSuccess) { return false; } auditDetails.append("{\"name\": \"").append(roleName) .append("\", \"trust\": \"").append(role.getTrust()).append('\"'); List<RoleMember> roleMembers = role.getRoleMembers(); List<String> members = role.getMembers(); if (members != null && !members.isEmpty()) { roleMembers = ZMSUtils.convertMembersToRoleMembers(members); } if (originalRole == null) { if (roleMembers != null) { for (RoleMember member : roleMembers) { if (!con.insertRoleMember(domainName, roleName, member, admin, auditRef)) { return false; } } auditLogRoleMembers(auditDetails, "added-members", roleMembers); } } else { processUpdateRoleMembers(con, originalRole, roleMembers, ignoreDeletes, domainName, roleName, admin, auditRef, auditDetails); } auditDetails.append('}'); return true; } 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 testProcessRoleInsert() { ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class); Role role = new Role().setName("newRole").setAuditEnabled(true).setSelfServe(true); StringBuilder auditDetails = new StringBuilder("testAudit"); zms.dbService.processRole(conn, null, "auditedDomain", "testRole1", role, adminUser, auditRef, false, auditDetails); assertFalse(role.getAuditEnabled()); assertTrue(role.getSelfServe()); }
@Test public void testProcessRoleUpdate() { ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class); Role originalRole = new Role().setName("originalRole").setAuditEnabled(false); Role role = new Role().setName("newRole").setAuditEnabled(true); StringBuilder auditDetails = new StringBuilder("testAudit"); zms.dbService.processRole(conn, originalRole, "auditedDomain", "newRole", role, adminUser, auditRef, false, auditDetails); assertFalse(role.getAuditEnabled()); originalRole.setAuditEnabled(true); Role role2 = new Role().setName("newRole2").setAuditEnabled(false); zms.dbService.processRole(conn, originalRole, "auditedDomain", "newRole2", role2, adminUser, auditRef, false, auditDetails); assertTrue(role2.getAuditEnabled()); Role role3 = new Role().setName("newRole3").setAuditEnabled(false).setSelfServe(true); zms.dbService.processRole(conn, originalRole, "auditedDomain", "newRole3", role3, adminUser, auditRef, false, auditDetails); assertTrue(role3.getSelfServe()); Role role4 = new Role().setName("newRole4").setAuditEnabled(false).setSelfServe(false); zms.dbService.processRole(conn, originalRole, "auditedDomain", "newRole4", role4, adminUser, auditRef, false, auditDetails); assertFalse(role4.getSelfServe()); }