ZTSImpl implements KeyStore, ZTSHandler { int getConfiguredRoleCertExpiryTimeMins(DataCache data, Set<String> roles) { int maxAllowedExpiry = 0; for (String role: roles) { RoleMeta rm = data.getRoleMeta(role); if (rm == null) { continue; } Integer certExpiryMins = rm.getCertExpiryMins(); if (certExpiryMins == null) { continue; } if (certExpiryMins > 0 && (maxAllowedExpiry == 0 || certExpiryMins < maxAllowedExpiry)) { maxAllowedExpiry = certExpiryMins; } } if (maxAllowedExpiry == 0) { Integer certExpiryMins = data.getDomainData().getRoleCertExpiryMins(); if (certExpiryMins != null && certExpiryMins > 0) { maxAllowedExpiry = certExpiryMins; } } return maxAllowedExpiry; } 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 testGetConfiguredRoleExpiryTimeMinsNoSettings() { DataCache data = new DataCache(); Role role = new Role().setName("athenz:role.admin"); data.processRole(role); data.setDomainData(new DomainData()); Set<String> roles = new HashSet<>(); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 0); roles.add("readers"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 0); roles.add("admin"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 0); }
@Test public void testGetConfiguredRoleExpiryTimeMinsDomainSettings() { DataCache data = new DataCache(); Role role = new Role().setName("athenz:role.admin"); data.processRole(role); DomainData domainData = new DomainData(); domainData.setRoleCertExpiryMins(120); data.setDomainData(domainData); Set<String> roles = new HashSet<>(); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); roles.add("readers"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); roles.add("admin"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); }
@Test public void testGetConfiguredRoleExpiryTimeMinsInvalidDomainSettings() { DataCache data = new DataCache(); Role role = new Role().setName("athenz:role.admin"); data.processRole(role); DomainData domainData = new DomainData(); domainData.setRoleCertExpiryMins(-60); data.setDomainData(domainData); Set<String> roles = new HashSet<>(); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 0); roles.add("readers"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 0); roles.add("admin"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 0); }
@Test public void testGetConfiguredRoleExpiryTimeMinsInvalidRoleSettings() { DataCache data = new DataCache(); Role role = new Role().setName("athenz:role.admin").setCertExpiryMins(-30); data.processRole(role); DomainData domainData = new DomainData(); domainData.setRoleCertExpiryMins(120); data.setDomainData(domainData); Set<String> roles = new HashSet<>(); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); roles.add("readers"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); roles.add("admin"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); }
@Test public void testGetConfiguredRoleExpiryTimeMinsRoleSettings() { DataCache data = new DataCache(); Role role = new Role().setName("athenz:role.admin").setCertExpiryMins(180); data.processRole(role); DomainData domainData = new DomainData(); domainData.setRoleCertExpiryMins(120); data.setDomainData(domainData); Set<String> roles = new HashSet<>(); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); roles.add("readers"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); roles.add("admin"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 180); }
@Test public void testGetConfiguredRoleExpiryTimeMinsMultipleRoleSettings() { DataCache data = new DataCache(); Role role1 = new Role().setName("athenz:role.admin").setCertExpiryMins(60); data.processRole(role1); Role role2 = new Role().setName("athenz:role.readers").setCertExpiryMins(80); data.processRole(role2); Role role3 = new Role().setName("athenz:role.writers").setCertExpiryMins(70); data.processRole(role3); DomainData domainData = new DomainData(); domainData.setRoleCertExpiryMins(120); data.setDomainData(domainData); Set<String> roles = new HashSet<>(); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 120); roles.add("readers"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 80); roles.add("admin"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 60); roles.add("writers"); assertEquals(zts.getConfiguredRoleCertExpiryTimeMins(data, roles), 60); }