maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r164187 - /maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon /maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository /maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository /maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon /maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp /maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http /maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext /maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh
Date Fri, 22 Apr 2005 07:52:04 GMT
Author: brett
Date: Fri Apr 22 00:52:02 2005
New Revision: 164187

URL: http://svn.apache.org/viewcvs?rev=164187&view=rev
Log:
decouple authentication from repository

Modified:
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/Wagon.java
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
    maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
    maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
    maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
Fri Apr 22 00:52:02 2005
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.apache.maven.wagon.events.SessionEvent;
 import org.apache.maven.wagon.events.SessionEventSupport;
 import org.apache.maven.wagon.events.SessionListener;
@@ -56,6 +57,8 @@
 
     protected ProxyInfo proxyInfo = null;
 
+    protected AuthenticationInfo authenticationInfo = null;
+
     // ----------------------------------------------------------------------
     // Repository
     // ----------------------------------------------------------------------
@@ -72,18 +75,47 @@
     public void connect( Repository repository )
         throws ConnectionException, AuthenticationException
     {
-        connect( repository, null );
+        connect( repository, null, null );
     }
 
     public void connect( Repository repository, ProxyInfo proxyInfo )
         throws ConnectionException, AuthenticationException
     {
+        connect( repository, null, proxyInfo );
+    }
+
+    public void connect( Repository repository, AuthenticationInfo authenticationInfo )
+        throws ConnectionException, AuthenticationException
+    {
+        connect( repository, authenticationInfo, null );
+    }
+
+    public void connect( Repository repository, AuthenticationInfo authenticationInfo, ProxyInfo
proxyInfo )
+        throws ConnectionException, AuthenticationException
+    {
         if ( repository == null )
         {
             throw new IllegalStateException( "The repository specified cannot be null." );
         }
 
         this.repository = repository;
+
+        if ( authenticationInfo == null )
+        {
+            // Get user/pass that were encoded in the URL.
+            if ( repository.getUsername() != null )
+            {
+                authenticationInfo = new AuthenticationInfo();
+                authenticationInfo.setUserName( repository.getUsername() );
+                if ( repository.getPassword() != null )
+                {
+                    authenticationInfo.setPassword( repository.getPassword() );
+                }
+            }
+        }
+
+        // TODO: Do these needs to be fields, or are they only used in openConnection()?
+        this.authenticationInfo = authenticationInfo;
         this.proxyInfo = proxyInfo;
 
         fireSessionOpening();

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/Wagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/Wagon.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/Wagon.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/Wagon.java Fri
Apr 22 00:52:02 2005
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.events.SessionListener;
 import org.apache.maven.wagon.events.TransferListener;
@@ -79,6 +80,12 @@
         throws ConnectionException, AuthenticationException;
 
     void connect( Repository source, ProxyInfo proxyInfo )
+        throws ConnectionException, AuthenticationException;
+
+    void connect( Repository source, AuthenticationInfo authenticationInfo )
+        throws ConnectionException, AuthenticationException;
+
+    void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo
)
         throws ConnectionException, AuthenticationException;
 
     void openConnection()

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/repository/Repository.java
Fri Apr 22 00:52:02 2005
@@ -51,14 +51,16 @@
 
     private RepositoryPermissions permissions;
 
-    private AuthenticationInfo authenticationInfo;
-
     /**
      * Properties influencing wagon behaviour
      * which are very specific to particular wagon.
      */
     private Properties parameters = new Properties();
 
+    // Username/password are sometimes encoded in the URL
+    private String username = null;
+
+    private String password = null;
 
     public Repository()
     {
@@ -72,15 +74,6 @@
         setUrl( url );
     }
 
-    public Repository( String id, String url, AuthenticationInfo authenticationInfo )
-    {
-        setId( id );
-
-        setUrl( url );
-
-        this.authenticationInfo = authenticationInfo;
-    }
-
     public String getId()
     {
         return id;
@@ -92,16 +85,6 @@
     }
 
 
-    public AuthenticationInfo getAuthenticationInfo()
-    {
-        return authenticationInfo;
-    }
-
-    public void setAuthenticationInfo( AuthenticationInfo authenticationInfo )
-    {
-        this.authenticationInfo = authenticationInfo;
-    }
-
     public String getBasedir()
     {
         return basedir;
@@ -144,30 +127,23 @@
         this.basedir = PathUtils.basedir( url );
 
         String username = PathUtils.user( url );
+        this.username = username;
 
         if ( username != null )
         {
-            if ( authenticationInfo == null )
-            {
-                authenticationInfo = new AuthenticationInfo();
-            }
-            authenticationInfo.setUserName( username );
-
             String password = PathUtils.password( url );
 
-            String userInfo = username;
-
             if ( password != null )
             {
-                authenticationInfo.setPassword( password );
+                this.password = password;
 
-                userInfo += ":" + password;
+                username += ":" + password;
             }
 
-            userInfo += "@";
+            username += "@";
 
-            int index = url.indexOf( userInfo );
-            this.url = url.substring( 0, index ) + url.substring( index + userInfo.length()
);
+            int index = url.indexOf( username );
+            this.url = url.substring( 0, index ) + url.substring( index + username.length()
);
         }
     }
 
@@ -263,6 +239,16 @@
     public int hashCode()
     {
         return getId().hashCode();
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public String getPassword()
+    {
+        return password;
     }
 }
 

Modified: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/repository/RepositoryTest.java
Fri Apr 22 00:52:02 2005
@@ -49,10 +49,6 @@
     {
         Repository repository = new Repository();
 
-        repository.setAuthenticationInfo( new AuthenticationInfo() );
-
-        assertNotNull( repository.getAuthenticationInfo() );
-
         repository.setBasedir( "directory" );
 
         assertEquals( "directory", repository.getBasedir() );

Modified: maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
(original)
+++ maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
Fri Apr 22 00:52:02 2005
@@ -96,8 +96,6 @@
 
         testRepository.setUrl( getTestRepositoryUrl() );
 
-        testRepository.setAuthenticationInfo( getAuthInfo() );
-
         testRepository.setPermissions( getPermissions() );
 
         // ----------------------------------------------------------------------
@@ -205,7 +203,7 @@
 
         wagon.addTransferListener( checksumObserver );
 
-        wagon.connect( testRepository );
+        wagon.connect( testRepository, getAuthInfo() );
 
         sourceFile = new File( FileTestUtils.getTestOutputDir(), "test-resource.txt" );
         FileUtils.fileWrite( sourceFile.getAbsolutePath(), "test-resource.txt\n" );
@@ -226,7 +224,7 @@
 
         wagon.addTransferListener( checksumObserver );
 
-        wagon.connect( testRepository );
+        wagon.connect( testRepository, getAuthInfo() );
 
         destFile = FileTestUtils.createUniqueFile( getName(), getName() );
 

Modified: maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
Fri Apr 22 00:52:02 2005
@@ -31,7 +31,6 @@
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.WagonConstants;
 import org.apache.maven.wagon.authentication.AuthenticationException;
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.apache.maven.wagon.repository.RepositoryPermissions;
 import org.apache.maven.wagon.resource.Resource;
 
@@ -48,16 +47,14 @@
     public void openConnection()
         throws ConnectionException, AuthenticationException
     {
-        AuthenticationInfo authInfo = getRepository().getAuthenticationInfo();
-
-        if ( authInfo == null )
+        if ( authenticationInfo == null )
         {
             throw new IllegalArgumentException( "Authentication Credentials cannot be null
for FTP protocol" );
         }
 
-        String username = authInfo.getUserName();
+        String username = authenticationInfo.getUserName();
 
-        String password = authInfo.getPassword();
+        String password = authenticationInfo.getPassword();
 
         String host = getRepository().getHost();
 

Modified: maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/HttpWagon.java
Fri Apr 22 00:52:02 2005
@@ -69,17 +69,15 @@
     {
         client = new HttpClient( new MultiThreadedHttpConnectionManager() );
 
-        final AuthenticationInfo authInfo = getRepository().getAuthenticationInfo();
-
         String username = null;
 
         String password = null;
 
-        if ( authInfo != null )
+        if ( authenticationInfo != null )
         {
-            username = authInfo.getUserName();
+            username = authenticationInfo.getUserName();
 
-            password = authInfo.getPassword();
+            password = authenticationInfo.getPassword();
         }
 
         String host = getRepository().getHost();

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
Fri Apr 22 00:52:02 2005
@@ -87,9 +87,7 @@
     public void openConnection()
         throws AuthenticationException
     {
-        final AuthenticationInfo authInfo = getRepository().getAuthenticationInfo();
-
-        if ( authInfo == null )
+        if ( authenticationInfo == null )
         {
             throw new IllegalArgumentException( "Authentication Credentials cannot be null
for SSH protocol" );
         }
@@ -102,13 +100,13 @@
         }
 
         // If user don't define a password, he want to use a private key
-        if ( authInfo.getPassword() == null )
+        if ( authenticationInfo.getPassword() == null )
         {
             File privateKey;
 
-            if ( authInfo.getPrivateKey() != null )
+            if ( authenticationInfo.getPrivateKey() != null )
             {
-                privateKey = new File( authInfo.getPrivateKey() );
+                privateKey = new File( authenticationInfo.getPrivateKey() );
             }
             else
             {
@@ -117,9 +115,9 @@
 
             if ( privateKey.exists() )
             {
-                if ( authInfo.getPassphrase() == null )
+                if ( authenticationInfo.getPassphrase() == null )
                 {
-                    authInfo.setPassphrase( "" );
+                    authenticationInfo.setPassphrase( "" );
                 }
 
                 fireSessionDebug( "Using private key: " + privateKey );
@@ -172,8 +170,6 @@
     public void executeCommand( String command )
         throws TransferFailedException
     {
-        AuthenticationInfo authenticationInfo = getRepository().getAuthenticationInfo();
-
         Commandline cl = new Commandline();
 
         cl.setExecutable( sshExecutable );
@@ -202,8 +198,6 @@
     private void executeScpCommand( File localFile, String remoteFile, boolean put )
         throws TransferFailedException
     {
-        AuthenticationInfo authenticationInfo = getRepository().getAuthenticationInfo();
-
         Commandline cl = new Commandline();
 
         cl.setWorkingDirectory( localFile.getParentFile().getAbsolutePath() );

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java?rev=164187&r1=164186&r2=164187&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
Fri Apr 22 00:52:02 2005
@@ -77,9 +77,7 @@
     {
         try
         {
-            final AuthenticationInfo authInfo = getRepository().getAuthenticationInfo();
-
-            if ( authInfo == null )
+            if ( authenticationInfo == null )
             {
                 throw new IllegalArgumentException( "Authentication Credentials cannot be
null for SSH protocol" );
             }
@@ -95,16 +93,16 @@
 
             String host = getRepository().getHost();
 
-            session = jsch.getSession( authInfo.getUserName(), host, port );
+            session = jsch.getSession( authenticationInfo.getUserName(), host, port );
 
             // If user don't define a password, he want to use a private key
-            if ( authInfo.getPassword() == null )
+            if ( authenticationInfo.getPassword() == null )
             {
                 File privateKey;
 
-                if ( authInfo.getPrivateKey() != null )
+                if ( authenticationInfo.getPrivateKey() != null )
                 {
-                    privateKey = new File( authInfo.getPrivateKey() );
+                    privateKey = new File( authenticationInfo.getPrivateKey() );
                 }
                 else
                 {
@@ -113,14 +111,14 @@
 
                 if ( privateKey.exists() )
                 {
-                    if ( authInfo.getPassphrase() == null )
+                    if ( authenticationInfo.getPassphrase() == null )
                     {
-                        authInfo.setPassphrase( "" );
+                        authenticationInfo.setPassphrase( "" );
                     }
 
                     fireSessionDebug( "Using private key: " + privateKey );
 
-                    jsch.addIdentity( privateKey.getAbsolutePath(), authInfo.getPassphrase()
);
+                    jsch.addIdentity( privateKey.getAbsolutePath(), authenticationInfo.getPassphrase()
);
                 }
                 else
                 {
@@ -153,7 +151,7 @@
             }
 
             // username and password will be given via UserInfo interface.
-            UserInfo ui = new WagonUserInfo( authInfo );
+            UserInfo ui = new WagonUserInfo( authenticationInfo );
 
             session.setUserInfo( ui );
 



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-cvs-help@maven.apache.org


Mime
View raw message