mirror of https://github.com/apache/ant-ivy
FIX: When in ssh plugin we does not set username in scheme, Ivy always try to connect with guest username, even if we change one in panel. (IVY-710) (thanks to Ruslan Shevchenko)
git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@613798 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea33beff53
commit
c88d4466b1
|
|
@ -75,6 +75,7 @@ for detailed view of each issue, please consult http://issues.apache.org/jira/br
|
|||
- IMPROVEMENT: Downgrade Ant version requirement to 1.6 to build Ivy (IVY-687)
|
||||
- IMPROVEMENT: In the ResolveReport class, add the possibility to filter the evicted module while getting the list of DownloadArtifact (IVY-704) (thanks to Nicolas Lalevée)
|
||||
|
||||
- FIX: When in ssh plugin we does not set username in scheme, Ivy always try to connect with guest username, even if we change one in panel. (IVY-710) (thanks to Ruslan Shevchenko)
|
||||
- FIX: NPE in SshCache during publish with ssh resolver without passFile (IVY-709) (thanks to Ruslan Shevchenko)
|
||||
- FIX: Update install ivy build file example (IVY-705) (thanks to Benjamin Francisoud)
|
||||
- FIX: Ivy swallows ParseException when using a latest strategy requiring module descriptors (IVY-702) (thanks to Nicolas Lalevée)
|
||||
|
|
|
|||
|
|
@ -21,9 +21,12 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.ivy.plugins.repository.AbstractRepository;
|
||||
import org.apache.ivy.util.Credentials;
|
||||
import org.apache.ivy.util.CredentialsUtil;
|
||||
import org.apache.ivy.util.Message;
|
||||
|
||||
import com.jcraft.jsch.Session;
|
||||
|
|
@ -38,7 +41,7 @@ public abstract class AbstractSshBasedRepository extends AbstractRepository {
|
|||
|
||||
private String keyFilePassword = null;
|
||||
|
||||
private String user = "guest";
|
||||
private String user = null;
|
||||
|
||||
private String host = null;
|
||||
|
||||
|
|
@ -48,6 +51,15 @@ public abstract class AbstractSshBasedRepository extends AbstractRepository {
|
|||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hashmap of user/hosts with credentials.
|
||||
* key is hostname, value is Credentials
|
||||
**/
|
||||
private static HashMap credentialsCache = new HashMap();
|
||||
|
||||
private static final int MAX_CREDENTILAS_CACHE_SIZE = 100;
|
||||
|
||||
/**
|
||||
* get a new session using the default attributes if the given String is a full uri, use the
|
||||
* data from the uri instead
|
||||
|
|
@ -79,6 +91,15 @@ public abstract class AbstractSshBasedRepository extends AbstractRepository {
|
|||
}
|
||||
}
|
||||
}
|
||||
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, getKeyFile(),
|
||||
getKeyFilePassword(), getPassFile());
|
||||
}
|
||||
|
|
@ -104,9 +125,9 @@ public abstract class AbstractSshBasedRepository extends AbstractRepository {
|
|||
if (uri.getPath() == null) {
|
||||
throw new URISyntaxException(source, "Missing path in URI");
|
||||
}
|
||||
if (uri.getUserInfo() == null && getUser() == null) {
|
||||
throw new URISyntaxException(source, "Missing username in URI or in resolver");
|
||||
}
|
||||
//if (uri.getUserInfo() == null && getUser() == null) {
|
||||
// throw new URISyntaxException(source, "Missing username in URI or in resolver");
|
||||
//}
|
||||
return uri;
|
||||
} catch (URISyntaxException e) {
|
||||
Message.error(e.getMessage());
|
||||
|
|
@ -116,6 +137,32 @@ public abstract class AbstractSshBasedRepository extends AbstractRepository {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called, when user was not found in URL.
|
||||
* Maintain static hashe of credentials and retrieve or ask credentials
|
||||
* for host.
|
||||
*
|
||||
* @param host
|
||||
* host for which we want to get credentials.
|
||||
* @return credentials for given host
|
||||
**/
|
||||
private Credentials requestCredentials(String host) {
|
||||
Object o = credentialsCache.get(host);
|
||||
if (o == null) {
|
||||
Credentials c = CredentialsUtil.promptCredentials(
|
||||
new Credentials(null, host, user, userPassword), getPassFile());
|
||||
if (c != null) {
|
||||
if (credentialsCache.size() > MAX_CREDENTILAS_CACHE_SIZE) {
|
||||
credentialsCache.clear();
|
||||
}
|
||||
credentialsCache.put(host, c);
|
||||
}
|
||||
return c;
|
||||
} else {
|
||||
return (Credentials) o;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* closes the session and remove it from the cache (eg. on case of errors)
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue