@Override protected Credentials getGuestCredentials() { return new Credentials("GUEST", ""); }
/** * This method is equivalent to calling {@link #equals(Object, boolean)} with <code>false</code>: * two Credentials instances with the same login but a different password are considered equal. * * @param o the Object to test for equality * @return true if this and the specified instance are equal * @see #equals(Object, boolean) */ public boolean equals(Object o) { return equals(o, false); }
@Override public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo) { String[] result = new String[prompt.length]; for (int i=0; i<echo.length; i++) result[i] = echo[i] ? credentials.getLogin() : credentials.getPassword(); return result; } }
@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); }
/** * 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; } } } }
if(urlCredentials!=null && guestCredentials!=null && urlCredentials.equals(guestCredentials)) urlCredentials = null; guestRadioButton = new JRadioButton(StringUtils.capitalize(guestCredentials.getLogin())); guestRadioButton.addActionListener(this); compPanel.addRow(Translator.get("auth_dialog.connect_as"), guestRadioButton, 0); loginComboBox.addItem(credentialsMappings[i].getCredentials().getLogin()); loginField.setText(selectedCredentials.getLogin()); passwordField.setText(selectedCredentials.getPassword());
sb.append(URLEncoder.encode(credentials.getLogin(), "UTF-8")); String password = credentials.getPassword(); if(!"".equals(password)) { sb.append(':'); if(maskPassword) sb.append(credentials.getMaskedPassword()); else { try {
@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; }
/** * Returns the login part of this URL, <code>null</code> if there isn't any. * * @return the login part of this URL, <code>null</code> if there isn't any * @see #getCredentials() */ public String getLogin() { return credentials==null?null:credentials.getLogin(); }
/** * Returns the password part of this URL, <code>null</code> if there isn't any. * * @return the password part of this URL, <code>null</code> if there isn't any * @see #getCredentials() */ public String getPassword() { return credentials==null?null:credentials.getPassword(); }
/** * Returns <code>true</code> if these Credentials and the specified instance are equal. For credentials to be equal, * their login (as returned by {@link #getLogin()} must be equal. If the password-sensitive parameter is enabled, * their passwords (as returned by {@link #getPassword()} must also match. * * <p> * Empty Credentials and <code>null</code> are considered equal: if a <code>null</code> instance is specified, * <code>true</code> is returned if these Credentials are {@link #isEmpty() empty}). * </p> * * @param o the Object to test for equality * @param passwordSensitive true if passwords need to be equal for credentials instanes to match * @return true if this and the specified instance are equal */ public boolean equals(Object o, boolean passwordSensitive) { // Empty Credentials and null are equivalent if(o==null) return isEmpty(); if(!(o instanceof Credentials)) // Note: this class is declared final so we don't need to worry about subclasses return false; Credentials credentials = (Credentials)o; return credentials.login.equals(this.login) && (!passwordSensitive || credentials.password.equals(this.password)); }
public String toString() { return credentials.toString()+" "+realm.toString(false); } }
h = 31* h + credentials.hashCode();
/** * 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);
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")+")"; } });
private static String getUsername(FileURL url) { Credentials credentials = url.getCredentials(); String username; if(credentials==null||(username=credentials.getLogin()).equals("")) username = getDefaultUsername(); return username; }
@Override public String getPassphrase() { return credentials.getPassword(); }
/** * Sets the login and password parts of this URL. Any credentials contained by this FileURL will be replaced. * <code>null</code> can be passed to discard existing credentials. * * <p>Credentials may or may not be of any use for the scheme's file protocol depending on the value * returned by {@link #getAuthenticationType()}.</p> * * @param credentials the new login and password parts, replacing any existing credentials. If null is passed, * existing credentials will be discarded. * @see #getCredentials() */ public void setCredentials(Credentials credentials) { if(credentials==null || credentials.isEmpty()) // Empty credentials are equivalent to null credentials this.credentials = null; else this.credentials = credentials; urlModified(); }
public void comboBoxSelectionChanged(SaneComboBox source) { CredentialsMapping selectedCredentialsMapping = credentialsMappings[loginComboBox.getSelectedIndex()]; Credentials selectedCredentials = selectedCredentialsMapping.getCredentials(); loginField.setText(selectedCredentials.getLogin()); passwordField.setText(selectedCredentials.getPassword()); // Enable/disable 'save credentials' checkbox depending on whether the selected credentials are persistent or not if(saveCredentialsCheckBox!=null) saveCredentialsCheckBox.setSelected(selectedCredentialsMapping.isPersistent()); }