maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r409075 - in /maven/wagon/trunk/wagon-providers/wagon-webdav/src: main/java/org/apache/maven/wagon/providers/webdav/ test/java/org/apache/maven/wagon/providers/webdav/ test/resources/org/apache/maven/wagon/providers/webdav/
Date Wed, 24 May 2006 05:50:27 GMT
Author: carlos
Date: Tue May 23 22:50:26 2006
New Revision: 409075

URL: http://svn.apache.org/viewvc?rev=409075&view=rev
Log:
[WAGON-48] Authentication code was never called

Added:
    maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.java
  (with props)
    maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/resources/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.xml
  (with props)
Modified:
    maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
    maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/Context.java
    maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java

Modified: maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java?rev=409075&r1=409074&r2=409075&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
Tue May 23 22:50:26 2006
@@ -112,34 +112,23 @@
         try
         {
             httpURL = urlToHttpURL( url );
+            
+            if ( authenticationInfo != null )
+            {
+                String userName = authenticationInfo.getUserName();
+                String password = authenticationInfo.getPassword();
+
+                if ( userName != null && password != null )
+                    httpURL.setUserinfo( userName, password );
+            }
 
             CorrectedWebdavResource.setDefaultAction( CorrectedWebdavResource.NOACTION );
             wdresource = new CorrectedWebdavResource( httpURL );
         }
         catch ( HttpException he )
         {
-            if ( he.getReasonCode() == HttpStatus.SC_UNAUTHORIZED )
-            {
-                try
-                {
-                    httpURL.setUserinfo( authenticationInfo.getUserName(), authenticationInfo.getPassword()
);
-
-                    wdresource = new CorrectedWebdavResource( httpURL );
-                }
-                catch ( URIException urie )
-                {
-                    throw new AuthenticationException( "Authentication Exception: " + urie.getReason()
);
-                }
-                catch ( IOException ioe )
-                {
-                    throw new ConnectionException( "Connection Exception: " + ioe.getMessage()
);
-                }
-            }
-            else
-            {
-                throw new ConnectionException( "Connection Exception: " + url + " " + he.getReasonCode()
+ " "
-                    + HttpStatus.getStatusText( he.getReasonCode() ) );
-            }
+            throw new ConnectionException( "Connection Exception: " + url + " " + he.getReasonCode()
+ " "
+                + HttpStatus.getStatusText( he.getReasonCode() ) );
         }
         catch ( URIException urie )
         {
@@ -438,7 +427,7 @@
                     throw new ResourceDoesNotExistException( "File: " + url + " does not
exist" );
 
                 default:
-                    throw new TransferFailedException( "Failed to trasfer file: " + url +
". Return code is: "
+                    throw new TransferFailedException( "Failed to transfer file: " + url
+ ". Return code is: "
                                                        + statusCode );
             }                
         }
@@ -471,7 +460,7 @@
                 throw new ResourceDoesNotExistException( "File: " + url + " does not exist"
);
 
             default:
-                throw new TransferFailedException( "Failed to trasfer file: " + url + ".
Return code is: "
+                throw new TransferFailedException( "Failed to transfer file: " + url + ".
Return code is: "
                     + statusCode );
         }
         

Added: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.java?rev=409075&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.java
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.java
Tue May 23 22:50:26 2006
@@ -0,0 +1,76 @@
+package org.apache.maven.wagon.providers.webdav;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.wagon.FileTestUtils;
+import org.apache.maven.wagon.WagonTestCase;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+
+/**
+ * Authenticated WebDAV Wagon Test 
+ * 
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ */
+public class AuthenticatedWebDavWagonTest
+    extends WagonTestCase
+{
+    private ServletServer server;
+
+    protected String getTestRepositoryUrl()
+        throws IOException
+    {
+        return "dav:http://localhost:10007/authdav/newfolder/folder2";
+    }
+
+    protected String getProtocol()
+    {
+        return "dav";
+    }
+
+    protected AuthenticationInfo getAuthInfo()
+    {
+        AuthenticationInfo authenticationInfo = new AuthenticationInfo();
+
+        authenticationInfo.setUserName( "userName" );
+
+        authenticationInfo.setPassword( "password" );
+
+        return authenticationInfo;
+    }
+
+    protected void setupWagonTestingFixtures()
+        throws Exception
+    {
+        File file = FileTestUtils.createUniqueFile( "authdav-repository", "test-resource"
);
+
+        file.delete();
+
+        File davDir = file.getParentFile();
+        davDir.mkdirs();
+
+        server = (ServletServer) lookup( ServletServer.ROLE );
+    }
+
+    protected void tearDownWagonTestingFixtures()
+        throws Exception
+    {
+        release( server );
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/Context.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/Context.java?rev=409075&r1=409074&r2=409075&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/Context.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/Context.java
Tue May 23 22:50:26 2006
@@ -18,6 +18,8 @@
 
 import java.util.List;
 
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+
 /**
  * Context
  * 
@@ -26,7 +28,9 @@
 public class Context
 {
     private String id;
-    
+
+    private AuthenticationInfo authenticationInfo;
+
     private List servlets;
 
     public String getId()
@@ -34,10 +38,13 @@
         return id;
     }
 
+    public AuthenticationInfo getAuthenticationInfo()
+    {
+        return authenticationInfo;
+    }
+
     public List getServlets()
     {
         return servlets;
     }
-    
-    
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java?rev=409075&r1=409074&r2=409075&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/java/org/apache/maven/wagon/providers/webdav/ServletServer.java
Tue May 23 22:50:26 2006
@@ -21,12 +21,17 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException;
+import org.mortbay.http.BasicAuthenticator;
+import org.mortbay.http.HashUserRealm;
+import org.mortbay.http.SecurityConstraint;
 import org.mortbay.http.SocketListener;
+import org.mortbay.http.handler.SecurityHandler;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.servlet.ServletHttpContext;
@@ -83,6 +88,18 @@
     private void initContext( Context wdc, ServletHttpContext context )
         throws ClassNotFoundException, InstantiationException, IllegalAccessException
     {
+        AuthenticationInfo authenticationInfo = wdc.getAuthenticationInfo();
+        if ( authenticationInfo != null )
+        {
+            HashUserRealm userRealm = new HashUserRealm( "basic" );
+            userRealm.put( authenticationInfo.getUserName(), authenticationInfo.getPassword()
);
+            context.getHttpServer().addRealm( userRealm );
+
+            context.setAuthenticator( new BasicAuthenticator() );
+            context.addSecurityConstraint( "/*", new SecurityConstraint( "any", SecurityConstraint.ANY_ROLE
) );
+            context.addHandler( new SecurityHandler() );
+        }
+
         Iterator itpaths = wdc.getServlets().iterator();
         while ( itpaths.hasNext() )
         {

Added: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/resources/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/resources/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.xml?rev=409075&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/resources/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.xml
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/resources/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.xml
Tue May 23 22:50:26 2006
@@ -0,0 +1,37 @@
+<plexus>
+  <components>
+    <component>
+      <role>org.apache.maven.wagon.providers.webdav.ServletServer</role>
+      <implementation>org.apache.maven.wagon.providers.webdav.ServletServer</implementation>
+      <configuration>
+        <port>10007</port>
+        <contexts>
+          <context>
+            <id>/authdav</id>
+            <authenticationInfo>
+            	<userName>userName</userName>
+            	<password>password</password>
+            </authenticationInfo>
+            <servlets>
+              <servlet>
+                <id>LOCALREPO</id>
+                <path>/*</path>
+                <servlet>it.could.webdav.DAVServlet</servlet>
+                <parameters>
+                  <property>
+                    <name>rootPath</name>
+                    <value>${basedir}/target/test-output/authdav-repository</value>
+                  </property>
+                  <property>
+                    <name>xmlOnly</name>
+                    <value>false</value>
+                  </property>
+                </parameters>
+              </servlet>
+            </servlets>
+          </context>
+        </contexts>
+      </configuration>
+    </component>
+  </components>
+</plexus>

Propchange: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/resources/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-providers/wagon-webdav/src/test/resources/org/apache/maven/wagon/providers/webdav/AuthenticatedWebDavWagonTest.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



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


Mime
View raw message