DBService implements RolesProvider { PublicKeyEntry getPublicKeyFromCache(String domainName, String serviceName, String keyId) { DataCache data = cacheStore.getIfPresent(domainName); if (data == null) { return null; } AthenzDomain athenzDomain = data.getAthenzDomain(); if (athenzDomain == null) { return null; } List<ServiceIdentity> services = athenzDomain.getServices(); if (services == null) { return null; } final String fullServiceName = ZMSUtils.serviceResourceName(domainName, serviceName); for (ServiceIdentity service : services) { if (fullServiceName.equals(service.getName())) { List<PublicKeyEntry> publicKeys = service.getPublicKeys(); if (publicKeys != null) { for (PublicKeyEntry publicKey : publicKeys) { if (keyId.equals(publicKey.getId())) { return publicKey; } } } break; } } return null; } DBService(ObjectStore store, AuditLogger auditLogger, ZMSConfig zmsConfig, AuditReferenceValidator auditReferenceValidator); DomainRoleMembers listOverdueReviewRoleMembers(String domainName); @Override List<Role> getRolesByDomain(String domain); ResourceAccessList getResourceAccessList(String principal, String action); AthenzDomain getAthenzDomain(final String domainName, boolean masterCopy); Quota getQuota(String domainName); void executePutRoleSystemMeta(ResourceContext ctx, final String domainName, final String roleName,
           RoleSystemMeta meta, final String attribute, final String auditRef, final String caller); void executePutGroupSystemMeta(ResourceContext ctx, final String domainName, final String groupName,
                                          GroupSystemMeta meta, final String attribute, final String auditRef); void executePutServiceIdentitySystemMeta(ResourceContext ctx, String domainName, String serviceName,
            ServiceIdentitySystemMeta meta, String attribute, String auditRef, String caller); void executePutRoleMeta(ResourceContext ctx, String domainName, String roleName, Role originalRole,
                                   RoleMeta meta, String auditRef, String caller); void executePutGroupMeta(ResourceContext ctx, final String domainName, final String groupName,
                                    GroupMeta meta, final String auditRef); Set<String> getPendingMembershipApproverRoles(int delayDays); Set<String> getPendingGroupMembershipApproverRoles(int delayDays); Map<String, DomainRoleMember> getRoleExpiryMembers(int delayDays); Map<String, DomainRoleMember> getRoleReviewMembers(int delayDays); Map<String, DomainGroupMember> getGroupExpiryMembers(int delayDays); void processExpiredPendingMembers(int pendingRoleMemberLifespan, final String monitorIdentity); void processExpiredPendingGroupMembers(int pendingGroupMemberLifespan, final String monitorIdentity); static int AUDIT_TYPE_ROLE; static int AUDIT_TYPE_POLICY; static int AUDIT_TYPE_SERVICE; static int AUDIT_TYPE_DOMAIN; static int AUDIT_TYPE_ENTITY; static int AUDIT_TYPE_TENANCY; static int AUDIT_TYPE_TEMPLATE; static int AUDIT_TYPE_GROUP; }
@Test public void testGetPublicKeyFromCache() { final String domainName1 = "getcachepublickey"; final String domainName2 = "getcachepublickey2"; AthenzDomain athenzDomain1 = new AthenzDomain(domainName1); ServiceIdentity service1 = createServiceObject(domainName1, "service1", "http: "users", "host1"); ServiceIdentity service2 = createServiceObject(domainName1, "service2", "http: "users", "host1"); ServiceIdentity service3 = new ServiceIdentity(); service3.setName(ZMSUtils.serviceResourceName(domainName1, "service3")); List<ServiceIdentity> services = new ArrayList<>(); services.add(service1); services.add(service2); services.add(service3); athenzDomain1.setServices(services); DataCache dataCache1 = new DataCache(athenzDomain1, 101); AthenzDomain athenzDomain2 = new AthenzDomain(domainName2); DataCache dataCache2 = new DataCache(athenzDomain2, 101); zms.dbService.cacheStore.put(domainName1, dataCache1); zms.dbService.cacheStore.put(domainName2, dataCache2); PublicKeyEntry key = zms.dbService.getPublicKeyFromCache(domainName1, "service1", "1"); assertNotNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service1", "2"); assertNotNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service2", "1"); assertNotNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service2", "2"); assertNotNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service1", "3"); assertNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service2", "3"); assertNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service3", "1"); assertNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service4", "1"); assertNull(key); key = zms.dbService.getPublicKeyFromCache(domainName1, "service5", "2"); assertNull(key); key = zms.dbService.getPublicKeyFromCache(domainName2, "service1", "1"); assertNull(key); key = zms.dbService.getPublicKeyFromCache(domainName2, "service2", "1"); assertNull(key); }