/** * Creates a new CredentialsMapping instance that associates the specified credentials with the given location. * * @param credentials user credentials * @param realm the location to associate the credentials with * @param isPersistent if true, indicates to CredentialsManager that the credentials should be saved when the * application terminates. */ public CredentialsMapping(Credentials credentials, FileURL realm, boolean isPersistent) { this.credentials = credentials; this.isPersistent = isPersistent; this.realm = realm.getRealm(); }
/** * Creates a new ConnectionHandler for the given server URL using the Credentials included in the URL (potentially * <code>null</code>). * * @param serverURL URL of the server to connect to */ public ConnectionHandler(FileURL serverURL) { realm = serverURL.getRealm(); this.credentials = serverURL.getCredentials(); }
@Override protected FileSystem getHadoopFileSystem(FileURL url) throws IOException { // Note: getRealm returns a fresh instance every time FileURL realm = url.getRealm(); Configuration conf = new Configuration(); // Import the user from the URL's authority, if set // TODO: for some reason, setting the group has no effect: files are still created with the default supergroup conf.setStrings(UnixUserGroupInformation.UGI_PROPERTY_NAME, getUsername(url), getGroup(url)); return FileSystem.get(URI.create(realm.toString(false)), conf); }
@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); }
public static ConnectionHandler getConnectionHandler(ConnectionHandlerFactory connectionHandlerFactory, FileURL url, boolean acquireLock) throws InterruptedIOException { FileURL realm = url.getRealm();
/** * 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)); } } }
/** * Tests {@link com.mucommander.commons.file.FileURL#getRealm()} by ensuring that it returns the same URL only with the * path stripped out. * <p> * <b>Important:</b> this method must be overridden for protocols that have a specific realm notion (like SMB) or * else the test will fail. * </p> * * * @throws MalformedURLException should not happen */ @Test public void testRealm() throws MalformedURLException { assertEquals(getURL("host", "/"), getURL("host", "/path/to/file").getRealm()); }
/** * This method is overridden to test SMB's specific notion of realm. */ @Override public void testRealm() throws MalformedURLException { assertEquals(getURL("host", "/share"), getURL("host", "/share/path/to/file").getRealm()); } }