use of org.apache.ivy.util.Credentials in project ant-ivy by apache.
the class AbstractSshBasedRepository method getSession.
/**
* get a new session using the default attributes if the given String is a full uri, use the
* data from the uri instead
*
* @param pathOrUri
* might be just a path or a full ssh or sftp uri
* @return matching Session
* @throws IOException if something goes wrong
*/
protected Session getSession(String pathOrUri) throws IOException {
URI uri = parseURI(pathOrUri);
String host = getHost();
int port = getPort();
String user = getUser();
String userPassword = getUserPassword();
String sshConfig = getSshConfig();
File keyFile = getKeyFile();
if (uri != null && uri.getScheme() != null) {
if (uri.getHost() != null) {
host = uri.getHost();
}
if (uri.getPort() != -1) {
port = uri.getPort();
}
if (uri.getUserInfo() != null) {
String userInfo = uri.getUserInfo();
if (!userInfo.contains(":")) {
user = userInfo;
} else {
user = userInfo.substring(0, userInfo.indexOf(":"));
userPassword = userInfo.substring(userInfo.indexOf(":") + 1);
}
}
}
if (sshConfig != null) {
ConfigRepository configRepository = OpenSSHConfig.parseFile(sshConfig);
Config config = configRepository.getConfig(host);
host = config.getHostname();
if (user == null) {
user = config.getUser();
}
String keyFilePath = config.getValue("IdentityFile");
if (keyFilePath != null && keyFile == null) {
keyFile = new File(keyFilePath);
}
}
if (host == null) {
throw new IllegalArgumentException("missing host information. host should be provided either " + "directly on the repository or in the connection URI " + ", or in the openssh config file specified by sshConfig");
}
if (user == null) {
Credentials c = requestCredentials(host);
if (c != null) {
user = c.getUserName();
userPassword = c.getPasswd();
} else {
Message.error("username is not set");
}
}
return SshCache.getInstance().getSession(host, port, user, userPassword, keyFile, getKeyFilePassword(), getPassFile(), isAllowedAgentUse());
}
use of org.apache.ivy.util.Credentials in project ant-ivy by apache.
the class CredentialsStore method addCredentials.
public void addCredentials(String realm, String host, String userName, String passwd) {
if (userName == null) {
return;
}
Credentials c = new Credentials(realm, host, userName, passwd);
Message.debug("credentials added: " + c);
KEYRING.put(c.getKey(), c);
SECURED_HOSTS.add(host);
}
use of org.apache.ivy.util.Credentials in project ant-ivy by apache.
the class IvyAuthenticator method getPasswordAuthentication.
// API ******************************************************************
// Overriding Authenticator *********************************************
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication result = null;
if (isProxyAuthentication()) {
String proxyUser = System.getProperty("http.proxyUser");
if (!isNullOrEmpty(proxyUser)) {
String proxyPass = System.getProperty("http.proxyPassword", "");
Message.debug("authenticating to proxy server with username [" + proxyUser + "]");
result = new PasswordAuthentication(proxyUser, proxyPass.toCharArray());
}
} else {
Credentials c = CredentialsStore.INSTANCE.getCredentials(getRequestingPrompt(), getRequestingHost());
Message.debug("authentication: k='" + Credentials.buildKey(getRequestingPrompt(), getRequestingHost()) + "' c='" + c + "'");
if (c != null) {
final String password = c.getPasswd() == null ? "" : c.getPasswd();
result = new PasswordAuthentication(c.getUserName(), password.toCharArray());
}
}
if (result == null && original != null) {
Authenticator.setDefault(original);
try {
result = Authenticator.requestPasswordAuthentication(getRequestingHost(), getRequestingSite(), getRequestingPort(), getRequestingProtocol(), getRequestingPrompt(), getRequestingScheme(), getRequestingURL(), getRequestorType());
} finally {
Authenticator.setDefault(this);
}
}
return result;
}
Aggregations