continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r1140480 - in /continuum/trunk/continuum-buildagent: ./ continuum-buildagent-webdav-client/ continuum-buildagent-webdav-client/src/ continuum-buildagent-webdav-client/src/main/ continuum-buildagent-webdav-client/src/main/java/ continuum-bui...
Date Tue, 28 Jun 2011 08:28:12 GMT
Author: oching
Date: Tue Jun 28 08:28:11 2011
New Revision: 1140480

URL: http://svn.apache.org/viewvc?rev=1140480&view=rev
Log:
[CONTINUUM-2632] Secure working copies of Continuum build agents
o only allow access to the working copy if the password attached to the request matches the
shared secret password between the master and build agent that is configured in the build
agent config file
o added a sample webdav client for testing access to the working copies in the build agent

Added:
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/pom.xml
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/webdav/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/webdav/client/
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/webdav/client/WorkingCopyWebdavClient.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockWorkingCopyServlet.java
Modified:
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProvider.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/WorkingCopyServlet.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProviderTest.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java
    continuum/trunk/continuum-buildagent/pom.xml

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/pom.xml?rev=1140480&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/pom.xml (added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/pom.xml Tue Jun
28 08:28:11 2011
@@ -0,0 +1,99 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.continuum</groupId>
+    <artifactId>continuum-buildagent</artifactId>
+    <version>1.4.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>continuum-buildagent-webdav-client</artifactId>
+  <version>1.4.1-SNAPSHOT</version>
+  <name>Continuum :: Distributed Build :: Build Agent :: Webdav Client</name>
+  <dependencies>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore</artifactId>
+      <version>4.1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.1.1</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-jdk14</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <!--
+    To execute the sample working copy webdav client, just execute "mvn exec:java".
+
+    By default, the sample webdav client gets the POM file of the Continuum project with
id "1"
+    from the working copy directory. Change the values of the continuumProjectId and pomFile
+    properties depending on the contents of the continuum-buildagent's working directory
you
+    are running this against.
+    -->
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <configuration>
+          <executable>java</executable>
+          <mainClass>org.apache.continuum.buildagent.webdav.client.WorkingCopyWebdavClient</mainClass>
+          <arguments>
+            <argument>${url}/workingcopy/${continuumProjectId}/${pomFile}</argument>
+            <argument>${sharedSecretPassword}</argument>
+          </arguments>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <bannedDependencies>
+                  <includes>
+                    <!--
+                     Needed during runtime by httpclient. This module isn't included in webapp
so it
+                     should be alright to include commons-logging
+                     -->
+                    <include>commons-logging:commons-logging:1.1.1:jar:runtime</include>
+                  </includes>
+                </bannedDependencies>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <properties>
+    <url>http://localhost:${port}/continuum-buildagent</url>
+    <port>8181</port>
+    <sharedSecretPassword>secret</sharedSecretPassword>
+    <continuumProjectId>1</continuumProjectId>
+    <pomFile>pom.xml</pomFile>
+  </properties>
+</project>

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/webdav/client/WorkingCopyWebdavClient.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/webdav/client/WorkingCopyWebdavClient.java?rev=1140480&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/webdav/client/WorkingCopyWebdavClient.java
(added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav-client/src/main/java/org/apache/continuum/buildagent/webdav/client/WorkingCopyWebdavClient.java
Tue Jun 28 08:28:11 2011
@@ -0,0 +1,80 @@
+package org.apache.continuum.buildagent.webdav.client;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.AuthCache;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.params.ConnManagerPNames;
+import org.apache.http.conn.params.ConnPerRouteBean;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.util.EntityUtils;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+public class WorkingCopyWebdavClient
+{
+    public static void main( String[] args )
+        throws Exception
+    {
+        System.out.println( "Running webdav client.." );
+
+        SchemeRegistry schemeRegistry = new SchemeRegistry();
+        // http scheme
+        schemeRegistry.register( new Scheme( "http", PlainSocketFactory.getSocketFactory(),
80 ) );
+
+        HttpParams params = new BasicHttpParams();
+        params.setParameter( ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30 );
+        params.setParameter( ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(
30 ) );
+
+        HttpProtocolParams.setVersion( params, HttpVersion.HTTP_1_1 );
+
+        ClientConnectionManager cm = new ThreadSafeClientConnManager( params, schemeRegistry
);
+
+        DefaultHttpClient httpClient = new DefaultHttpClient( cm, params );
+
+        URL url = new URL( args[0] );
+        URI uri = url.toURI();
+        HttpGet httpGet = new HttpGet( uri );
+
+        httpClient.getCredentialsProvider().setCredentials( new AuthScope( uri.getHost(),
uri.getPort() ),
+                                                                            new UsernamePasswordCredentials(
"", args[1] ) );
+
+        HttpHost targetHost = new HttpHost( url.getHost(), url.getPort(), url.getProtocol()
);
+
+        AuthCache authCache = new BasicAuthCache();
+        BasicScheme basicAuth = new BasicScheme();
+        authCache.put( targetHost, basicAuth );
+
+        BasicHttpContext localcontext = new BasicHttpContext();
+        localcontext.setAttribute( ClientContext.AUTH_CACHE, authCache );
+
+        HttpResponse httpResponse = httpClient.execute( targetHost, httpGet, localcontext
);
+
+        System.out.println( "Response status code :: " + httpResponse.getStatusLine().getStatusCode()
);
+
+        InputStream is = IOUtils.toInputStream( EntityUtils.toString( httpResponse.getEntity(),
+                                                                      EntityUtils.getContentCharSet(
httpResponse.getEntity() ) ) );
+        String content = IOUtils.toString( is );
+
+        System.out.println( "Content :: " + content );
+    }
+
+}

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProvider.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProvider.java?rev=1140480&r1=1140479&r2=1140480&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProvider.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProvider.java
Tue Jun 28 08:28:11 2011
@@ -19,17 +19,35 @@ package org.apache.continuum.webdav;
  * under the License.
  */
 
+import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavSessionProvider;
 import org.apache.jackrabbit.webdav.WebdavRequest;
+import org.codehaus.plexus.util.Base64;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletResponse;
 
 public class ContinuumBuildAgentDavSessionProvider
     implements DavSessionProvider
 {
+    private Logger log = LoggerFactory.getLogger( this.getClass() );
+
+    private BuildAgentConfigurationService buildAgentConfigurationService;
+
+    public ContinuumBuildAgentDavSessionProvider( BuildAgentConfigurationService buildAgentConfigurationService
)
+    {
+        this.buildAgentConfigurationService = buildAgentConfigurationService;
+    }
+
     public boolean attachSession( WebdavRequest request )
         throws DavException
     {
-        // TODO check if user is authorized
+        if( !isAuthorized( request ) )
+        {
+            throw new DavException( HttpServletResponse.SC_UNAUTHORIZED );
+        }
 
         request.setDavSession( new ContinuumBuildAgentDavSession() );
 
@@ -40,4 +58,40 @@ public class ContinuumBuildAgentDavSessi
     {
         request.setDavSession(null);
     }
+
+    private boolean isAuthorized( WebdavRequest request )
+    {
+        String header = request.getHeader( "Authorization" );
+
+        // in tomcat this is : authorization=Basic YWRtaW46TWFuYWdlMDc=
+        if ( header == null )
+        {
+            header = request.getHeader( "authorization" );
+        }
+
+        if ( ( header != null ) && header.startsWith( "Basic " ) )
+        {
+            String base64Token = header.substring( 6 );
+            String token = new String( Base64.decodeBase64( base64Token.getBytes() ) );
+
+            String password = "";
+            int delim = token.indexOf( ':' );
+
+            if ( delim != ( -1 ) )
+            {
+                password = token.substring( delim + 1 );
+            }
+
+            if( buildAgentConfigurationService.getSharedSecretPassword() != null &&
+                buildAgentConfigurationService.getSharedSecretPassword().equals( password
) )
+            {
+                log.debug( "Password matches configured shared key in continuum build agent."
);
+                return true;
+            }
+        }
+
+        log.warn( "Not authorized to access the working copy." );
+
+        return false;
+    }
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/WorkingCopyServlet.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/WorkingCopyServlet.java?rev=1140480&r1=1140479&r2=1140480&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/WorkingCopyServlet.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/main/java/org/apache/continuum/webdav/WorkingCopyServlet.java
Tue Jun 28 08:28:11 2011
@@ -21,26 +21,41 @@ package org.apache.continuum.webdav;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
+import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
+import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.webdav.DavMethods;
 import org.apache.jackrabbit.webdav.DavResource;
 import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.DavSessionProvider;
 import org.apache.jackrabbit.webdav.WebdavRequest;
+import org.apache.jackrabbit.webdav.WebdavRequestImpl;
+import org.apache.jackrabbit.webdav.WebdavResponse;
+import org.apache.jackrabbit.webdav.WebdavResponseImpl;
 import org.apache.jackrabbit.webdav.server.AbstractWebdavServlet;
 import org.codehaus.plexus.spring.PlexusToSpringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.web.context.WebApplicationContext;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 
+import java.io.IOException;
+
 public class WorkingCopyServlet
     extends AbstractWebdavServlet
 {
+    private Logger log = LoggerFactory.getLogger( this.getClass() );
+
     private DavLocatorFactory locatorFactory;
 
     private DavResourceFactory resourceFactory;
 
-    private DavSessionProvider sessionProvider;
+    protected DavSessionProvider sessionProvider;
 
     @Override
     public void init( ServletConfig servletConfig )
@@ -50,6 +65,74 @@ public class WorkingCopyServlet
         initServers( servletConfig );
     }
 
+    /**
+     * Service the given request. This method has been overridden and copy/pasted to allow
better exception handling and
+     * to support different realms
+     *
+     * @param request
+     * @param response
+     * @throws ServletException
+     * @throws java.io.IOException
+     */
+    @Override
+    protected void service( HttpServletRequest request, HttpServletResponse response )
+        throws ServletException, IOException
+    {
+        WebdavRequest webdavRequest = new WebdavRequestImpl( request, getLocatorFactory()
);
+
+        // DeltaV requires 'Cache-Control' header for all methods except 'VERSION-CONTROL'
and 'REPORT'.
+        int methodCode = DavMethods.getMethodCode( request.getMethod() );
+        boolean noCache =
+            DavMethods.isDeltaVMethod( webdavRequest )
+                && !( DavMethods.DAV_VERSION_CONTROL == methodCode || DavMethods.DAV_REPORT
== methodCode );
+        WebdavResponse webdavResponse = new WebdavResponseImpl( response, noCache );
+        DavResource resource = null;
+
+        try
+        {
+            // make sure there is a authenticated user
+            if ( !( getDavSessionProvider() ).attachSession( webdavRequest ) )
+            {
+                return;
+            }
+
+            // check matching if=header for lock-token relevant operations
+            resource =
+                getResourceFactory().createResource( webdavRequest.getRequestLocator(), webdavRequest,
webdavResponse );
+
+            if ( !isPreconditionValid( webdavRequest, resource ) )
+            {
+                webdavResponse.sendError( DavServletResponse.SC_PRECONDITION_FAILED );
+                return;
+            }
+            if ( !execute( webdavRequest, webdavResponse, methodCode, resource ) )
+            {
+                super.service( request, response );
+            }
+        }
+        catch ( DavException e )
+        {
+            if ( e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED )
+            {
+                final String msg = "Unauthorized error";
+                log.error( msg );
+                webdavResponse.sendError( e.getErrorCode(), msg );
+            }
+            else if ( e.getCause() != null )
+            {
+                webdavResponse.sendError( e.getErrorCode(), e.getCause().getMessage() );
+            }
+            else
+            {
+                webdavResponse.sendError( e.getErrorCode(), e.getMessage() );
+            }
+        }
+        finally
+        {
+            getDavSessionProvider().releaseSession( webdavRequest );
+        }
+    }
+
     public synchronized void initServers( ServletConfig servletConfig )
     {
         WebApplicationContext wac =
@@ -58,8 +141,12 @@ public class WorkingCopyServlet
         resourceFactory =
             (DavResourceFactory) wac.getBean( PlexusToSpringUtils.
                                               buildSpringId( ContinuumBuildAgentDavResourceFactory.class
) );
+
+        BuildAgentConfigurationService buildAgentConfigurationService = (BuildAgentConfigurationService)
+            wac.getBean( PlexusToSpringUtils.buildSpringId( BuildAgentConfigurationService.class
) );
+
         locatorFactory = new ContinuumBuildAgentDavLocatorFactory();
-        sessionProvider = new ContinuumBuildAgentDavSessionProvider();
+        sessionProvider = new ContinuumBuildAgentDavSessionProvider( buildAgentConfigurationService);
     }
 
     @Override

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProviderTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProviderTest.java?rev=1140480&r1=1140479&r2=1140480&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProviderTest.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/ContinuumBuildAgentDavSessionProviderTest.java
Tue Jun 28 08:28:11 2011
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.security.Principal;
 import java.util.Enumeration;
+import java.util.Hashtable;
 import java.util.Locale;
 import java.util.Map;
 
@@ -33,11 +34,15 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
 import org.apache.jackrabbit.webdav.DavSessionProvider;
 import org.apache.jackrabbit.webdav.WebdavRequest;
 import org.apache.jackrabbit.webdav.WebdavRequestImpl;
 
 import junit.framework.TestCase;
+import org.codehaus.plexus.util.Base64;
+import org.easymock.MockControl;
 
 public class ContinuumBuildAgentDavSessionProviderTest
     extends TestCase
@@ -46,20 +51,40 @@ public class ContinuumBuildAgentDavSessi
 
     private WebdavRequest request;
 
+    private MockControl buildAgentConfigurationServiceControl;
+
+    private BuildAgentConfigurationService buildAgentConfigurationService;
+
     @Override
     protected void setUp()
         throws Exception
     {
         super.setUp();
-        sessionProvider = new ContinuumBuildAgentDavSessionProvider();
+
+        buildAgentConfigurationServiceControl = MockControl.
+            createControl( BuildAgentConfigurationService.class );
+        buildAgentConfigurationService =
+            (BuildAgentConfigurationService) buildAgentConfigurationServiceControl.getMock();
+
+        sessionProvider = new ContinuumBuildAgentDavSessionProvider( buildAgentConfigurationService
);
         request = new WebdavRequestImpl( new HttpServletRequestMock(), null );
+
+        buildAgentConfigurationServiceControl.expectAndReturn(
+            buildAgentConfigurationService.getSharedSecretPassword(), "secret", 2 );
+
+        buildAgentConfigurationServiceControl.replay();
+
     }
 
     public void testAttachSession()
         throws Exception
     {
         assertNull( request.getDavSession() );
+
         sessionProvider.attachSession( request );
+        
+        buildAgentConfigurationServiceControl.verify();
+
         assertNotNull( request.getDavSession() );
     }
 
@@ -67,13 +92,17 @@ public class ContinuumBuildAgentDavSessi
         throws Exception
     {
         assertNull( request.getDavSession() );
+
         sessionProvider.attachSession( request );
+
+        buildAgentConfigurationServiceControl.verify();
+
         assertNotNull( request.getDavSession() );
         
         sessionProvider.releaseSession( request );
         assertNull( request.getDavSession() );
     }
-
+    
     @SuppressWarnings("unchecked")
     private class HttpServletRequestMock implements HttpServletRequest
     {
@@ -236,7 +265,13 @@ public class ContinuumBuildAgentDavSessi
             throw new UnsupportedOperationException("Not supported yet.");
         }
 
-        public String getHeader(String arg0) {
+        public String getHeader(String arg0)
+        {
+            if( arg0 != null && arg0.equalsIgnoreCase( "authorization" ) )
+            {
+                return getAuthorizationHeader();
+            }
+
             return "";
         }
 
@@ -247,7 +282,10 @@ public class ContinuumBuildAgentDavSessi
 
         public Enumeration getHeaders(String arg0) 
         {
-            throw new UnsupportedOperationException("Not supported yet.");
+            Hashtable<String, String> hashTable = new Hashtable<String,String>();
+            hashTable.put( "Authorization", getAuthorizationHeader() );
+
+            return hashTable.elements();
         }
 
         public int getIntHeader(String arg0) 
@@ -339,5 +377,18 @@ public class ContinuumBuildAgentDavSessi
         {
             throw new UnsupportedOperationException("Not supported yet.");
         }
+
+        private String getAuthorizationHeader()
+        {
+            try
+            {
+                String encodedPassword = IOUtils.toString( Base64.encodeBase64( ":secret".getBytes()
) ) ;
+                return "Basic " + encodedPassword;
+            }
+            catch( IOException e )
+            {
+                return "";
+            }
+        }
     }
 }

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockWorkingCopyServlet.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockWorkingCopyServlet.java?rev=1140480&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockWorkingCopyServlet.java
(added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockWorkingCopyServlet.java
Tue Jun 28 08:28:11 2011
@@ -0,0 +1,44 @@
+package org.apache.continuum.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.continuum.buildagent.configuration.DefaultBuildAgentConfigurationService;
+import javax.servlet.ServletConfig;
+
+public class MockWorkingCopyServlet
+        extends WorkingCopyServlet
+{
+    @Override
+    public synchronized void initServers( ServletConfig servletConfig )
+    {
+        super.initServers( servletConfig );
+        sessionProvider = new ContinuumBuildAgentDavSessionProvider( new BuildAgentConfigurationServiceMock()
);
+    }
+
+    public class BuildAgentConfigurationServiceMock
+        extends DefaultBuildAgentConfigurationService
+    {
+        @Override
+        public String getSharedSecretPassword()
+        {
+            return "secret";
+        }
+    }
+}

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java?rev=1140480&r1=1140479&r2=1140480&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java
Tue Jun 28 08:28:11 2011
@@ -20,12 +20,13 @@ package org.apache.continuum.webdav;
  */
 
 import java.io.File;
-
+import java.io.IOException;
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.ehcache.CacheManager;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 
 import com.meterware.httpunit.GetMethodWebRequest;
@@ -35,6 +36,7 @@ import com.meterware.httpunit.WebRequest
 import com.meterware.httpunit.WebResponse;
 import com.meterware.servletunit.ServletRunner;
 import com.meterware.servletunit.ServletUnitClient;
+import org.codehaus.plexus.util.Base64;
 
 public class WorkingCopyServletTest
     extends PlexusInSpringTestCase
@@ -67,7 +69,7 @@ public class WorkingCopyServletTest
         HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
 
         sr = new ServletRunner( getTestFile( "src/test/resources/WEB-INF/web.xml" ) );
-        sr.registerServlet( "/workingcopy/*", WorkingCopyServlet.class.getName() );
+        sr.registerServlet( "/workingcopy/*", MockWorkingCopyServlet.class.getName() );
         sc = sr.newClient();
 
         new File( workingDirectory, "1/src/main/java/org/apache/continuum" ).mkdirs();
@@ -103,7 +105,7 @@ public class WorkingCopyServletTest
     public void testGetWorkingCopy()
         throws Exception
     {
-        WorkingCopyServlet servlet = (WorkingCopyServlet) sc.newInvocation( REQUEST_PATH
).getServlet();
+        MockWorkingCopyServlet servlet = (MockWorkingCopyServlet) sc.newInvocation( REQUEST_PATH
).getServlet();
         assertNotNull( servlet );
     }
 
@@ -111,6 +113,8 @@ public class WorkingCopyServletTest
         throws Exception
     {
         request = new GetMethodWebRequest( REQUEST_PATH );
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
+
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
 
@@ -122,6 +126,8 @@ public class WorkingCopyServletTest
         throws Exception
     {
         request = new GetMethodWebRequest( REQUEST_PATH + "src/" );
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
+
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
 
@@ -134,34 +140,42 @@ public class WorkingCopyServletTest
     {
         request = new GetMethodWebRequest( REQUEST_PATH + 
                                            "src/main/java/org/apache/continuum" );
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
 
         request = new GetMethodWebRequest( REQUEST_PATH + "src/main/java/org/apache/continuum/"
);
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
 
         request = new GetMethodWebRequest( REQUEST_PATH + "src/main/java/org/apache/continuum/App.java"
);
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
 
         request = new GetMethodWebRequest( REQUEST_PATH + "src/main/java/org/apache/continuum/App.java/"
);
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode()
);
 
         request = new GetMethodWebRequest( REQUEST_PATH + "pom.xml" );
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
 
         request = new GetMethodWebRequest( REQUEST_PATH + "pom.xml/" );
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode()
);
 
         request = new GetMethodWebRequest( REQUEST_PATH + "target/continuum-artifact-1.0.jar"
);
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
 
         request = new GetMethodWebRequest( REQUEST_PATH + "target/continuum-artifact-1.0.jar/"
);
+        request.setHeaderField( "Authorization", getAuthorizationHeader() );
         response = sc.getResponse( request );
         assertEquals( "Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode()
);
     }
@@ -174,4 +188,17 @@ public class WorkingCopyServletTest
             assertEquals( "Link[" + i + "]", expectedLinks[i], actualLinks[i].getURLString()
);
         }
     }
+
+    private String getAuthorizationHeader()
+    {
+        try
+        {
+            String encodedPassword = IOUtils.toString( Base64.encodeBase64( ":secret".getBytes()
) ) ;
+            return "Basic " + encodedPassword;
+        }
+        catch( IOException e )
+        {
+            return "";
+        }
+    }
 }

Modified: continuum/trunk/continuum-buildagent/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/pom.xml?rev=1140480&r1=1140479&r2=1140480&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/pom.xml (original)
+++ continuum/trunk/continuum-buildagent/pom.xml Tue Jun 28 08:28:11 2011
@@ -1,4 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
@@ -35,5 +35,6 @@ under the License.
     <module>continuum-buildagent-webdav</module>
     <module>continuum-buildagent-webapp</module>
     <module>continuum-buildagent-jetty</module>
+    <module>continuum-buildagent-webdav-client</module>
   </modules>
 </project>



Mime
View raw message