/** * 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); }
/** * Returns <code>true</code> if the credentials (login and password) of this URL and the given URL are equal. * The comparison is case-sensitive. * * @param url the URL to test for credentials equality * @return <code>true</code> if the credentials of this URL and the given URL are equal */ public boolean credentialsEquals(FileURL url) { Credentials creds1 = this.credentials; Credentials creds2 = url.credentials; return (creds1==null && creds2==null) || (creds1!=null && creds1.equals(creds2, true)) || (creds2!=null && creds2.equals(creds1, true)); }
/** * Returns <code>true</code> if both the given realm and credentials are equal to those of this ConnectionHandler. * The credentials comparison is password-sensitive. * * @param realm the FileURL to compare against this ConnectionHandler's * @param credentials the Credentials to compare against this ConnectionHandler's * @return true if both the given realm and credentials are equal to those of this ConnectionHandler * @see Credentials#equals(Object, boolean) */ public boolean equals(FileURL realm, Credentials credentials) { if(!this.realm.equals(realm, false, true)) return false; // Compare credentials. One or both Credentials instances may be null. // Note: Credentials.equals() considers null as equal to empty Credentials (see Credentials#isEmpty()) return (this.credentials==null && credentials==null) || (this.credentials!=null && this.credentials.equals(credentials, true)) || (credentials!=null && credentials.equals(this.credentials, true)); }
/** * Returns <code>true</code> if the given Object is a {@link com.mucommander.auth.CredentialsMapping} instance * whose credentials and realm are equals to those of this instance. * * @param o the Object to test for equality * @return true if both CredentialsMapping instances are equal */ public boolean equals(Object o) { if(!(o instanceof CredentialsMapping)) // Note: CredentialsMapping is final, no need to test classes return false; CredentialsMapping cm = (CredentialsMapping)o; return cm.credentials.equals(this.credentials, false) && cm.realm.equals(this.realm, false, true); }
/** * 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; } } } }
/** * Ensures that the values returned by {@link FileURL#getGuestCredentials()} and {@link SchemeHandler#getGuestCredentials()} * match the expected one returned by {@link #getGuestCredentials()}. * * @throws MalformedURLException should not happen */ @Test public void testGuestCredentials() throws MalformedURLException { FileURL url = getRootURL(); Credentials expectedGuestCredentials = getGuestCredentials(); // Assert that the guest credentials values returned by the FileURL and its handler match the expected one // and are consistent if(expectedGuestCredentials == null) { assert url.getGuestCredentials() == null; assert url.getHandler().getGuestCredentials() == null; } else { assert expectedGuestCredentials.equals(url.getGuestCredentials()); assert expectedGuestCredentials.equals(url.getHandler().getGuestCredentials()); } }
if(urlCredentials!=null && guestCredentials!=null && urlCredentials.equals(guestCredentials)) urlCredentials = null;
assert password.equals(url.getPassword()); assert new Credentials(login, password).equals(url.getCredentials(), true);
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();