ZTSImpl implements KeyStore, ZTSHandler { List<Policy> getPolicyList(DomainData domainData) { ArrayList<Policy> ztsPolicies = new ArrayList<>(); com.yahoo.athenz.zms.SignedPolicies signedPolicies = domainData.getPolicies(); if (signedPolicies == null) { return ztsPolicies; } com.yahoo.athenz.zms.DomainPolicies domainPolicies = signedPolicies.getContents(); if (domainPolicies == null) { return ztsPolicies; } List<com.yahoo.athenz.zms.Policy> zmsPolicies = domainPolicies.getPolicies(); if (zmsPolicies == null) { return ztsPolicies; } for (com.yahoo.athenz.zms.Policy zmsPolicy : zmsPolicies) { Policy ztsPolicy = new Policy() .setModified(zmsPolicy.getModified()) .setName(zmsPolicy.getName()); List<com.yahoo.athenz.zms.Assertion> zmsAssertions = zmsPolicy.getAssertions(); if (zmsAssertions != null) { ArrayList<Assertion> ztsAssertions = new ArrayList<>(); for (com.yahoo.athenz.zms.Assertion zmsAssertion : zmsAssertions) { Assertion ztsAssertion = new Assertion() .setAction(zmsAssertion.getAction()) .setResource(zmsAssertion.getResource()) .setRole(zmsAssertion.getRole()) .setEffect(getAssertionEffect(zmsAssertion.getEffect())); ztsAssertions.add(ztsAssertion); } ztsPolicy.setAssertions(ztsAssertions); } ztsPolicies.add(ztsPolicy); } return ztsPolicies; } 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 testGetPolicyList() { List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>(); List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>(); com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy(); com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion(); assertion.setResource("coretech:tenant.weather.*"); assertion.setAction("read"); assertion.setRole("coretech:role.readers"); assertions.add(assertion); policy.setAssertions(assertions); policy.setName("coretech:policy.reader"); policies.add(policy); policy = new com.yahoo.athenz.zms.Policy(); assertion = new com.yahoo.athenz.zms.Assertion(); assertion.setResource("coretech:tenant.weather.*"); assertion.setAction("write"); assertion.setRole("coretech:role.writers"); assertions.add(assertion); policy.setAssertions(assertions); policy.setName("coretech:policy.writer"); policies.add(policy); com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies(); domainPolicies.setDomain("coretech"); domainPolicies.setPolicies(policies); com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies(); signedPolicies.setContents(domainPolicies); signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), privateKey)); signedPolicies.setKeyId("0"); DomainData domain = new DomainData(); domain.setName("coretech"); domain.setPolicies(signedPolicies); domain.setModified(Timestamp.fromCurrentTime()); List<com.yahoo.athenz.zts.Policy> policyList = zts.getPolicyList(domain); assertEquals(policyList.size(), 2); assertEquals(policyList.get(0).getName(), "coretech:policy.reader"); assertEquals(policyList.get(1).getName(), "coretech:policy.writer"); }
@Test public void testGetPolicyListPoliciesNull() { DomainData domain = new DomainData(); domain.setName("coretech"); domain.setPolicies(null); domain.setModified(Timestamp.fromCurrentTime()); List<com.yahoo.athenz.zts.Policy> policyList = zts.getPolicyList(domain); assertEquals(policyList.size(), 0); }
@Test public void testGetPolicyListPoliciesEmpty() { DomainData domain = new DomainData(); domain.setName("coretech"); List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>(); com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies(); domainPolicies.setDomain("coretech"); domainPolicies.setPolicies(policies); com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies(); signedPolicies.setContents(domainPolicies); signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), privateKey)); signedPolicies.setKeyId("0"); domain.setPolicies(signedPolicies); domain.setModified(Timestamp.fromCurrentTime()); List<com.yahoo.athenz.zts.Policy> policyList = zts.getPolicyList(domain); assertEquals(policyList.size(), 0); }
@Test public void testGetPolicyListEmptyValues() { DomainData domainData = new DomainData(); SignedPolicies signedPolicies = new SignedPolicies(); domainData.setPolicies(signedPolicies); List<com.yahoo.athenz.zts.Policy> policies = zts.getPolicyList(domainData); assertTrue(policies.isEmpty()); DomainPolicies domainPolicies = new DomainPolicies(); signedPolicies.setContents(domainPolicies); policies = zts.getPolicyList(domainData); assertTrue(policies.isEmpty()); Policy policy = new Policy(); policy.setName("policy1"); List<Policy> zmsPolicies = new ArrayList<>(); zmsPolicies.add(policy); domainPolicies.setPolicies(zmsPolicies); policies = zts.getPolicyList(domainData); assertEquals(1, policies.size()); assertNull(policies.get(0).getAssertions()); }