/** * 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(); }
private static String getUsername(FileURL url) { Credentials credentials = url.getCredentials(); String username; if(credentials==null||(username=credentials.getLogin()).equals("")) username = getDefaultUsername(); return username; }
private void initClientIfNeeded() throws RuntimeFaultFaultMsg, InvalidLocaleFaultMsg, InvalidLoginFaultMsg { if (client == null) { client = new VSphereClient(location.getHost(), location .getCredentials().getLogin(), location.getCredentials() .getPassword()); client.connect(); } }
/** * Opens and returns a <code>HttpURLConnection</code> to the resource denoted by the specified URL. * If the {@link FileURL} contained by this HTTPFile contains {@link Credentials}, these will be used as credentials * for <i>HTTP Basic Authentication<i>. * * @param url the URL to open * @return a HttpURLConnection to the resource denoted by the specified URL * @throws IOException if the HttpURLConnection could not be opened */ private HttpURLConnection getHttpURLConnection(URL url) throws IOException { // Get URLConnection instance HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // If credentials are contained in this HTTPFile's FileURL, use them for Basic HTTP Authentication Credentials credentials = fileURL.getCredentials(); if(credentials!=null) conn.setRequestProperty( "Authorization", "Basic "+ Base64Encoder.encode(credentials.getLogin()+":"+credentials.getPassword()) ); // Set user-agent header. conn.setRequestProperty("User-Agent", USER_AGENT); return conn; }
Credentials credentials = url.getCredentials();
URL childURL; FileURL childFileURL; Credentials credentials = fileURL.getCredentials();
@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); }
Credentials urlCredentials = url.getCredentials(); int matchingConnHandlers = 0;
/** * 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; } }
/** * Creates and returns a <code>jcifs.smb.SmbFile</code> for the given location. The credentials contained by * the {@link FileURL} (if any) are passed along to the <code>SmbFile</code>. * * @param url the location to the SmbFile file to create * @return an SmbFile corresponding to the given location * @throws MalformedURLException if an error occurred while creating the SmbFile instance */ private static SmbFile createSmbFile(FileURL url) throws MalformedURLException { Credentials credentials = url.getCredentials(); if(credentials==null) return new SmbFile(url.toString(false)); // Extract the domain (if any) from the username String login = credentials.getLogin(); String domain; int domainStart = login.indexOf(";"); if(domainStart!=-1) { domain = login.substring(0, domainStart); login = login.substring(domainStart+1, login.length()); } else { domain = null; } // A NtlmPasswordAuthentication is created from the FileURL credentials and passed to a specific SmbFile constructor. // The reason for doing this rather than using the SmbFile(String) constructor is that SmbFile uses java.net.URL // for the URL parsing which is unable to properly parse urls where the password contains a '@' character, // such as smb://user:p@ssword@host/path . return new SmbFile(url.toString(false), new NtlmPasswordAuthentication(domain, login, credentials.getPassword())); }
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source==cancelButton) { dispose(); return; } try { currentServerPanel.dialogValidated(); FileURL serverURL = currentServerPanel.getServerURL(); // Can throw a MalformedURLException // Create a CredentialsMapping instance and pass to Folder so that it uses it to connect to the folder and // adds to CredentialsManager once the folder has been successfully changed Credentials credentials = serverURL.getCredentials(); CredentialsMapping credentialsMapping; if(credentials!=null) { credentialsMapping = new CredentialsMapping(credentials, serverURL, saveCredentialsCheckBox.isSelected()); } else { credentialsMapping = null; } dispose(); // Change the current folder folderPanel.tryChangeCurrentFolder(serverURL, credentialsMapping); } catch(IOException ex) { InformationDialog.showErrorDialog(this, Translator.get("table.folder_access_error_title"), Translator.get("folder_does_not_exist")); } }
public AbstractFile getFile(FileURL url, Object... instantiationParams) throws IOException { Credentials credentials = url.getCredentials(); if(credentials==null || credentials.getLogin().equals("") || credentials.getPassword().equals("")) throw new AuthException(url);
/** * 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); }
Credentials urlCredentials = fileURL.getCredentials(); if(urlCredentials!=null && guestCredentials!=null && urlCredentials.equals(guestCredentials)) urlCredentials = null;
assert password.equals(url.getPassword()); assert new Credentials(login, password).equals(url.getCredentials(), true);
destURL.setCredentials(baseFolderURL.getCredentials()); destURL.importProperties(baseFolderURL);
assert url.getCredentials().equals(parentURL.getCredentials()); assert url.getLogin().equals(parentURL.getLogin()); assert url.getPassword().equals(parentURL.getPassword());
assert credentials.equals(url.getCredentials(), true); assert host.equals(url.getHost()); assert port == url.getPort(); assert url.getCredentials() == null; assert !url.containsCredentials(); assert url.getHost() == null;
newURL.setCredentials(folderURL.getCredentials()); newURL.importProperties(folderURL); this.folderURL = newURL;
/** * 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) }