ZTSImpl implements KeyStore, ZTSHandler { String retrieveTenantDomainName(String roleName, String serviceName) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("retrieveTenantDomainName: Processing role name: " + roleName); } String[] comps = roleName.split("\\."); if (comps.length < 4) { return null; } if (!comps[1].equals("tenant")) { return null; } if (serviceName != null && !comps[0].equals(serviceName)) { return null; } if (comps.length == 4) { if (dataStore.getDataCache(comps[2]) == null) { return null; } return comps[2]; } String resourceGroup = comps[comps.length - 2]; StringBuilder domainNameBuf = new StringBuilder(512).append(comps[2]); for (int i = 3; i < comps.length - 2; i++) { domainNameBuf.append('.').append(comps[i]); } String fullDomainName = domainNameBuf.toString() + "." + resourceGroup; if (dataStore.getDataCache(fullDomainName) != null) { return fullDomainName; } fullDomainName = domainNameBuf.toString(); if (dataStore.getDataCache(fullDomainName) != null) { return fullDomainName; } return null; } 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 testRetrieveTenantDomainNameInvalidEntries() { assertNull(zts.retrieveTenantDomainName("dom1", null)); assertNull(zts.retrieveTenantDomainName("dom1.tenant", null)); assertNull(zts.retrieveTenantDomainName("dom1.tenant.dom3", null)); assertNull(zts.retrieveTenantDomainName("dom1.dom2.dom3.admin", null)); assertNull(zts.retrieveTenantDomainName("dom1.dom2.tenant.read", null)); assertNull(zts.retrieveTenantDomainName("tenant.dom2.dom3.write", null)); assertNull(zts.retrieveTenantDomainName("service1.tenant.dom3.read", "service2")); assertNull(zts.retrieveTenantDomainName("service2.tenant.dom3.dom4.admin", "service")); }
@Test public void testRetrieveTenantDomainName4CompsValidDomain() { SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true); store.processDomain(signedDomain, false); assertEquals("coretech", zts.retrieveTenantDomainName("storage.tenant.coretech.admin", "storage")); assertEquals("coretech", zts.retrieveTenantDomainName("storage.tenant.coretech.admin", null)); }
@Test public void testRetrieveTenantDomainName4CompsInvalidDomain() { assertNull(zts.retrieveTenantDomainName("storage.tenant.coretech_unknown.admin", "storage")); assertNull(zts.retrieveTenantDomainName("storage.tenant.coretech_unknown.admin", null)); }
@Test public void testRetrieveTenantDomainName4PlusCompsValidDomainWithResourceGroup() { SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true); store.processDomain(signedDomain, false); assertEquals("coretech", zts.retrieveTenantDomainName("storage.tenant.coretech.resource_group.admin", "storage")); assertEquals("coretech", zts.retrieveTenantDomainName("storage.tenant.coretech.resource_group.admin", null)); signedDomain = createSignedDomain("coretech.office.burbank", "weather", "storage", true); store.processDomain(signedDomain, false); assertEquals("coretech.office.burbank", zts.retrieveTenantDomainName("storage.tenant.coretech.office.burbank.resource_group.admin", "storage")); assertEquals("coretech.office.burbank", zts.retrieveTenantDomainName("storage.tenant.coretech.office.burbank.resource_group.admin", null)); }
@Test public void testRetrieveTenantDomainName4PlusCompsValidDomainWithOutResourceGroup() { SignedDomain signedDomain = createSignedDomain("coretech.office.burbank", "weather", "storage", true); store.processDomain(signedDomain, false); assertEquals("coretech.office.burbank", zts.retrieveTenantDomainName("storage.tenant.coretech.office.burbank.admin", "storage")); assertEquals("coretech.office.burbank", zts.retrieveTenantDomainName("storage.tenant.coretech.office.burbank.admin", null)); }
@Test public void testRetrieveTenantDomainName4PlusCompsInvalidDomain() { SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true); store.processDomain(signedDomain, false); assertNull(zts.retrieveTenantDomainName("storage.tenant.coretech.office.glendale.admin", "storage")); assertNull(zts.retrieveTenantDomainName("storage.tenant.coretech.office.glendale.resource_group.admin", null)); }