@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!(lastURL.toLowerCase().startsWith(FileProtocols.HTTP+"://") || lastURL.toLowerCase().startsWith(FileProtocols.HTTPS+"://"))) lastURL = FileProtocols.HTTP+"://"+lastURL; FileURL fileURL = FileURL.getFileURL(lastURL); fileURL.setCredentials(new Credentials(lastUsername, lastPassword)); return fileURL; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); FileURL url = FileURL.getFileURL(FileProtocols.SMB+"://"+lastServer+(lastShare.startsWith("/")?"":"/")+lastShare); // Insert the domain (if any) before the username, separated by a semicolon String userInfo = lastUsername; if(!lastDomain.equals("")) userInfo = lastDomain+";"+userInfo; url.setCredentials(new Credentials(userInfo, lastPassword)); return url; }
/** * Throws an {@link AuthException} using this connection handler's realm, credentials and the message passed as * an argument (can be <code>null</code>). The FileURL instance representing the realm that is used to create * the <code>AuthException</code> is a clone of this realm, making it safe for modification. * * @param message the message to pass to AuthException's constructor, can be <code>null</code> * @throws AuthException always throws the created AuthException */ public void throwAuthException(String message) throws AuthException { FileURL clonedRealm = (FileURL)realm.clone(); clonedRealm.setCredentials(credentials); throw new AuthException(clonedRealm, message); }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); FileURL url = FileURL.getFileURL(FileProtocols.VSPHERE + "://" + lastVsphere + "/" + lastGuest + "/" + PathUtils.removeLeadingSeparator(lastDir)); url.setCredentials(new Credentials(lastUsername, new String(passwordField.getPassword()))); url.setProperty(VSphereFile.GUEST_CREDENTIALS, lastGuestUsername + ":" + new String(guestPasswordField.getPassword())); return url; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.SFTP+"://"+lastServer+lastInitialDir); // Set credentials url.setCredentials(new Credentials(lastUsername, lastPassword)); if(!"".equals(lastKeyPath.trim())) url.setProperty(SFTPFile.PRIVATE_KEY_PATH_PROPERTY_NAME, lastKeyPath); // Set port url.setPort(lastPort); return url; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.S3+"://"+lastServer+lastInitialDir); // Set credentials url.setCredentials(new Credentials(lastUsername, lastPassword)); // Set port url.setPort(lastPort); return url; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.HDFS+"://"+lastServer+lastInitialDir); // Set user and group url.setCredentials(new Credentials(lastUsername, "")); // url.setProperty(HDFSFile.GROUP_PROPERTY_NAME, lastGroup); // Set port url.setPort(lastPort); return url; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.FTP+"://"+lastServer+lastInitialDir); if(anonymousUser) url.setCredentials(new Credentials(ANONYMOUS_CREDENTIALS.getLogin(), new String(passwordField.getPassword()))); else url.setCredentials(new Credentials(lastUsername, lastPassword)); // Set port url.setPort(lastPort); // Set passiveMode property to true (default) or false url.setProperty(FTPFile.PASSIVE_MODE_PROPERTY_NAME, ""+passiveMode); // Set FTP encoding property url.setProperty(FTPFile.ENCODING_PROPERTY_NAME, encodingSelectBox.getSelectedEncoding()); // Set connection retry properties url.setProperty(FTPFile.NB_CONNECTION_RETRIES_PROPERTY_NAME, ""+nbRetriesSpinner.getValue()); url.setProperty(FTPFile.CONNECTION_RETRY_DELAY_PROPERTY_NAME, ""+retryDelaySpinner.getValue()); return url; }
fileURL.setCredentials(new Credentials(login, password));
childFileURL.setCredentials(credentials);
/** * Use the credentials and realm properties of the specified <code>CredentialsMapping</code> to authenticate the * given {@link FileURL}. * <p>Any credentials contained by the <code>FileURL</code> will be lost and replaced with the new ones. * If properties with the same key are defined both in the realm and the given FileURL, the ones from the FileURL * will be preserved.</p> * * @param location the FileURL to authenticate * @param credentialsMapping the credentials to use to authenticate the given FileURL */ public static void authenticate(FileURL location, CredentialsMapping credentialsMapping) { location.setCredentials(credentialsMapping.getCredentials()); FileURL realm = credentialsMapping.getRealm(); Enumeration<String> propertyKeys = realm.getPropertyNames(); String key; while(propertyKeys.hasMoreElements()) { key = propertyKeys.nextElement(); if(location.getProperty(key)==null) location.setProperty(key, realm.getProperty(key)); } }
/** * Returns an <code>AbstractFile</code> representing the canonical path of this file, or <code>this</code> if the * absolute and canonical path of this file are identical.<br/> * Note that the returned file may or may not exist, for example if this file is a symlink to a file that doesn't * exist. * * @return an <code>AbstractFile representing the canonical path of this file, or this if the absolute and canonical * path of this file are identical. */ public AbstractFile getCanonicalFile() { String canonicalPath = getCanonicalPath(false); if(canonicalPath.equals(getAbsolutePath(false))) return this; try { FileURL canonicalURL = FileURL.getFileURL(canonicalPath); canonicalURL.setCredentials(fileURL.getCredentials()); return FileFactory.getFile(canonicalURL); } catch(IOException e) { return this; } }
@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); }
/** * Returns a URL with the same scheme, host and port (if any) as the specified URL, and a path set to * <code>"/"</code> or <code>"\"</code> depending on the URL format. * The login, password, query and fragment parts of the returned URL are always <code>null</code>. * For example, when called with <code>http://www.mucommander.com:8080/path/to/file?query¶m=value</code>, * this method returns <code>http://www.mucommander.com:8080/</code>. * * @param location the location for which to return the authentication realm * @return the authentication realm of the specified location */ public FileURL getRealm(FileURL location) { // Start by cloning the given URL and then modify the parts that need it FileURL realm = (FileURL)location.clone(); realm.setPath(location.getPathSeparator()); realm.setCredentials(null); realm.setQuery(null); // Todo // realm.setFragment(null) return realm; } }
public Object getElementAt(int i) { ConnectionHandler connHandler = connections.get(i); // Show login (but not password) in the URL // Note: realm returned by ConnectionHandler does not contain credentials FileURL clonedRealm = (FileURL)connHandler.getRealm().clone(); Credentials loginCredentials = new Credentials(connHandler.getCredentials().getLogin(), ""); clonedRealm.setCredentials(loginCredentials); return clonedRealm.toString(true) +" ("+Translator.get(connHandler.isLocked()?"server_connections_dialog.connection_busy":"server_connections_dialog.connection_idle")+")"; } });
/** * Ensure that non URL-safe characters in login and password parts are properly handled, both when parsing * and representing URLs as string. * * @throws MalformedURLException should not happen */ @Test public void testCredentialsURLEncoding() throws MalformedURLException { FileURL url = getRootURL(); String urlDecodedString = ":@&=+$,/?t%#[]"; String urlEncodedString = "%3A%40%26%3D%2B%24%2C%2F%3Ft%25%23%5B%5D"; url.setCredentials(new Credentials(urlDecodedString, urlDecodedString)); String urlRep = url.getScheme()+"://"+urlEncodedString+":"+urlEncodedString+"@"; assert urlRep.equals(url.toString(true, false)); url = FileURL.getFileURL(urlRep); Credentials credentials = url.getCredentials(); assert credentials.getLogin().equals(urlDecodedString); assert credentials.getPassword().equals(urlDecodedString); }
destURL.setCredentials(baseFolderURL.getCredentials()); destURL.importProperties(baseFolderURL);
url.setCredentials(credentials); url.setHost(host); url.setPort(port); url.setCredentials(null); url.setHost(null); url.setPort(-1);
/** * 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) }
url1.setCredentials(new Credentials("LOGIN", "password")); assertEquals(url1, url2, false, false); assertNotEquals(url1, url2, true, true); url1.setCredentials(new Credentials("login", "PASSWORD")); assertEquals(url1, url2, false, false); assertNotEquals(url1, url2, true, true); url1.setCredentials(new Credentials("login", "password")); assertEquals(url1, url2, true, true);