ZTSClient implements Closeable { public RoleAccess getRoleAccess(String domainName, String principal) { updateServicePrincipal(); ZTSClientCache.DomainAndPrincipal cacheKey = null; Cache<ZTSClientCache.DomainAndPrincipal, RoleAccess> cache = ztsClientCache.getRoleAccessCache(); if (cache != null) { cacheKey = new ZTSClientCache.DomainAndPrincipal(domainName, principal); RoleAccess cachedValue = cache.get(cacheKey); if (cachedValue != null) { return cachedValue; } } try { RoleAccess roleAccess = ztsClient.getRoleAccess(domainName, principal); if (cache != null) { cache.put(cacheKey, roleAccess); } return roleAccess; } catch (ResourceException ex) { throw new ZTSClientException(ex.getCode(), ex.getMessage()); } catch (Exception ex) { throw new ZTSClientException(ZTSClientException.BAD_REQUEST, ex.getMessage()); } } ZTSClient();  ZTSClient(String ztsUrl);  ZTSClient(Principal identity);  ZTSClient(String ztsUrl, Principal identity);  ZTSClient(String ztsUrl, SSLContext sslContext);  ZTSClient(String ztsUrl, String proxyUrl, SSLContext sslContext);  ZTSClient(String domainName, String serviceName, ServiceIdentityProvider siaProvider);  ZTSClient(String ztsUrl, String domainName, String serviceName,
                     ServiceIdentityProvider siaProvider); static void setX509CertDnsName(final String dnsName); static void setConnectionTimeouts(int connectTimeout, int readTimeout); static void setX509CsrDetails(final String csrDn, final String csrDomain); static void setCacheDisable(boolean cacheState); static void setPrefetchAutoEnable(boolean fetchState); static void setPrefetchInterval(int interval); static void setTokenMinExpiryTime(int minExpiryTime); static void lookupZTSUrl(); static void initZTSAccessTokenFileLoader(); static void setAccessTokenSignKeyResolver(JwtsSigningKeyResolver jwtsSigningKeyResolver); @Override void close(); void setEnablePrefetch(boolean state); void setProperty(String name, Object value); void setNotificationSender(ZTSClientNotificationSender notificationSender); static void cancelPrefetch(); String getZTSUrl(); void setZTSRDLGeneratedClient(ZTSRDLGeneratedClient client); void setZTSClientCache(ZTSClientCache ztsClientCache); SSLContext createSSLContext(final String trustStorePath, final char[] trustStorePassword,
                 final String publicCertFile, final String privateKeyFile, boolean monitorKeyCertUpdates); static String getHeader(); ZTSClient addCredentials(Principal identity); void addCredentials(String credHeader, String credToken); ZTSClient clearCredentials(); HostServices getHostServices(String host); JWKList getJWKList(boolean rfcCurveNames); JWKList getJWKList(); RoleToken getRoleToken(String domainName); RoleToken getRoleToken(String domainName, String roleNames); RoleToken getRoleToken(String domainName, String roleNames, Integer minExpiryTime,
            Integer maxExpiryTime, boolean ignoreCache); RoleToken getRoleToken(String domainName, String roleNames, Integer minExpiryTime,
            Integer maxExpiryTime, boolean ignoreCache, String proxyForPrincipal); AccessTokenResponse getAccessToken(String domainName, List<String> roleNames, long expiryTime); AccessTokenResponse getAccessToken(String domainName, List<String> roleNames,
            String idTokenServiceName, long expiryTime, boolean ignoreCache); AccessTokenResponse getAccessToken(String domainName, List<String> roleNames, String idTokenServiceName,
            String proxyForPrincipal, long expiryTime, boolean ignoreCache); RoleToken postRoleCertificateRequest(String domainName, String roleName,
            RoleCertificateRequest req); static RoleCertificateRequest generateRoleCertificateRequest(final String principalDomain,
            final String principalService, final String roleDomainName, final String roleName,
            PrivateKey privateKey, final String csrDn, final String csrDomain, int expiryTime); static RoleCertificateRequest generateRoleCertificateRequest(final String principalDomain,
            final String principalService, final String roleDomainName, final String roleName,
            final PrivateKey privateKey, final String cloud, int expiryTime); static InstanceRefreshRequest generateInstanceRefreshRequest(final String principalDomain,
            final String principalService, PrivateKey privateKey, final String csrDn,
            final String csrDomain, int expiryTime); static InstanceRefreshRequest generateInstanceRefreshRequest(String principalDomain,
            String principalService, PrivateKey privateKey, String cloud, int expiryTime); boolean prefetchAccessToken(String domainName, List<String> roleNames,
            String idTokenServiceName, String proxyForPrincipal, long expiryTime); RoleAccess getRoleAccess(String domainName, String principal); ServiceIdentity getServiceIdentity(String domainName, String serviceName); PublicKeyEntry getPublicKeyEntry(String domainName, String serviceName, String keyId); ServiceIdentityList getServiceIdentityList(String domainName); TenantDomains getTenantDomains(String providerDomainName, String userName,
            String roleName, String serviceName); Identity postInstanceRefreshRequest(String domain, String service, InstanceRefreshRequest req); AWSLambdaIdentity getAWSLambdaServiceCertificate(String domainName,
            String serviceName, String account, String provider); AWSCredentialsProvider getAWSCredentialProvider(String domainName, String roleName); AWSCredentialsProvider getAWSCredentialProvider(String domainName, String roleName,
            String externalId, Integer minExpiryTime, Integer maxExpiryTime); AWSTemporaryCredentials getAWSTemporaryCredentials(String domainName, String roleName); AWSTemporaryCredentials getAWSTemporaryCredentials(String domainName, String roleName,
            boolean ignoreCache); AWSTemporaryCredentials getAWSTemporaryCredentials(String domainName, String roleName,
            String externalId, Integer minExpiryTime, Integer maxExpiryTime); AWSTemporaryCredentials getAWSTemporaryCredentials(String domainName, String roleName,
            String externalId, Integer minExpiryTime, Integer maxExpiryTime, boolean ignoreCache); DomainSignedPolicyData getDomainSignedPolicyData(String domainName, String matchingTag,
            Map<String, List<String>> responseHeaders); Access getAccess(String domainName, String roleName, String principal); ResourceAccess getResourceAccess(String action, String resource, String trustDomain, String principal); ResourceAccess getResourceAccessExt(String action, String resource, String trustDomain, String principal); void postDomainMetrics(String domainName, DomainMetrics req); InstanceIdentity postInstanceRegisterInformation(InstanceRegisterInformation info,
            Map<String, List<String>> responseHeaders); InstanceIdentity postInstanceRefreshInformation(String provider, String domain,
            String service, String instanceId, InstanceRefreshInformation info); void deleteInstanceIdentity(String provider, String domain,
            String service, String instanceId); CertificateAuthorityBundle getCertificateAuthorityBundle(String bundleName); static final String ZTS_CLIENT_PROP_ATHENZ_CONF; static final String ZTS_CLIENT_PROP_TOKEN_MIN_EXPIRY_TIME; static final String ZTS_CLIENT_PROP_READ_TIMEOUT; static final String ZTS_CLIENT_PROP_CONNECT_TIMEOUT; static final String ZTS_CLIENT_PROP_PREFETCH_SLEEP_INTERVAL; static final String ZTS_CLIENT_PROP_PREFETCH_AUTO_ENABLE; static final String ZTS_CLIENT_PROP_X509CERT_DNS_NAME; static final String ZTS_CLIENT_PROP_X509CSR_DN; static final String ZTS_CLIENT_PROP_X509CSR_DOMAIN; static final String ZTS_CLIENT_PROP_DISABLE_CACHE; static final String ZTS_CLIENT_PROP_CERT_ALIAS; static final String ZTS_CLIENT_PROP_KEYSTORE_PATH; static final String ZTS_CLIENT_PROP_KEYSTORE_TYPE; static final String ZTS_CLIENT_PROP_KEYSTORE_PASSWORD; static final String ZTS_CLIENT_PROP_KEYSTORE_PWD_APP_NAME; static final String ZTS_CLIENT_PROP_KEY_MANAGER_PASSWORD; static final String ZTS_CLIENT_PROP_KEY_MANAGER_PWD_APP_NAME; static final String ZTS_CLIENT_PROP_TRUSTSTORE_PATH; static final String ZTS_CLIENT_PROP_TRUSTSTORE_TYPE; static final String ZTS_CLIENT_PROP_TRUSTSTORE_PASSWORD; static final String ZTS_CLIENT_PROP_TRUSTSTORE_PWD_APP_NAME; static final String ZTS_CLIENT_PROP_POOL_MAX_PER_ROUTE; static final String ZTS_CLIENT_PROP_POOL_MAX_TOTAL; static final String ZTS_CLIENT_PROP_PRIVATE_KEY_STORE_FACTORY_CLASS; static final String ZTS_CLIENT_PROP_CLIENT_PROTOCOL; static final String ZTS_CLIENT_PKEY_STORE_FACTORY_CLASS; static final String ZTS_CLIENT_DEFAULT_CLIENT_SSL_PROTOCOL; static final String ROLE_TOKEN_HEADER; }
@Test public void testGetRoleAccess() { ZTSRDLClientMock ztsClientMock = new ZTSRDLClientMock(); Principal principal = SimplePrincipal.create("user_domain", "user", "v=S1;d=user_domain;n=user;s=sig", PRINCIPAL_AUTHORITY); ZTSClient client = new ZTSClient("http: client.setZTSRDLGeneratedClient(ztsClientMock); RoleAccess roleAccess = client.getRoleAccess("coretech", "user.joe"); List<String> roles = roleAccess.getRoles(); assertEquals(roles.size(), 2); assertTrue(roles.contains("role1")); try { client.getRoleAccess("exc", "user.joe"); fail(); } catch (ZTSClientException ex) { assertEquals(ex.getCode(), 400); } try { client.getRoleAccess("unknown", "user.joe"); fail(); } catch (ZTSClientException ex) { assertEquals(ex.getCode(), 404); } client.close(); }