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); } }
@Override protected FileSystem getHadoopFileSystem(FileURL url) throws IOException { if(!url.containsCredentials()) throw new AuthException(url); // Note: getRealm returns a fresh instance every time FileURL realm = url.getRealm(); // Import credentials Credentials creds = url.getCredentials(); if(creds!=null) { // URL-encode secret as it may contain non URL-safe characters ('+' and '/') realm.setCredentials(new Credentials(creds.getLogin(), URLEncoder.encode(creds.getPassword(), "UTF-8"))); } // Change the scheme to the actual Hadoop fileystem (s3 -> s3n) realm.setScheme("s3n"); return FileSystem.get(URI.create(realm.toString(true, false)), DEFAULT_CONFIGURATION); }
/** * Looks for the best set of credentials matching the given location (if any) and use it to authenticate the * URL by calling {@link #authenticate(com.mucommander.commons.file.FileURL, CredentialsMapping)}. * Returns <code>true</code> if a set of credentials was found and used to authenticate the URL, <code>false</code> * otherwise. * * <p>Credentials are first looked for using {@link #getMatchingCredentials(com.mucommander.commons.file.FileURL)}. * If there is no match, guest credentials are retrieved from the URL and used (if any).</p> * * @param location the FileURL to authenticate */ private static void authenticateImplicit(FileURL location) { LOGGER.trace("called, fileURL="+ location +" containsCredentials="+ location.containsCredentials()); CredentialsMapping creds[] = getMatchingCredentials(location); if(creds.length>0) { authenticate(location, creds[0]); } else { Credentials guestCredentials = location.getGuestCredentials(); if(guestCredentials!=null) { authenticate(location, new CredentialsMapping(guestCredentials, location.getRealm(), false)); } } }
protected SMBFile(FileURL fileURL, SmbFile smbFile) throws IOException { super(fileURL); if(!fileURL.containsCredentials()) throw new AuthException(fileURL, "Authentication required");
if(login!=null) { assert login.equals(url.getLogin()); assert url.containsCredentials();
/** * Verifies the given path is not null, that it can be resolved by {@link FileFactory#getFile(String)} into * a file, and that this file is equal to the given one. If the given file is not a directory, the contents of both * file instances are compared to make sure they are equal. * * @param file the file instance that corresponds to the given path * @param path the path that should be resolved into the specified file * @throws IOException should not happen * @throws NoSuchAlgorithmException should not happen */ protected void testPathResolution(AbstractFile file, String path) throws IOException, NoSuchAlgorithmException { assert path != null; // If the file is authenticated, test if the given path contains credentials and if it does not, add the // credentials to it. if(file.getURL().containsCredentials()) { FileURL fileURL = FileURL.getFileURL(path); if(!fileURL.containsCredentials()) { fileURL.setCredentials(file.getURL().getCredentials()); path = fileURL.toString(true); } } // Assert that the file can be resolved again using the path, and that the resolved file is shallow-equal // and deep-equal AbstractFile resolvedFile = FileFactory.getFile(path); assert resolvedFile != null; assert resolvedFile.equals(file); // Shallow equals assert resolvedFile.isDirectory()==file.isDirectory(); if(!file.isDirectory()) assertContentsEquals(file, resolvedFile); // Deep equals (compares contents) }
assert !url.containsCredentials(); assert url.getHost() == null; assert -1 == url.getPort();
else if(!folderURL.containsCredentials() && ( (authenticationType==AuthenticationType.AUTHENTICATION_REQUIRED) || (authenticationType==AuthenticationType.AUTHENTICATION_OPTIONAL && CredentialsManager.getMatchingCredentials(folderURL).length>0))) {