private static AbstractFile createRawFile(FileURL fileURL, Authenticator authenticator, Object... instantiationParams) throws IOException { String scheme = fileURL.getScheme().toLowerCase(); // Special case for local files to avoid provider hashtable lookup and other unnecessary checks // (for performance reasons) if(scheme.equals(FileProtocols.FILE)) { if(localFileProvider == null) throw new IOException("Unknown file protocol: " + scheme); return localFileProvider.getFile(fileURL, instantiationParams); // Uncomment this line and comment the previous one to simulate a slow filesystem //file = new DebugFile(file, 0, 50); } // Use the protocol hashtable for any other file protocol else { // If an Authenticator has been specified and the specified FileURL's protocol is authenticated and the // FileURL doesn't contain any credentials, use it to authenticate the FileURL. if(authenticator!=null && fileURL.getAuthenticationType()!=AuthenticationType.NO_AUTHENTICATION && !fileURL.containsCredentials()) authenticator.authenticate(fileURL); // Finds the right file protocol provider ProtocolProvider provider = getProtocolProvider(scheme); if(provider == null) throw new IOException("Unknown file protocol: " + scheme); return provider.getFile(fileURL, instantiationParams); } }
/** * Ensures that the values returned by {@link FileURL#getAuthenticationType()} ()} and {@link SchemeHandler#getAuthenticationType()} * match the expected value returned by {@link #getAuthenticationType()}, and that the value is one of the constants * defined in {@link AuthenticationType}. * If the authentication type is {@link AuthenticationType#NO_AUTHENTICATION}, verifies that * {@link #getGuestCredentials()} returns <code>null</code>. * * @throws MalformedURLException should not happen */ @Test public void testAuthenticationType() throws MalformedURLException { FileURL url = getRootURL(); AuthenticationType expectedAuthenticationType = getAuthenticationType(); assert expectedAuthenticationType.equals(url.getAuthenticationType()); assert expectedAuthenticationType.equals(url.getHandler().getAuthenticationType()); assert expectedAuthenticationType==AuthenticationType.NO_AUTHENTICATION || expectedAuthenticationType==AuthenticationType.AUTHENTICATION_REQUIRED || expectedAuthenticationType==AuthenticationType.AUTHENTICATION_OPTIONAL; if(expectedAuthenticationType== AuthenticationType.NO_AUTHENTICATION) assert url.getGuestCredentials() == null; }
AuthenticationType authenticationType = folderURL.getAuthenticationType(); if(credentialsMapping!=null) { newCredentialsMapping = credentialsMapping;