ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r613798 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java
Date Mon, 21 Jan 2008 08:43:29 GMT
Author: xavier
Date: Mon Jan 21 00:43:28 2008
New Revision: 613798

URL: http://svn.apache.org/viewvc?rev=613798&view=rev
Log:
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)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=613798&r1=613797&r2=613798&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Mon Jan 21 00:43:28 2008
@@ -75,6 +75,7 @@
 - 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)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java?rev=613798&r1=613797&r2=613798&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java
Mon Jan 21 00:43:28 2008
@@ -21,9 +21,12 @@
 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 @@
 
     private String keyFilePassword = null;
 
-    private String user = "guest";
+    private String user = null;
 
     private String host = null;
 
@@ -48,6 +51,15 @@
         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 @@
                 }
             }
         }
+        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 @@
             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());
@@ -114,6 +135,32 @@
             Message.error("Please use scheme://user:pass@hostname/path/to/repository");
             return null;
         }
+    }
+
+    /**
+     *  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;
+      }
     }
 
     /**



Mime
View raw message