@Override protected Credentials getGuestCredentials() { return new Credentials("anonymous", "someuser@mucommander.com"); }
@Override protected Credentials getGuestCredentials() { return new Credentials("GUEST", ""); }
@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; }
/** * Updates the value of the item that was being editing. Should be called whenever the list selection has changed. */ private void modifyCredentials() { // Make sure that the item still exists (could have been removed) before trying to modify its value int itemIndex = credentials.indexOf(lastSelectedItem); if(lastSelectedItem!=null && itemIndex!=-1) { credentials.setElementAt(new CredentialsMapping(new Credentials(loginField.getText(), new String(passwordField.getPassword())), lastSelectedItem.getRealm(), true), itemIndex); } this.lastSelectedItem = (CredentialsMapping) credentialsList.getSelectedValue(); }
@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; }
@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; }
CredentialsManager.getPersistentCredentialMappings().add(new CredentialsMapping(new Credentials(login, password), url, true));
@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));
/** * Called when the dialog has been validated by the user, when the OK button has been pressed or when enter has * been pressed in a text field. */ private void setCredentialMapping() { if(guestRadioButton!=null && guestRadioButton.isSelected()) { guestCredentialsSelected = true; selectedCredentialsMapping = new CredentialsMapping(fileURL.getGuestCredentials(), fileURL, false); } else { Credentials enteredCredentials = new Credentials(loginField.getText(), new String(passwordField.getPassword())); guestCredentialsSelected = false; boolean isPersistent = saveCredentialsCheckBox.isSelected(); selectedCredentialsMapping = new CredentialsMapping(enteredCredentials, fileURL, isPersistent); // Look for an existing matching CredentialsMapping instance to re-use the realm which may contain // connection properties. int nbCredentials = credentialsMappings.length; CredentialsMapping cm; for(int i=0; i<nbCredentials; i++) { cm = credentialsMappings[i]; if(cm.getCredentials().equals(enteredCredentials, true)) { // Comparison must be password-sensitive // Create a new CredentialsMapping instance in case the 'isPersistent' flag has changed. // (original credentials may have originally been added as 'volatile' and then made persistent by // ticking the checkbox, or vice-versa) selectedCredentialsMapping = new CredentialsMapping(cm.getCredentials(), cm.getRealm(), isPersistent); break; } } } }
@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 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); }
assert password.equals(url.getPassword()); assert new Credentials(login, password).equals(url.getCredentials(), true);
Credentials credentials = new Credentials("login", "password"); String host = "host"; int port = 10000;
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);