/** * Returns the credentials to access the given URL. * * @param url * the URL to find the credentials for, cannot be <code>null</code>. * @return a {@link UrlCredentials} instance for the given URL, or <code>null</code> if none were found, or if none * were necessary. */ final UrlCredentials getCredentials(URL url) { Collection<UrlCredentials> creds; synchronized (m_credentialMapping) { creds = new ArrayList<>(m_credentialMapping.values()); } for (UrlCredentials c : creds) { if (c.matches(url)) { return c; } } return null; }
/** * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#matches(java.net.URL)}. */ @Test public void testMatchesValidURLOk() throws Exception { UrlCredentials creds = new UrlCredentials(AuthType.NONE, new URL("http://localhost:8080/")); assert creds.matches(new URL("http://localhost:8080/obr")) : "Base URL should match given URL!"; assert creds.matches(new URL("http://localhost:8080")) == false : "Base URL shouldn't match given URL!"; assert creds.matches(new URL("http://localhost:8081/")) == false : "Base URL shouldn't match given URL!"; }
/** * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#matches(java.net.URL)}. */ @Test public void testMatchesNullURLOk() throws Exception { UrlCredentials creds = new UrlCredentials(AuthType.NONE, new URL("http://localhost:8080/")); assert creds.matches(null) == false : "Null URL should never match any credentials!"; }