ZTSImpl implements KeyStore, ZTSHandler { public TenantDomains getTenantDomains(ResourceContext ctx, String providerDomainName, String userName, String roleName, String serviceName) { final String caller = ctx.getApiName(); final String principalDomain = logPrincipalAndGetDomain(ctx); validateRequest(ctx.request(), principalDomain, caller); validate(providerDomainName, TYPE_DOMAIN_NAME, principalDomain, caller); validate(userName, TYPE_ENTITY_NAME, principalDomain, caller); if (roleName != null) { validate(roleName, TYPE_ENTITY_NAME, principalDomain, caller); } if (serviceName != null) { validate(serviceName, TYPE_SERVICE_NAME, principalDomain, caller); } providerDomainName = providerDomainName.toLowerCase(); setRequestDomain(ctx, providerDomainName); if (roleName != null) { roleName = roleName.toLowerCase(); } if (serviceName != null) { serviceName = serviceName.toLowerCase(); } userName = normalizeDomainAliasUser(userName.toLowerCase()); DataCache data = dataStore.getDataCache(providerDomainName); if (data == null) { setRequestDomain(ctx, ZTSConsts.ZTS_UNKNOWN_DOMAIN); throw notFoundError("getTenantDomains: No such provider domain: " + providerDomainName, caller, ZTSConsts.ZTS_UNKNOWN_DOMAIN, principalDomain); } if (userName.indexOf('.') == -1) { userName = this.userDomain + "." + userName; } roleName = convertEmptyStringToNull(roleName); String[] requestedRoleList = null; if (roleName != null) { requestedRoleList = roleName.split(","); } Set<String> roles = new HashSet<>(); dataStore.getAccessibleRoles(data, providerDomainName, userName, requestedRoleList, roles, false); Set<String> domainNames = new HashSet<>(); for (String role : roles) { String domainName = retrieveTenantDomainName(role, serviceName); if (domainName != null) { domainNames.add(domainName); } } TenantDomains tenantDomains = new TenantDomains(); tenantDomains.setTenantDomainNames(new ArrayList<>(domainNames)); return tenantDomains; } ZTSImpl();  ZTSImpl(CloudStore implCloudStore, DataStore implDataStore); @Override String getPublicKey(String domain, String service, String keyId); ServiceIdentity getServiceIdentity(ResourceContext ctx, String domainName, String serviceName); PublicKeyEntry getPublicKeyEntry(ResourceContext ctx, String domainName,
            String serviceName, String keyId); ServiceIdentityList getServiceIdentityList(ResourceContext ctx, String domainName); HostServices getHostServices(ResourceContext ctx, String host); Response getDomainSignedPolicyData(ResourceContext ctx, String domainName, String matchingTag); TenantDomains getTenantDomains(ResourceContext ctx, String providerDomainName,
            String userName, String roleName, String serviceName); @Override RoleToken getRoleToken(ResourceContext ctx, String domainName, String roleNames,
            Integer minExpiryTime, Integer maxExpiryTime, String proxyForPrincipal); @Override AccessTokenResponse postAccessTokenRequest(ResourceContext ctx, String request); RoleAccess getRoleAccess(ResourceContext ctx, String domainName, String principal); @Override RoleToken postRoleCertificateRequest(ResourceContext ctx, String domainName,
            String roleName, RoleCertificateRequest req); @Override RoleCertificate postRoleCertificateRequestExt(ResourceContext ctx, RoleCertificateRequest req); AWSTemporaryCredentials getAWSTemporaryCredentials(ResourceContext ctx, String domainName,
            String roleName, Integer durationSeconds, String externalId); @Override Response postInstanceRegisterInformation(ResourceContext ctx, InstanceRegisterInformation info); @Override InstanceIdentity postInstanceRefreshInformation(ResourceContext ctx, String provider,
            String domain, String service, String instanceId, InstanceRefreshInformation info); @Override void deleteInstanceIdentity(ResourceContext ctx, String provider,
            String domain, String service, String instanceId); @Deprecated @Override Identity postInstanceRefreshRequest(ResourceContext ctx, String domain,
            String service, InstanceRefreshRequest req); @Override Response postSSHCertRequest(ResourceContext ctx, SSHCertRequest certRequest); @Override JWKList getJWKList(ResourceContext ctx, Boolean rfc); @Deprecated @Override Identity postOSTKInstanceRefreshRequest(ResourceContext ctx, String domain,
            String service, OSTKInstanceRefreshRequest req); @Override ResourceAccess getResourceAccessExt(ResourceContext ctx, String action, String resource,
            String trustDomain, String checkPrincipal); @Override ResourceAccess getResourceAccess(ResourceContext ctx, String action, String resource,
            String trustDomain, String checkPrincipal); @Override Access getAccess(ResourceContext ctx, String domainName, String roleName,
            String principal); CertificateAuthorityBundle getCertificateAuthorityBundle(ResourceContext ctx, String name); @Override DomainMetrics postDomainMetrics(ResourceContext ctx, String domainName,
            DomainMetrics domainMetrics); @Override Status getStatus(ResourceContext ctx); @Override Schema getRdlSchema(ResourceContext context); ResourceContext newResourceContext(HttpServletRequest request,
                                              HttpServletResponse response,
                                              String apiName); static String getRootDir(); void recordMetrics(ResourceContext ctx, int httpStatus);  }
@Test public void testGetTenantDomainsSingleDomain() { SignedDomain signedDomain = createSignedDomain("athenz.product", "weather.frontpage", "storage", true); store.processDomain(signedDomain, false); signedDomain = createTenantSignedDomain("weather.frontpage", "athenz.product", "storage"); store.processDomain(signedDomain, false); SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority()); ResourceContext context = createResourceContext(principal); TenantDomains tenantDomains = zts.getTenantDomains(context, "athenz.product", "user_domain.user100", null, null); assertNotNull(tenantDomains); assertEquals(tenantDomains.getTenantDomainNames().size(), 1); assertEquals(tenantDomains.getTenantDomainNames().get(0), "weather.frontpage"); }
@Test public void testGetTenantDomainsSingleDomainRoleSvcName() { SignedDomain signedDomain = createSignedDomain("athenz.product", "weather.frontpage", "storage", true); store.processDomain(signedDomain, false); signedDomain = createTenantSignedDomain("weather.frontpage", "athenz.product", "storage"); store.processDomain(signedDomain, false); SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority()); ResourceContext context = createResourceContext(principal); TenantDomains tenantDomains = zts.getTenantDomains(context, "athenz.product", "user_domain.user100", "storage.tenant.weather.frontpage.admin", "storage"); assertNotNull(tenantDomains); assertEquals(tenantDomains.getTenantDomainNames().size(), 1); assertEquals(tenantDomains.getTenantDomainNames().get(0), "weather.frontpage"); }
@Test public void testGetTenantDomainsMultipleDomains() { SignedDomain signedDomain = createMultipleSignedDomains("athenz.multiple", "hockey.kings", "hockey.stars", "storage", true); store.processDomain(signedDomain, false); signedDomain = createTenantSignedDomain("hockey.kings", "athenz.multiple", "storage"); store.processDomain(signedDomain, false); signedDomain = createTenantSignedDomain("hockey.stars", "athenz.multiple", "storage"); store.processDomain(signedDomain, false); SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority()); ResourceContext context = createResourceContext(principal); TenantDomains tenantDomains = zts.getTenantDomains(context, "athenz.multiple", "user_domain.user100", null, null); assertNotNull(tenantDomains); assertEquals(tenantDomains.getTenantDomainNames().size(), 2); assertTrue(tenantDomains.getTenantDomainNames().contains("hockey.kings")); assertTrue(tenantDomains.getTenantDomainNames().contains("hockey.stars")); }
@Test public void testGetTenantDomainsInvalidUser() { SignedDomain signedDomain = createSignedDomain("athenz.product", "weather.frontpage", "storage", true); store.processDomain(signedDomain, false); signedDomain = createTenantSignedDomain("weather.frontpage", "athenz.product", "storage"); store.processDomain(signedDomain, false); SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority()); ResourceContext context = createResourceContext(principal); TenantDomains tenantDomains = zts.getTenantDomains(context, "athenz.product", "user1099", null, null); assertNotNull(tenantDomains); assertEquals(tenantDomains.getTenantDomainNames().size(), 0); }
@Test public void testGetTenantDomainsInvalidDomain() { SignedDomain signedDomain = createSignedDomain("athenz.product", "weather.frontpage", "storage", true); store.processDomain(signedDomain, false); signedDomain = createTenantSignedDomain("weather.frontpage", "athenz.product", "storage"); store.processDomain(signedDomain, false); SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority()); ResourceContext context = createResourceContext(principal); try { zts.getTenantDomains(context, "athenz.non_product", "user100", null, null); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), 404); } }