DBService implements RolesProvider { List<String> listPrincipals(String domainName, boolean domainOnly) { try (ObjectStoreConnection con = store.getConnection(true, false)) { List<String> principals = con.listPrincipals(domainName); if (!domainOnly) { return principals; } List<String> users = new ArrayList<>(); int prefixLength = 0; if (domainName != null) { prefixLength = domainName.length() + 1; } for (String principal : principals) { if (prefixLength > 0) { if (principal.substring(prefixLength).indexOf('.') == -1) { users.add(principal); } } else { if (principal.indexOf('.') == principal.lastIndexOf('.')) { users.add(principal); } } } return users; } } 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 testListPrincipalsUsersOnly() { String domainName = "listusers1"; TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); TopLevelDomain dom2 = createTopLevelDomainObject("listusersports", "Test Domain2", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom2); TopLevelDomain dom3 = createTopLevelDomainObject("listuserweather", "Test Domain3", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom3); Role role1 = createRoleObject(domainName, "role1", null, "user.joe", "user.janie"); zms.putRole(mockDomRsrcCtx, domainName, "role1", auditRef, role1); Role role2 = createRoleObject(domainName, "role2", null, "user.joe", "listusersports.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role2", auditRef, role2); Role role3 = createRoleObject(domainName, "role3", null, "user.jack", "listuserweather.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role3", auditRef, role3); Role role4 = createRoleObject("listusersports", "role4", null, "user.ana", "user.janie"); zms.putRole(mockDomRsrcCtx, "listusersports", "role4", auditRef, role4); List<String> users = zms.dbService.listPrincipals("user", true); assertEquals(users.size(), 5); assertTrue(users.contains("user.testadminuser")); assertTrue(users.contains("user.janie")); assertTrue(users.contains("user.ana")); assertTrue(users.contains("user.jack")); assertTrue(users.contains("user.joe")); zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); zms.deleteTopLevelDomain(mockDomRsrcCtx, "listusersports", auditRef); zms.deleteTopLevelDomain(mockDomRsrcCtx, "listuserweather", auditRef); }
@Test public void testListPrincipalsAll() { String domainName = "listusers1"; ZMSTestUtils.cleanupNotAdminUsers(zms, adminUser, mockDomRsrcCtx); TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); TopLevelDomain dom2 = createTopLevelDomainObject("listusersports", "Test Domain2", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom2); TopLevelDomain dom3 = createTopLevelDomainObject("listuserweather", "Test Domain3", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom3); Role role1 = createRoleObject(domainName, "role1", null, "user.joe", "user.janie"); zms.putRole(mockDomRsrcCtx, domainName, "role1", auditRef, role1); Role role2 = createRoleObject(domainName, "role2", null, "user.joe", "listusersports.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role2", auditRef, role2); Role role3 = createRoleObject(domainName, "role3", null, "user.jack", "listuserweather.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role3", auditRef, role3); Role role4 = createRoleObject("listusersports", "role4", null, "user.ana", "user.janie"); zms.putRole(mockDomRsrcCtx, "listusersports", "role4", auditRef, role4); Role role5 = createRoleObject("listusersports", "role5", null, null, null); zms.putRole(mockDomRsrcCtx, "listusersports", "role5", auditRef, role5); List<String> users = zms.dbService.listPrincipals(null, false); assertTrue(users.contains("user.testadminuser")); assertTrue(users.contains("user.janie")); assertTrue(users.contains("user.ana")); assertTrue(users.contains("user.jack")); assertTrue(users.contains("user.joe")); assertTrue(users.contains("listusersports.jane")); assertTrue(users.contains("listuserweather.jane")); zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); zms.deleteTopLevelDomain(mockDomRsrcCtx, "listusersports", auditRef); zms.deleteTopLevelDomain(mockDomRsrcCtx, "listuserweather", auditRef); }
@Test public void testListPrincipalsSubdomains() { String domainName = "listusers1"; TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); TopLevelDomain dom2 = createTopLevelDomainObject("listusersports", "Test Domain2", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom2); SubDomain subDom2 = createSubDomainObject("api", "listusersports", "Test SubDomain2", "testOrg", adminUser); zms.postSubDomain(mockDomRsrcCtx, "listusersports", auditRef, subDom2); Role role1 = createRoleObject(domainName, "role1", null, "user.joe", "user.janie"); zms.putRole(mockDomRsrcCtx, domainName, "role1", auditRef, role1); Role role2 = createRoleObject(domainName, "role2", null, "user.joe", "listusersports.jane"); zms.putRole(mockDomRsrcCtx, domainName, "role2", auditRef, role2); Role role3 = createRoleObject("listusersports", "role3", null, "user.ana", "listusersports.api.service"); zms.putRole(mockDomRsrcCtx, "listusersports", "role3", auditRef, role3); List<String> users = zms.dbService.listPrincipals(null, false); assertTrue(users.contains("user.testadminuser")); assertTrue(users.contains("user.janie")); assertTrue(users.contains("user.ana")); assertTrue(users.contains("user.joe")); assertTrue(users.contains("listusersports.jane")); assertTrue(users.contains("listusersports.api.service")); users = zms.dbService.listPrincipals(null, true); assertTrue(users.contains("user.testadminuser")); assertTrue(users.contains("user.janie")); assertTrue(users.contains("user.ana")); assertTrue(users.contains("user.joe")); assertTrue(users.contains("listusersports.jane")); assertFalse(users.contains("listusersports.api.service")); users = zms.dbService.listPrincipals("listusersports", false); assertEquals(users.size(), 2); assertTrue(users.contains("listusersports.jane")); assertTrue(users.contains("listusersports.api.service")); users = zms.dbService.listPrincipals("listusersports", true); assertEquals(users.size(), 1); assertTrue(users.contains("listusersports.jane")); zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); zms.deleteSubDomain(mockDomRsrcCtx, "listusersports", "api", auditRef); zms.deleteTopLevelDomain(mockDomRsrcCtx, "listusersports", auditRef); }