PrincipalAuthority implements Authority, AuthorityKeyStore { String getAuthorizedServiceName(List<String> authorizedServices, String authorizedServiceName) { String serviceName = authorizedServiceName; if (serviceName == null) { if (authorizedServices.size() != 1) { LOG.error("getAuthorizedServiceName() failed: No authorized service name specified"); return null; } serviceName = authorizedServices.get(0); } else { if (!authorizedServices.contains(serviceName)) { LOG.error("getAuthorizedServiceName() failed: Invalid authorized service name specified:" + serviceName); return null; } } return serviceName; } PrincipalAuthority(); @Override String getID(); @Override void initialize(); @Override String getDomain(); @Override String getHeader(); @Override String getAuthenticateChallenge(); @Override Principal authenticate(String signedToken, String remoteAddr, String httpMethod,
            StringBuilder errMsg); @Override void setKeyStore(KeyStore keyStore); static final String HTTP_HEADER; static final String ATHENZ_AUTH_CHALLENGE; static final String ATHENZ_PROP_PRINCIPAL_HEADER; }
@Test public void testGetAuthorizedServiceNameMultipleServices() { PrincipalAuthority serviceAuthority = new PrincipalAuthority(); List<String> authorizedServices = new ArrayList<>(); authorizedServices.add("coretech.storage"); authorizedServices.add("media.storage"); assertNull(serviceAuthority.getAuthorizedServiceName(authorizedServices, null)); assertNull(serviceAuthority.getAuthorizedServiceName(authorizedServices, "sports.storage")); assertEquals(serviceAuthority.getAuthorizedServiceName(authorizedServices, "coretech.storage"), "coretech.storage"); }
@Test public void testGetAuthorizedServiceNameSingleServices() { PrincipalAuthority serviceAuthority = new PrincipalAuthority(); List<String> authorizedServices = new ArrayList<>(); authorizedServices.add("coretech.storage"); assertEquals(serviceAuthority.getAuthorizedServiceName(authorizedServices, null), "coretech.storage"); assertNull(serviceAuthority.getAuthorizedServiceName(authorizedServices, "sports.storage")); assertEquals(serviceAuthority.getAuthorizedServiceName(authorizedServices, "coretech.storage"), "coretech.storage"); }