in taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/CredentialManagerAuthenticator.java [60:130]
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType().equals(PROXY)) {
String password = System.getProperty("http.proxyPassword");
String username = System.getProperty("http.proxyUser");
if (username == null || password == null)
// No proxy authentication set
return null;
return new PasswordAuthentication(username, password.toCharArray());
}
URI uri;
if (getRequestingURL() != null) {
try {
uri = getRequestingURL().toURI();
} catch (URISyntaxException e) {
logger.warn("Unsupported request (invalid URL) for "
+ getRequestingURL());
return null;
}
} else {
// Construct an URI of socket://hostname:port
String host = getRequestingHost();
if (host == null)
// Use IP address
host = getRequestingSite().getHostAddress();
int port = getRequestingPort();
if (host == null || port < 0) {
logger.warn("Unsupported request for " + getRequestingScheme()
+ " " + getRequestingSite());
return null;
}
uri = URI.create("socket://" + host + ":" + port);
}
if (credManager == null) {
logger.warn("No Credential Manager");
return null;
}
boolean usePathRecursion = false;
String realm = getRequestingPrompt();
if (getRequestingScheme().equals("basic")
|| getRequestingScheme().equals("digest")) {
usePathRecursion = true;
if (realm != null && realm.length() > 0)
try {
uri = DistinguishedNameParserImpl.resolveUriFragment(uri, realm);
} catch (URISyntaxException e) {
logger.warn("Could not URI-encode fragment for realm: "
+ realm);
}
}
UsernamePassword usernameAndPassword;
try {
usernameAndPassword = credManager.getUsernameAndPasswordForService(uri,
usePathRecursion, realm);
} catch (CMException e) {
logger.warn("Could not get username and password for " + uri, e);
return null;
}
if (usernameAndPassword == null) {
logger.warn("No username/password found for " + uri);
return null;
}
PasswordAuthentication pwAuth = new PasswordAuthentication(
usernameAndPassword.getUsername(), usernameAndPassword
.getPassword());
usernameAndPassword.resetPassword();
return pwAuth;
}