DBService implements RolesProvider { DomainRoleMember getPrincipalRoles(String principal, String domainName) { try (ObjectStoreConnection con = store.getConnection(true, false)) { return con.getPrincipalRoles(principal, domainName); } } 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 testGetPrincipalRoles() { createMockDomain("domain1"); createMockDomain("domain2"); createMockDomain("domain3"); String principal = "user.johndoe"; List<RoleMember> roleMembers = new ArrayList<>(); roleMembers.add(new RoleMember().setMemberName("user.test1")); roleMembers.add(new RoleMember().setMemberName("user.test2")); roleMembers.add(new RoleMember().setMemberName(principal)); Role role = createRoleObject("domain1", "role1", null, roleMembers); zms.dbService.executePutRole(mockDomRsrcCtx, "domain1", "role1", role, "test", "putrole"); role = createRoleObject("domain1", "role2", null, roleMembers); zms.dbService.executePutRole(mockDomRsrcCtx, "domain1", "role2", role, "test", "putrole"); roleMembers = new ArrayList<>(); roleMembers.add(new RoleMember().setMemberName("user.test1")); roleMembers.add(new RoleMember().setMemberName("user.test2")); role = createRoleObject("domain2", "role1", null, roleMembers); zms.dbService.executePutRole(mockDomRsrcCtx, "domain2", "role1", role, "test", "putrole"); roleMembers = new ArrayList<>(); roleMembers.add(new RoleMember().setMemberName(principal)); role = createRoleObject("domain3", "role1", null, roleMembers); zms.dbService.executePutRole(mockDomRsrcCtx, "domain3", "role1", role, "test", "putrole"); DomainRoleMember domainRoleMember = zms.dbService.getPrincipalRoles(principal, null); MemberRole memberRole0 = new MemberRole(); memberRole0.setDomainName("domain1"); memberRole0.setRoleName("role1"); MemberRole memberRole1 = new MemberRole(); memberRole1.setDomainName("domain1"); memberRole1.setRoleName("role2"); MemberRole memberRole2 = new MemberRole(); memberRole2.setDomainName("domain3"); memberRole2.setRoleName("role1"); assertEquals(domainRoleMember.getMemberName(), principal); assertEquals(domainRoleMember.getMemberRoles().size(), 3); assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole0)); assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole1)); assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole2)); domainRoleMember = zms.dbService.getPrincipalRoles(principal, "domain1"); assertEquals(domainRoleMember.getMemberName(), principal); assertEquals(domainRoleMember.getMemberRoles().size(), 2); assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole0)); assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole1)); zms.dbService.executeDeleteDomain(mockDomRsrcCtx, "domain1", auditRef, "deletedomain"); zms.dbService.executeDeleteDomain(mockDomRsrcCtx, "domain2", auditRef, "deletedomain"); zms.dbService.executeDeleteDomain(mockDomRsrcCtx, "domain3", auditRef, "deletedomain"); }