Index: archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java
===================================================================
--- archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java (revision 648107)
+++ archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java (working copy)
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.web.util;
+package org.apache.maven.archiva.security;
/*
* Licensed to the Apache Software Foundation (ASF) under one
Property changes on: archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ "Author Date Id Revision"
Name: svn:eol-style
+ native
Index: archiva-modules/archiva-web/archiva-security/src/main/resources/plexus/components.xml
===================================================================
--- archiva-modules/archiva-web/archiva-security/src/main/resources/plexus/components.xml (revision 0)
+++ archiva-modules/archiva-web/archiva-security/src/main/resources/plexus/components.xml (revision 0)
@@ -0,0 +1,10 @@
+
+
+
+ org.apache.maven.archiva.security.ArchivaUser
+ xwork
+ org.apache.maven.archiva.security.ArchivaXworkUser
+ ArchivaXworkUser
+
+
+
Index: archiva-modules/archiva-web/archiva-security/pom.xml
===================================================================
--- archiva-modules/archiva-web/archiva-security/pom.xml (revision 649058)
+++ archiva-modules/archiva-web/archiva-security/pom.xml (working copy)
@@ -112,5 +112,15 @@
+
+ org.codehaus.plexus.redback
+ redback-xwork-integration
+
+
+ org.codehaus.plexus
+ plexus-container-default
+
+
+
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavProviderTestCase.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavProviderTestCase.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavProviderTestCase.java (working copy)
@@ -1,401 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.test;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.webdav.DavServerManager;
-import org.apache.webdav.lib.WebdavResource;
-import org.apache.webdav.lib.WebdavResources;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * AbstractWebdavProviderTestCase
- *
- * @author Joakim Erdfelt
- * @version $Id: AbstractWebdavProviderTestCase.java 5997 2007-03-04 19:41:15Z joakime $
- */
-public abstract class AbstractWebdavProviderTestCase
- extends PlexusInSpringTestCase
-{
- public static final int PORT = 4321;
-
- public static final String CONTEXT = "/repos";
-
- protected File serverRootDir = null;
-
- private DavServerManager manager;
-
- private String providerHint = "simple";
-
- public DavServerManager getManager()
- {
- return manager;
- }
-
- public String getProviderHint()
- {
- return providerHint;
- }
-
- public void setManager( DavServerManager manager )
- {
- this.manager = manager;
- }
-
- public void setProviderHint( String providerHint )
- {
- this.providerHint = providerHint;
- }
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
- try
- {
- manager = (DavServerManager) lookup( DavServerManager.ROLE, getProviderHint() );
- serverRootDir = getRootDir();
- }
- catch ( Exception e )
- {
- tearDown();
- throw e;
- }
- }
-
- protected void tearDown()
- throws Exception
- {
- serverRootDir = null;
-
- super.tearDown();
- }
-
- protected void dumpCollection( WebdavResource webdavResource, String path )
- throws Exception
- {
- webdavResource.setPath( path );
- WebdavResource resources[] = webdavResource.listWebdavResources();
-
- System.out.println( "Dump Collection [" + path + "]: " + resources.length + " hits." );
-
- dumpCollectionRecursive( "", webdavResource, path );
- }
-
- protected void dumpCollectionRecursive( String indent, WebdavResource webdavResource, String path )
- throws Exception
- {
- if ( indent.length() > 12 )
- {
- return;
- }
-
- WebdavResource resources[] = webdavResource.listWebdavResources();
-
- for ( int i = 0; i < resources.length; i++ )
- {
- System.out.println( indent + "WebDavResource[" + path + "|" + i + "]: "
- + ( resources[i].isCollection() ? "(collection) " : "" ) + resources[i].getName() );
-
- if ( resources[i].isCollection() )
- {
- dumpCollectionRecursive( indent + " ", resources[i], path + "/" + resources[i].getName() );
- }
- }
- }
-
- // --------------------------------------------------------------------
- // Actual Test Cases.
- // --------------------------------------------------------------------
-
- public void assertNotExists( File basedir, String relativePath )
- {
- assertNotExists( new File( basedir, relativePath ) );
- }
-
- public void assertNotExists( File file )
- {
- if ( file.exists() )
- {
- fail( "Unexpected path <" + file.getAbsolutePath() + "> should not exist." );
- }
- }
-
- public void assertExists( File basedir, String relativePath )
- {
- assertExists( new File( basedir, relativePath ) );
- }
-
- public void assertExists( File file )
- {
- if ( !file.exists() )
- {
- fail( "Expected path <" + file.getAbsolutePath() + "> does not exist." );
- }
- }
-
- private void resetDirectory( File dir )
- {
- try
- {
- FileUtils.deleteDirectory( dir );
- }
- catch ( IOException e )
- {
- fail( "Unable to delete test directory [" + dir.getAbsolutePath() + "]." );
- }
-
- if ( dir.exists() )
- {
- fail( "Unable to execute test, test directory [" + dir.getAbsolutePath()
- + "] exists, and cannot be deleted by the test case." );
- }
-
- if ( !dir.mkdirs() )
- {
- fail( "Unable to execute test, test directory [" + dir.getAbsolutePath() + "] cannot be created." );
- }
- }
-
- private File getRootDir()
- {
- if ( this.serverRootDir == null )
- {
- String clazz = this.getClass().getName();
- clazz = clazz.substring( clazz.lastIndexOf( "." ) + 1 );
- serverRootDir = new File( "target/test-contents-" + clazz + "/" + getName() );
-
- resetDirectory( serverRootDir );
- }
-
- return serverRootDir;
- }
-
- protected File getTestDir( String subdir )
- {
- File testDir = new File( getRootDir(), subdir );
- resetDirectory( testDir );
- return testDir;
- }
-
- public boolean isHttpStatusOk( WebdavResource webdavResource )
- {
- int statusCode = webdavResource.getStatusCode();
-
- if ( statusCode == HttpStatus.SC_MULTI_STATUS )
- {
- // TODO: find out multi-status values.
- }
-
- return ( statusCode >= 200 ) && ( statusCode < 300 );
- }
-
- public void assertDavMkDir( WebdavResource webdavResource, String collectionName )
- throws Exception
- {
- String httpurl = webdavResource.getHttpURL().toString();
-
- if ( !webdavResource.mkcolMethod( collectionName ) )
- {
- fail( "Unable to create collection/dir <" + collectionName + "> against <" + httpurl + "> due to <"
- + webdavResource.getStatusMessage() + ">" );
- }
-
- assertDavDirExists( webdavResource, collectionName );
- }
-
- public void assertDavFileExists( WebdavResource webdavResource, String path, String filename )
- throws Exception
- {
- String httpurl = webdavResource.getHttpURL().toString();
-
- if ( !webdavResource.headMethod( path + "/" + filename ) )
- {
- fail( "Unable to verify that file/contents <" + path + "/" + filename + "> exists against <" + httpurl
- + "> due to <" + webdavResource.getStatusMessage() + ">" );
- }
-
- String oldPath = webdavResource.getPath();
- try
- {
- webdavResource.setPath( path );
-
- WebdavResources resources = webdavResource.getChildResources();
-
- WebdavResource testResource = resources.getResource( filename );
-
- if ( testResource == null )
- {
- fail( "The file/contents <" + path + "/" + filename + "> does not exist in <" + httpurl + ">" );
- }
-
- if ( testResource.isCollection() )
- {
- fail( "The file/contents <" + path + "/" + filename
- + "> is incorrectly being reported as a collection." );
- }
- }
- finally
- {
- webdavResource.setPath( oldPath );
- }
- }
-
- public void assertDavFileNotExists( WebdavResource webdavResource, String path, String filename )
- throws Exception
- {
- String httpurl = webdavResource.getHttpURL().toString();
-
- if ( webdavResource.headMethod( path + "/" + filename ) )
- {
- fail( "Encountered unexpected file/contents <" + path + "/" + filename + "> at <" + httpurl + ">" );
- }
-
- String oldPath = webdavResource.getPath();
- try
- {
- webdavResource.setPath( path );
-
- WebdavResources resources = webdavResource.getChildResources();
-
- WebdavResource testResource = resources.getResource( filename );
-
- if ( testResource == null )
- {
- // Nothing found. we're done.
- return;
- }
-
- if ( !testResource.isCollection() )
- {
- fail( "Encountered unexpected file/contents <" + path + "/" + filename + "> at <" + httpurl + ">" );
- }
- }
- finally
- {
- webdavResource.setPath( oldPath );
- }
- }
-
- public void assertDavDirExists( WebdavResource webdavResource, String path )
- throws Exception
- {
- String httpurl = webdavResource.getHttpURL().toString();
-
- String oldPath = webdavResource.getPath();
- try
- {
- webdavResource.setPath( path );
-
- if ( !webdavResource.isCollection() )
- {
- if ( !isHttpStatusOk( webdavResource ) )
- {
- fail( "Unable to verify that path <" + path + "> is really a collection against <" + httpurl
- + "> due to <" + webdavResource.getStatusMessage() + ">" );
- }
- }
- }
- finally
- {
- webdavResource.setPath( oldPath );
- }
- }
-
- public void assertDavDirNotExists( WebdavResource webdavResource, String path )
- throws Exception
- {
- String httpurl = webdavResource.getHttpURL().toString();
-
- String oldPath = webdavResource.getPath();
- try
- {
- webdavResource.setPath( path );
-
- if ( webdavResource.isCollection() )
- {
- fail( "Encountered unexpected collection <" + path + "> at <" + httpurl + ">" );
- }
- }
- catch ( HttpException e )
- {
- if ( e.getReasonCode() == HttpStatus.SC_NOT_FOUND )
- {
- // Expected path.
- return;
- }
-
- fail( "Unable to set path due to HttpException: " + e.getReasonCode() + ":" + e.getReason() );
- }
- finally
- {
- webdavResource.setPath( oldPath );
- }
- }
-
- public void assertDavTouchFile( WebdavResource webdavResource, String path, String filename, String contents )
- throws Exception
- {
- String httpurl = webdavResource.getHttpURL().toString();
-
- webdavResource.setPath( path );
-
- if ( !webdavResource.putMethod( path + "/" + filename, contents ) )
- {
- fail( "Unable to create file/contents <" + path + "/" + filename + "> against <" + httpurl + "> due to <"
- + webdavResource.getStatusMessage() + ">" );
- }
-
- assertDavFileExists( webdavResource, path, filename );
- }
-
- protected void assertGet404( String url )
- throws IOException
- {
- HttpClient client = new HttpClient();
- GetMethod method = new GetMethod( url );
-
- try
- {
- client.executeMethod( method );
-
- if ( method.getStatusCode() == 404 )
- {
- // Expected path.
- return;
- }
-
- fail( "Request for resource " + url + " should have resulted in an HTTP 404 (Not Found) response, "
- + "instead got code " + method.getStatusCode() + " <" + method.getStatusText() + ">." );
- }
- catch ( HttpException e )
- {
- System.err.println( "HTTP Response: " + e.getReasonCode() + " " + e.getReason() );
- throw e;
- }
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavServer.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavServer.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavServer.java (working copy)
@@ -1,163 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.test;
-
-import org.apache.maven.archiva.webdav.DavServerManager;
-import org.apache.maven.archiva.webdav.servlet.basic.BasicWebDavServlet;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.PlexusContainerException;
-import org.codehaus.plexus.spring.PlexusContainerAdapter;
-import org.codehaus.plexus.util.FileUtils;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.Context;
-import org.mortbay.jetty.servlet.ServletHandler;
-import org.mortbay.jetty.servlet.ServletHolder;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * AbstractWebdavServer - Baseline server for starting up a BasicWebDavServlet to allow experimentation with.
- *
- * @author Joakim Erdfelt
- * @version $Id: AbstractWebdavServer.java 5407 2007-01-12 19:41:09Z joakime $
- */
-public abstract class AbstractWebdavServer
-{
- public static final int PORT = 14541;
-
- protected PlexusContainer container;
-
- protected String basedir;
-
- /** the jetty server */
- protected Server server;
-
- private DavServerManager manager;
-
- public String getBasedir()
- {
- if ( basedir != null )
- {
- return basedir;
- }
-
- basedir = System.getProperty( "basedir" );
- if ( basedir == null )
- {
- basedir = new File( "" ).getAbsolutePath();
- }
-
- return basedir;
- }
-
- public File getTestFile( String path )
- {
- return new File( getBasedir(), path );
- }
-
- protected abstract String getProviderHint();
-
- public void startServer()
- throws Exception
- {
- container = createContainerInstance();
-
- // ----------------------------------------------------------------------------
- // Create the DavServerManager
- // ----------------------------------------------------------------------------
-
- manager = (DavServerManager) container.lookup( DavServerManager.ROLE, getProviderHint() );
-
- // ----------------------------------------------------------------------------
- // Create the jetty server
- // ----------------------------------------------------------------------------
-
- System.setProperty( "DEBUG", "" );
- System.setProperty( "org.mortbay.log.class", "org.slf4j.impl.SimpleLogger" );
-
- server = new Server( PORT );
- Context root = new Context( server, "/", Context.SESSIONS );
- ServletHandler servletHandler = root.getServletHandler();
- root.setContextPath( "/" );
- root.setAttribute( PlexusConstants.PLEXUS_KEY, container );
-
- // ----------------------------------------------------------------------------
- // Configure the webdav servlet
- // ----------------------------------------------------------------------------
-
- ServletHolder holder = servletHandler.addServletWithMapping( BasicWebDavServlet.class, "/projects/*" );
-
- // Initialize server contents directory.
- File serverContentsDir = new File( "target/test-server/" );
-
- FileUtils.deleteDirectory( serverContentsDir );
- if ( serverContentsDir.exists() )
- {
- throw new IllegalStateException( "Unable to execute test, server contents test directory ["
- + serverContentsDir.getAbsolutePath() + "] exists, and cannot be deleted by the test case." );
- }
-
- if ( !serverContentsDir.mkdirs() )
- {
- throw new IllegalStateException( "Unable to execute test, server contents test directory ["
- + serverContentsDir.getAbsolutePath() + "] cannot be created." );
- }
-
- holder.setInitParameter( "dav.root", serverContentsDir.getAbsolutePath() );
-
- // ----------------------------------------------------------------------------
- // Start the jetty server
- // ----------------------------------------------------------------------------
-
- server.start();
- }
-
- protected PlexusContainer createContainerInstance()
- throws PlexusContainerException
- {
- return new PlexusContainerAdapter();
- }
-
- public void stopServer()
- {
- if ( server != null )
- {
- try
- {
- server.stop();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- }
-
- if ( container != null )
- {
- container.dispose();
- }
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractBasicWebdavProviderTestCase.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractBasicWebdavProviderTestCase.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractBasicWebdavProviderTestCase.java (working copy)
@@ -1,255 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.test;
-
-import org.apache.commons.httpclient.HttpURL;
-import org.apache.maven.archiva.webdav.servlet.basic.BasicWebDavServlet;
-import org.apache.webdav.lib.WebdavResource;
-import org.codehaus.plexus.util.IOUtil;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.ServletHandler;
-import org.mortbay.jetty.servlet.ServletHolder;
-import org.mortbay.jetty.webapp.WebAppContext;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * AbstractBasicWebdavProviderTestCase
- *
- * @author Joakim Erdfelt
- * @version $Id: AbstractBasicWebdavProviderTestCase.java 6000 2007-03-04 22:01:49Z joakime $
- */
-public abstract class AbstractBasicWebdavProviderTestCase
- extends AbstractWebdavProviderTestCase
-{
- private File serverRepoDir;
-
- private WebdavResource davRepo;
-
- /** The Jetty Server. */
- private Server server;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- // Initialize server contents directory.
-
- serverRepoDir = getTestDir( "sandbox" );
-
- // Setup the Jetty Server.
-
- System.setProperty( "DEBUG", "" );
- System.setProperty( "org.mortbay.log.class", "org.slf4j.impl.SimpleLogger" );
-
- server = new Server( PORT );
- WebAppContext webAppConfig = new WebAppContext( server, getTestFile( "src/test/webapp" ).getCanonicalPath(), "/" );
-
- ServletHandler servletHandler = webAppConfig.getServletHandler();
-
- ServletHolder holder = servletHandler.addServletWithMapping( BasicWebDavServlet.class, CONTEXT + "/*" );
-
- holder.setInitParameter( "dav.root", serverRepoDir.getAbsolutePath() );
-
- server.start();
-
- // Setup Client Side
-
- HttpURL httpSandboxUrl = new HttpURL( "http://localhost:" + PORT + CONTEXT + "/" );
-
- try
- {
- davRepo = new WebdavResource( httpSandboxUrl );
-
- davRepo.setDebug( 8 );
-
- davRepo.setPath( CONTEXT );
- }
- catch ( IOException e )
- {
- tearDown();
- throw e;
- }
- }
-
- protected void tearDown()
- throws Exception
- {
- serverRepoDir = null;
-
- if ( server != null )
- {
- try
- {
- server.stop();
- }
- catch ( Exception e )
- {
- /* ignore */
- }
- server = null;
- }
-
- if ( davRepo != null )
- {
- try
- {
- davRepo.close();
- }
- catch ( Exception e )
- {
- /* ignore */
- }
-
- davRepo = null;
- }
-
- super.tearDown();
- }
-
- // --------------------------------------------------------------------
- // Actual Test Cases.
- // --------------------------------------------------------------------
-
- public void testPutGet()
- throws Exception
- {
- // Quote: Rocky
- String contents = "yo!\n";
-
- assertDavTouchFile( davRepo, CONTEXT, "data.txt", contents );
-
- InputStream inputStream = davRepo.getMethodData( CONTEXT + "/data.txt" );
-
- assertEquals( contents, IOUtil.toString( inputStream ) );
- }
-
- public void testCollectionTasks()
- throws Exception
- {
- // Create a few collections.
- assertDavMkDir( davRepo, CONTEXT + "/bar" );
- assertDavMkDir( davRepo, CONTEXT + "/bar/foo" );
-
- // Remove a collection
- davRepo.setPath( CONTEXT );
- if ( !davRepo.deleteMethod( CONTEXT + "/bar/foo" ) )
- {
- fail( "Unable to remove <" + CONTEXT + "/bar/foo> on <" + davRepo.getHttpURL().toString() + "> due to <"
- + davRepo.getStatusMessage() + ">" );
- }
-
- assertDavDirNotExists( davRepo, CONTEXT + "/bar/foo" );
- }
-
- public void testResourceCopy()
- throws Exception
- {
- // Lyrics: Cool and the Gang - Celebrate Good Times
- String contents = "we're gonna have a good time tonite. lets celebrate. it's a celebration. "
- + "cel-e-brate good times, come on!";
-
- // Create a few collections.
- assertDavMkDir( davRepo, CONTEXT + "/bar" );
- assertDavMkDir( davRepo, CONTEXT + "/foo" );
-
- // Create a resource
- assertDavTouchFile( davRepo, CONTEXT + "/bar", "data.txt", contents );
-
- // Test for existance of resource
- assertDavFileExists( davRepo, CONTEXT + "/bar", "data.txt" );
- assertDavFileNotExists( davRepo, CONTEXT + "/foo", "data.txt" );
-
- // Copy resource
- String source = CONTEXT + "/bar/data.txt";
- String dest = CONTEXT + "/foo/data.txt";
- if ( !davRepo.copyMethod( source, dest ) )
- {
- fail( "Unable to copy <" + source + "> to <" + dest + "> on <" + davRepo.getHttpURL().toString()
- + "> due to <" + davRepo.getStatusMessage() + ">" );
- }
-
- // Test for existance of resource
- assertDavFileExists( davRepo, CONTEXT + "/bar", "data.txt" );
- assertDavFileExists( davRepo, CONTEXT + "/foo", "data.txt" );
- }
-
- public void testResourceMove()
- throws Exception
- {
- // Lyrics: Men At Work - Who Can It Be Now
- String contents = "Who can it be knocking at my door?\n" + "Make no sound, tip-toe across the floor.\n"
- + "If he hears, he'll knock all day,\n" + "I'll be trapped, and here I'll have to stay.\n"
- + "I've done no harm, I keep to myself;\n" + "There's nothing wrong with my state of mental health.\n"
- + "I like it here with my childhood friend;\n" + "Here they come, those feelings again!\n";
-
- // Create a few collections.
- assertDavMkDir( davRepo, CONTEXT + "/bar" );
- assertDavMkDir( davRepo, CONTEXT + "/foo" );
-
- // Create a resource
- assertDavTouchFile( davRepo, CONTEXT + "/bar", "data.txt", contents );
-
- // Test for existance of resource
- assertDavFileExists( davRepo, CONTEXT + "/bar", "data.txt" );
- assertDavFileNotExists( davRepo, CONTEXT + "/foo", "data.txt" );
-
- // Copy resource
- String source = CONTEXT + "/bar/data.txt";
- String dest = CONTEXT + "/foo/data.txt";
- if ( !davRepo.moveMethod( source, dest ) )
- {
- fail( "Unable to move <" + source + "> to <" + dest + "> on <" + davRepo.getHttpURL().toString()
- + "> due to <" + davRepo.getStatusMessage() + ">" );
- }
-
- // Test for existance of resource
- assertDavFileNotExists( davRepo, CONTEXT + "/bar", "data.txt" );
- assertDavFileExists( davRepo, CONTEXT + "/foo", "data.txt" );
- }
-
- public void testResourceDelete()
- throws Exception
- {
- // Lyrics: Men At Work - Down Under
- String contents = "Lying in a den in Bombay\n" + "With a slack jaw, and not much to say\n"
- + "I said to the man, \"Are you trying to tempt me\"\n" + "Because I come from the land of plenty?\n";
-
- // Create a few collections.
- assertDavMkDir( davRepo, CONTEXT + "/bar" );
-
- // Create a resource
- assertDavTouchFile( davRepo, CONTEXT + "/bar", "data.txt", contents );
-
- // Move resource
- davRepo.setPath( CONTEXT );
- if ( !davRepo.deleteMethod( CONTEXT + "/bar/data.txt" ) )
- {
- fail( "Unable to remove <" + CONTEXT + "/bar/data.txt> on <" + davRepo.getHttpURL().toString()
- + "> due to <" + davRepo.getStatusMessage() + ">" );
- }
-
- // Test for existance via webdav interface.
- assertDavFileNotExists( davRepo, CONTEXT + "/bar", "data.txt" );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavIndexHtmlTestCase.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavIndexHtmlTestCase.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractWebdavIndexHtmlTestCase.java (working copy)
@@ -1,148 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.test;
-
-import org.apache.commons.httpclient.HttpURL;
-import org.apache.maven.archiva.webdav.servlet.basic.BasicWebDavServlet;
-import org.apache.webdav.lib.WebdavResource;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.ServletHandler;
-import org.mortbay.jetty.servlet.ServletHolder;
-import org.mortbay.jetty.webapp.WebAppContext;
-
-import java.io.File;
-import java.io.IOException;
-
-public abstract class AbstractWebdavIndexHtmlTestCase
- extends AbstractWebdavProviderTestCase
-{
- private File serverRepoDir;
-
- private WebdavResource davRepo;
-
- /** The Jetty Server. */
- private Server server;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- // Initialize server contents directory.
-
- serverRepoDir = getTestDir( "sandbox" );
-
- // Setup the Jetty Server.
-
- System.setProperty( "DEBUG", "" );
- System.setProperty( "org.mortbay.log.class", "org.slf4j.impl.SimpleLogger" );
-
- server = new Server( PORT );
- WebAppContext webAppConfig = new WebAppContext( server, getTestFile( "src/test/webapp" ).getCanonicalPath(), "/" );
-
- ServletHandler servletHandler = webAppConfig.getServletHandler();
-
- ServletHolder holder = servletHandler.addServletWithMapping( BasicWebDavServlet.class, CONTEXT + "/*" );
-
- holder.setInitParameter( BasicWebDavServlet.INIT_ROOT_DIRECTORY, serverRepoDir.getAbsolutePath() );
- holder.setInitParameter( BasicWebDavServlet.INIT_USE_INDEX_HTML, "true" );
-
- server.start();
-
- // Setup Client Side
-
- HttpURL httpSandboxUrl = new HttpURL( "http://localhost:" + PORT + CONTEXT + "/" );
-
- try
- {
- davRepo = new WebdavResource( httpSandboxUrl );
-
- davRepo.setDebug( 8 );
-
- davRepo.setPath( CONTEXT );
- }
- catch ( IOException e )
- {
- tearDown();
- throw e;
- }
- }
-
- protected void tearDown()
- throws Exception
- {
- serverRepoDir = null;
-
- if ( server != null )
- {
- try
- {
- server.stop();
- }
- catch ( Exception e )
- {
- /* ignore */
- }
- server = null;
- }
-
- if ( davRepo != null )
- {
- try
- {
- davRepo.close();
- }
- catch ( Exception e )
- {
- /* ignore */
- }
-
- davRepo = null;
- }
-
- super.tearDown();
- }
-
- public void testCollectionIndexHtml()
- throws Exception
- {
- // Lyrics: Colin Hay - Overkill
- String contents = "I cant get to sleep\n" + "I think about the implications\n" + "Of diving in too deep\n"
- + "And possibly the complications\n" + "Especially at night\n" + "I worry over situations\n"
- + "I know will be alright\n" + "Perahaps its just my imagination\n" + "Day after day it reappears\n"
- + "Night after night my heartbeat, shows the fear\n" + "Ghosts appear and fade away";
-
- // Create a few collections.
- assertDavMkDir( davRepo, CONTEXT + "/bar" );
- assertDavMkDir( davRepo, CONTEXT + "/foo" );
-
- // Create a resource
- assertDavTouchFile( davRepo, CONTEXT + "/bar", "index.html", contents );
-
- // Test for existance of resource
- assertDavFileExists( davRepo, CONTEXT + "/bar", "index.html" );
- assertDavFileNotExists( davRepo, CONTEXT + "/foo", "index.html" );
-
- // Copy resource
- String actual = davRepo.getMethodDataAsString( CONTEXT + "/bar/" );
-
- assertEquals( contents, actual );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/TestMultiWebDavServlet.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/TestMultiWebDavServlet.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/TestMultiWebDavServlet.java (working copy)
@@ -1,46 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.test;
-
-import org.apache.maven.archiva.webdav.DavServerException;
-import org.apache.maven.archiva.webdav.servlet.multiplexed.MultiplexedWebDavServlet;
-
-import javax.servlet.ServletConfig;
-import java.io.File;
-
-/**
- * TestServlet
- *
- * @author Joakim Erdfelt
- * @version $Id: TestMultiWebDavServlet.java 5407 2007-01-12 19:41:09Z joakime $
- */
-public class TestMultiWebDavServlet
- extends MultiplexedWebDavServlet
-{
- public void initServers( ServletConfig config )
- throws DavServerException
- {
- String rootSandbox = config.getInitParameter( "root.sandbox" );
- String rootSnapshots = config.getInitParameter( "root.snapshots" );
-
- createServer( "sandbox", new File( rootSandbox ), config );
- createServer( "snapshots", new File( rootSnapshots ), config );
- }
-}
\ No newline at end of file
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractMultiWebdavProviderTestCase.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractMultiWebdavProviderTestCase.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/test/AbstractMultiWebdavProviderTestCase.java (working copy)
@@ -1,203 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.test;
-
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.HttpURL;
-import org.apache.webdav.lib.WebdavResource;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.ServletHandler;
-import org.mortbay.jetty.servlet.ServletHolder;
-import org.mortbay.jetty.webapp.WebAppContext;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * AbstractMultiWebdavProviderTestCase
- *
- * @author Joakim Erdfelt
- * @version $Id: AbstractMultiWebdavProviderTestCase.java 5997 2007-03-04 19:41:15Z joakime $
- */
-public abstract class AbstractMultiWebdavProviderTestCase
- extends AbstractWebdavProviderTestCase
-{
- File serverSandboxDir;
-
- File serverSnapshotsDir;
-
- /** The Jetty Server. */
- private Server server;
-
- private WebdavResource davSnapshots;
-
- private WebdavResource davSandbox;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- // Initialize server contents directory.
-
- serverSandboxDir = getTestDir( "sandbox" );
- serverSnapshotsDir = getTestDir( "snapshots" );
-
- // Setup the Jetty Server.
-
- System.setProperty( "DEBUG", "" );
- System.setProperty( "org.mortbay.log.class", "org.slf4j.impl.SimpleLogger" );
-
- server = new Server( PORT );
-
- WebAppContext webAppConfig = new WebAppContext( server, getTestFile( "src/test/webapp" ).getCanonicalPath(), "/" );
- ServletHandler servletHandler = webAppConfig.getServletHandler();
-
- ServletHolder holder = servletHandler.addServletWithMapping( TestMultiWebDavServlet.class, CONTEXT + "/*" );
- holder.setInitParameter( "root.sandbox", serverSandboxDir.getAbsolutePath() );
- holder.setInitParameter( "root.snapshots", serverSnapshotsDir.getAbsolutePath() );
-
- System.out.println( "root.sandbox = " + serverSandboxDir.getAbsolutePath() );
- System.out.println( "root.snapshots = " + serverSnapshotsDir.getAbsolutePath() );
-
- server.start();
-
- // Setup Client Side
-
- HttpURL httpSandboxUrl = new HttpURL( "http://localhost:" + PORT + CONTEXT + "/sandbox/" );
- HttpURL httpSnapshotsUrl = new HttpURL( "http://localhost:" + PORT + CONTEXT + "/snapshots/" );
-
- try
- {
- davSandbox = new WebdavResource( httpSandboxUrl );
- davSnapshots = new WebdavResource( httpSnapshotsUrl );
-
- davSandbox.setDebug( 8 );
- davSnapshots.setDebug( 8 );
-
- davSandbox.setPath( CONTEXT + "/sandbox/" );
- davSnapshots.setPath( CONTEXT + "/snapshots/" );
- }
- catch ( IOException e )
- {
- tearDown();
- throw e;
- }
- }
-
- protected void tearDown()
- throws Exception
- {
- serverRootDir = null;
-
- if ( server != null )
- {
- try
- {
- server.stop();
- }
- catch ( Exception e )
- {
- /* ignore */
- }
- server = null;
- }
-
- if ( davSandbox != null )
- {
- try
- {
- davSandbox.close();
- }
- catch ( Exception e )
- {
- /* ignore */
- }
-
- davSandbox = null;
- }
-
- if ( davSnapshots != null )
- {
- try
- {
- davSnapshots.close();
- }
- catch ( Exception e )
- {
- /* ignore */
- }
-
- davSnapshots = null;
- }
-
- super.tearDown();
- }
-
- public void testResourceMoveCrossWebdav()
- throws Exception
- {
- // Create a few collections.
- assertDavMkDir( davSandbox, CONTEXT + "/sandbox/bar" );
- assertDavMkDir( davSnapshots, CONTEXT + "/snapshots/foo" );
-
- // Create a resource
- assertDavTouchFile( davSandbox, CONTEXT + "/sandbox/bar", "data.txt", "yo!" );
-
- // Move resource URL to URL (Across the WebDav Servlets)
- davSandbox.setPath( CONTEXT + "/sandbox/bar" );
- String source = CONTEXT + "/sandbox/bar/data.txt";
- String dest = "http://localhost:" + PORT + CONTEXT + "/snapshots/foo/data.txt";
- if ( !davSandbox.moveMethod( source, dest ) )
- {
- // TODO: remove when fully implemented.
- if ( davSandbox.getStatusCode() == HttpStatus.SC_NOT_IMPLEMENTED )
- {
- // return quietly, as the server reported no support for this method.
- return;
- }
-
- fail( "Unable to move <" + source + "> to <" + dest + "> on <" + davSandbox.getHttpURL().toString()
- + "> due to <" + davSandbox.getStatusMessage() + ">" );
- }
-
- assertDavFileNotExists( davSandbox, CONTEXT + "/sandbox/bar", "data.txt" );
- assertDavFileExists( davSnapshots, CONTEXT + "/snapshots/foo", "data.txt" );
- }
-
- public void testResourceDoesNotExist()
- throws Exception
- {
- // Create a few collections.
- assertDavMkDir( davSandbox, CONTEXT + "/sandbox/bar" );
- assertDavMkDir( davSnapshots, CONTEXT + "/snapshots/foo" );
-
- // Create a resource
- assertDavTouchFile( davSandbox, CONTEXT + "/sandbox/bar", "data.txt", "yo!" );
-
- // Get bad resources URLs
- String urlPrefix = "http://localhost:" + PORT + CONTEXT;
- assertGet404( urlPrefix + "/sandbox/a/resource/that/does/not/exist.html" );
- assertGet404( urlPrefix + "/" );
- assertGet404( urlPrefix + "/snapshots/foo/index.html" );
- assertGet404( urlPrefix + "/sandbox/bar.html" );
- assertGet404( urlPrefix + "/nonexistant/index.html" );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/TestableHttpServletRequest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/TestableHttpServletRequest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/TestableHttpServletRequest.java (working copy)
@@ -1,495 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav;
-
-import org.apache.commons.lang.NotImplementedException;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.Principal;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * TestableHttpServletRequest
- *
- * @author Joakim Erdfelt
- * @version $Id: TestableHttpServletRequest.java 6940 2007-10-16 01:02:02Z joakime $
- */
-public class TestableHttpServletRequest
- implements HttpServletRequest
-{
-
- public TestableHttpServletRequest()
- {
- setDefaults();
- }
-
- public void setDefaults()
- {
- authType = null;
- scheme = "http";
- protocol = "HTTP/1.1";
- serverName = "localhost";
- serverPort = 80;
- remoteHost = "localhost";
- }
-
- private String authType;
-
- private String characterEncoding;
-
- private int contentLength;
-
- private String contentType;
-
- private String contextPath;
-
- private Locale locale;
-
- private String method;
-
- private String pathInfo;
-
- private String pathTranslated;
-
- private String protocol;
-
- private String queryString;
-
- private String remoteAddr;
-
- private String remoteHost;
-
- private String remoteUser;
-
- private String requestedSessionId;
-
- private boolean requestedSessionIdFromCookie;
-
- private boolean requestedSessionIdFromUrl;
-
- private boolean requestedSessionIdValid;
-
- private StringBuffer requestURL;
-
- private String scheme;
-
- private boolean secure;
-
- private String serverName;
-
- private int serverPort;
-
- private String servletPath;
-
- public Object getAttribute( String name )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getAttribute(String)" ) );
- }
-
- public Enumeration getAttributeNames()
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getAttributeNames()" ) );
- }
-
- public String getAuthType()
- {
- return authType;
- }
-
- public String getCharacterEncoding()
- {
- return characterEncoding;
- }
-
- public int getContentLength()
- {
- return contentLength;
- }
-
- public String getContentType()
- {
- return contentType;
- }
-
- public String getContextPath()
- {
- return contextPath;
- }
-
- public Cookie[] getCookies()
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getCookies()" ) );
- }
-
- public long getDateHeader( String name )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getDateHeader(String)" ) );
- }
-
- public String getHeader( String name )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getHeader(String)" ) );
- }
-
- private Map headers = new HashMap();
-
- public Enumeration getHeaderNames()
- {
- return new IterEnumeration( headers.keySet().iterator() );
- }
-
- public Enumeration getHeaders( String name )
- {
- throw new NotImplementedException( notImplemented( ".getHeaders(String)" ) );
- }
-
- public ServletInputStream getInputStream()
- throws IOException
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getInputStream()" ) );
- }
-
- public int getIntHeader( String name )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getIntHeader(String)" ) );
- }
-
- public Locale getLocale()
- {
- return locale;
- }
-
- public Enumeration getLocales()
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getLocales()" ) );
- }
-
- public String getMethod()
- {
- return method;
- }
-
- public String getParameter( String name )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getParameter(String)" ) );
- }
-
- public Map getParameterMap()
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getParameterMap()" ) );
- }
-
- public Enumeration getParameterNames()
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getParameterNames()" ) );
- }
-
- public String[] getParameterValues( String name )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getParameterValues(String)" ) );
- }
-
- public String getPathInfo()
- {
- return pathInfo;
- }
-
- public String getPathTranslated()
- {
- return pathTranslated;
- }
-
- public String getProtocol()
- {
- return protocol;
- }
-
- public String getQueryString()
- {
- return queryString;
- }
-
- public BufferedReader getReader()
- throws IOException
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getReader()" ) );
- }
-
- public String getRealPath( String path )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getRealPath(String)" ) );
- }
-
- public String getRemoteAddr()
- {
- return remoteAddr;
- }
-
- public String getRemoteHost()
- {
- return remoteHost;
- }
-
- public String getRemoteUser()
- {
- return remoteUser;
- }
-
- public RequestDispatcher getRequestDispatcher( String path )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getRequestDispatcher(String)" ) );
- }
-
- public String getRequestedSessionId()
- {
- return requestedSessionId;
- }
-
- public String getRequestURI()
- {
- return requestURL.toString();
- }
-
- public StringBuffer getRequestURL()
- {
- return requestURL;
- }
-
- public String getScheme()
- {
- return scheme;
- }
-
- public String getServerName()
- {
- return serverName;
- }
-
- public int getServerPort()
- {
- return serverPort;
- }
-
- public String getServletPath()
- {
- return servletPath;
- }
-
- public HttpSession getSession()
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getSession()" ) );
- }
-
- public HttpSession getSession( boolean create )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getSession(boolean)" ) );
- }
-
- public Principal getUserPrincipal()
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".getUserPrincipal()" ) );
- }
-
- public boolean isRequestedSessionIdFromCookie()
- {
- return requestedSessionIdFromCookie;
- }
-
- public boolean isRequestedSessionIdFromUrl()
- {
- return requestedSessionIdFromUrl;
- }
-
- public boolean isRequestedSessionIdFromURL()
- {
- return requestedSessionIdFromUrl;
- }
-
- public boolean isRequestedSessionIdValid()
- {
- return requestedSessionIdValid;
- }
-
- public boolean isSecure()
- {
- return secure;
- }
-
- public boolean isUserInRole( String role )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".isUserInRole(String)" ) );
- }
-
- public void removeAttribute( String name )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".removeAttribute(String)" ) );
- }
-
- public void setAttribute( String name, Object o )
- {
- // TODO: Implement if needed.
- throw new NotImplementedException( notImplemented( ".setAttribute(String, Object)" ) );
- }
-
- public void setCharacterEncoding( String encoding )
- throws UnsupportedEncodingException
- {
- this.characterEncoding = encoding;
- }
-
- public void setContentLength( int contentLength )
- {
- this.contentLength = contentLength;
- }
-
- public void setContentType( String contentType )
- {
- this.contentType = contentType;
- }
-
- public void setContextPath( String contextPath )
- {
- this.contextPath = contextPath;
- }
-
- public void setMethod( String method )
- {
- this.method = method;
- }
-
- public void setPathInfo( String pathInfo )
- {
- this.pathInfo = pathInfo;
- }
-
- public void setProtocol( String protocol )
- {
- this.protocol = protocol;
- }
-
- public void setQueryString( String queryString )
- {
- this.queryString = queryString;
- }
-
- public void setScheme( String scheme )
- {
- this.scheme = scheme;
- }
-
- public void setSecure( boolean secure )
- {
- this.secure = secure;
- }
-
- public void setServerName( String serverName )
- {
- this.serverName = serverName;
- }
-
- public void setServerPort( int serverPort )
- {
- this.serverPort = serverPort;
- }
-
- public void setServletPath( String servletPath )
- {
- this.servletPath = servletPath;
- }
-
- public void setUrl( String urlString )
- throws MalformedURLException
- {
- URL url = new URL( urlString );
- this.queryString = url.getQuery();
- this.scheme = url.getProtocol();
- this.serverName = url.getHost();
- this.serverPort = url.getPort();
-
- String path = url.getPath();
- if ( !path.startsWith( this.servletPath ) )
- {
- throw new MalformedURLException( "Unable to operate on request path [" + path
- + "] outside of servletPath [" + this.servletPath + "]." );
- }
-
- this.pathInfo = path.substring( this.servletPath.length() );
- this.requestURL = new StringBuffer( this.pathInfo );
- }
-
- private String notImplemented( String msg )
- {
- return msg + " is not implemented in " + this.getClass().getName();
- }
-
- class IterEnumeration
- implements Enumeration
- {
- private Iterator iter;
-
- public IterEnumeration( Iterator it )
- {
- this.iter = it;
- }
-
- public boolean hasMoreElements()
- {
- return this.iter.hasNext();
- }
-
- public Object nextElement()
- {
- return this.iter.next();
- }
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedDavServerRequestTest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedDavServerRequestTest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedDavServerRequestTest.java (working copy)
@@ -1,67 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.servlet.multiplexed;
-
-import junit.framework.TestCase;
-import org.apache.maven.archiva.webdav.TestableHttpServletRequest;
-import org.apache.maven.archiva.webdav.util.WrappedRepositoryRequest;
-
-import java.net.MalformedURLException;
-
-/**
- * MultiplexedDavServerRequestTest
- *
- * @author Joakim Erdfelt
- * @version $Id: MultiplexedDavServerRequestTest.java 6940 2007-10-16 01:02:02Z joakime $
- */
-public class MultiplexedDavServerRequestTest
- extends TestCase
-{
- private void assertMultiURL( String expectedPrefix, String expectedLogicalResource, String url )
- throws MalformedURLException
- {
- TestableHttpServletRequest testrequest = new TestableHttpServletRequest();
- testrequest.setMethod( "GET" );
- testrequest.setServletPath( "/repository" );
- testrequest.setUrl( url );
-
- WrappedRepositoryRequest wraprequest = new WrappedRepositoryRequest( testrequest );
- MultiplexedDavServerRequest multirequest = new MultiplexedDavServerRequest( wraprequest );
-
- assertEquals( expectedPrefix, multirequest.getPrefix() );
- assertEquals( expectedLogicalResource, multirequest.getLogicalResource() );
- }
-
- public void testNormalUsage()
- throws MalformedURLException
- {
- assertMultiURL( "corporate", "/", "http://localhost:9091/repository/corporate" );
- assertMultiURL( "corporate", "/dom4j/dom4j/1.4", "http://localhost:9091/repository/corporate/dom4j/dom4j/1.4" );
- }
-
- public void testHacker()
- throws MalformedURLException
- {
- assertMultiURL( "corporate", "/etc/passwd", "http://localhost:9091/repository/corporate//etc/passwd" );
- // Since the double ".." puts the path outside of the /corporate/, it will return "/" as a hack fallback.
- assertMultiURL( "corporate", "/", "http://localhost:9091/repository/corporate/dom4j/../../etc/passwd" );
- assertMultiURL( "corporate", "/", "http://localhost:9091/repository/corporate/../.." );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentBasicTest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentBasicTest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentBasicTest.java (working copy)
@@ -1,38 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.simple;
-
-import org.apache.maven.archiva.webdav.test.AbstractBasicWebdavProviderTestCase;
-
-/**
- * SimpleDavServerComponentBasicTest
- *
- * @author Joakim Erdfelt
- * @version $Id: SimpleDavServerComponentBasicTest.java 5408 2007-01-12 19:42:37Z joakime $
- */
-public class SimpleDavServerComponentBasicTest
- extends AbstractBasicWebdavProviderTestCase
-{
- public SimpleDavServerComponentBasicTest()
- {
- super();
- setProviderHint( "simple" );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentMultiTest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentMultiTest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentMultiTest.java (working copy)
@@ -1,38 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.simple;
-
-import org.apache.maven.archiva.webdav.test.AbstractMultiWebdavProviderTestCase;
-
-/**
- * SimpleDavServerComponentCrossTest
- *
- * @author Joakim Erdfelt
- * @version $Id: SimpleDavServerComponentMultiTest.java 5408 2007-01-12 19:42:37Z joakime $
- */
-public class SimpleDavServerComponentMultiTest
- extends AbstractMultiWebdavProviderTestCase
-{
- public SimpleDavServerComponentMultiTest()
- {
- super();
- setProviderHint( "simple" );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleWebdavServer.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleWebdavServer.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleWebdavServer.java (working copy)
@@ -1,50 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.simple;
-
-import org.apache.maven.archiva.webdav.test.AbstractWebdavServer;
-
-/**
- * SimpleWebdavServer
- *
- * @author Joakim Erdfelt
- * @version $Id: SimpleWebdavServer.java 5379 2007-01-07 22:54:41Z joakime $
- */
-public class SimpleWebdavServer
- extends AbstractWebdavServer
-{
- public static void main( String[] args )
- {
- try
- {
- SimpleWebdavServer server = new SimpleWebdavServer();
- server.startServer();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- }
-
- protected String getProviderHint()
- {
- return "simple";
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentIndexHtmlTest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentIndexHtmlTest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponentIndexHtmlTest.java (working copy)
@@ -1,38 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.simple;
-
-import org.apache.maven.archiva.webdav.test.AbstractWebdavIndexHtmlTestCase;
-
-/**
- * SimpleDavServerComponentIndexHtmlTest
- *
- * @author Joakim Erdfelt
- * @version $Id: SimpleDavServerComponentIndexHtmlTest.java 6000 2007-03-04 22:01:49Z joakime $
- */
-public class SimpleDavServerComponentIndexHtmlTest
- extends AbstractWebdavIndexHtmlTestCase
-{
- public SimpleDavServerComponentIndexHtmlTest()
- {
- super();
- setProviderHint( "simple" );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/util/WrappedRepositoryRequestTest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/util/WrappedRepositoryRequestTest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/util/WrappedRepositoryRequestTest.java (working copy)
@@ -1,75 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.util;
-
-import org.apache.maven.archiva.webdav.TestableHttpServletRequest;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
-import javax.servlet.http.HttpServletRequest;
-import java.net.MalformedURLException;
-
-/**
- * WrappedRepositoryRequestTest
- *
- * @author Joakim Erdfelt
- * @version $Id: WrappedRepositoryRequestTest.java 6940 2007-10-16 01:02:02Z joakime $
- */
-public class WrappedRepositoryRequestTest
- extends PlexusInSpringTestCase
-{
- private HttpServletRequest createHttpServletGetRequest( String url )
- throws MalformedURLException
- {
- TestableHttpServletRequest testrequest = new TestableHttpServletRequest();
- testrequest.setMethod( "GET" );
- testrequest.setServletPath( "/repository" );
- testrequest.setUrl( url );
-
- return testrequest;
- }
-
- public void testShort()
- throws Exception
- {
- HttpServletRequest request = createHttpServletGetRequest( "http://machine.com/repository/org" );
- WrappedRepositoryRequest wrapreq = new WrappedRepositoryRequest( request );
- assertNotNull( wrapreq );
-
- assertEquals( "/repository", wrapreq.getServletPath() );
- assertEquals( "/org", wrapreq.getPathInfo() );
- assertEquals( "/org", wrapreq.getRequestURI() );
- }
-
- public void testLonger()
- throws Exception
- {
- HttpServletRequest request = createHttpServletGetRequest( "http://machine.com/repository/"
- + "org/codehaus/plexus/webdav/plexus-webdav-simple/1.0-alpha-3/plexus-webdav-simple-1.0-alpha-3.jar" );
-
- WrappedRepositoryRequest wrapreq = new WrappedRepositoryRequest( request );
- assertNotNull( wrapreq );
-
- assertEquals( "/repository", wrapreq.getServletPath() );
-
- String expected = "/org/codehaus/plexus/webdav/plexus-webdav-simple/1.0-alpha-3/plexus-webdav-simple-1.0-alpha-3.jar";
- assertEquals( expected, wrapreq.getPathInfo() );
- assertEquals( expected, wrapreq.getRequestURI() );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DefaultDavServerManager.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DefaultDavServerManager.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DefaultDavServerManager.java (working copy)
@@ -1,88 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * DefaultDavServerManager
- *
- * @author Joakim Erdfelt
- * @version $Id: DefaultDavServerManager.java 7009 2007-10-25 23:34:43Z joakime $
- *
- * @plexus.component role="org.apache.maven.archiva.webdav.DavServerManager" role-hint="default"
- */
-public class DefaultDavServerManager
- implements DavServerManager
-{
- /**
- * @plexus.requirement role-hint="simple"
- */
- private DavServerComponent server;
-
- private Map servers;
-
- public DefaultDavServerManager()
- {
- servers = new HashMap();
- }
-
- public DavServerComponent createServer( String prefix, File rootDirectory )
- throws DavServerException
- {
- if ( servers.containsKey( prefix ) )
- {
- throw new DavServerException( "Unable to create a new server on a pre-existing prefix [" + prefix + "]" );
- }
-
- server.setPrefix( prefix );
- if ( rootDirectory != null )
- {
- server.setRootDirectory( rootDirectory );
- }
-
- servers.put( prefix, server );
-
- return server;
- }
-
- public DavServerComponent getServer( String prefix )
- {
- return (DavServerComponent) servers.get( prefix );
- }
-
- public void removeServer( String prefix )
- {
- servers.remove( prefix );
- }
-
- public Collection getServers()
- {
- return servers.values();
- }
-
- public void removeAllServers()
- {
- servers.clear();
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java (revision 0)
@@ -0,0 +1,117 @@
+package org.apache.maven.archiva.webdav;
+
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.util.Text;
+
+/**
+ * @author James William Dumay
+ */
+public class ArchivaDavResourceLocator implements DavResourceLocator
+{
+ private String prefix;
+
+ private String resourcePath;
+
+ private String href;
+
+ private String workspaceName;
+
+ private DavLocatorFactory davLocatorFactory;
+
+ public ArchivaDavResourceLocator(String prefix, String resourcePath, String workspaceName, DavLocatorFactory davLocatorFactory)
+ {
+ this.prefix = prefix;
+ this.workspaceName = workspaceName;
+ this.davLocatorFactory = davLocatorFactory;
+
+ // remove trailing '/' that is not part of the resourcePath except for the root item.
+ if (resourcePath.endsWith("/") && !"/".equals(resourcePath)) {
+ resourcePath = resourcePath.substring(0, resourcePath.length()-1);
+ }
+ this.resourcePath = resourcePath;
+
+ href = prefix + Text.escapePath(resourcePath);
+ }
+
+ public String getPrefix()
+ {
+ return prefix;
+ }
+
+ public String getResourcePath()
+ {
+ return resourcePath;
+ }
+
+ public String getWorkspacePath()
+ {
+ return "";
+ }
+
+ public String getWorkspaceName()
+ {
+ return workspaceName;
+ }
+
+ public boolean isSameWorkspace(DavResourceLocator locator)
+ {
+ return isSameWorkspace(locator.getWorkspaceName());
+ }
+
+ public boolean isSameWorkspace(String workspaceName)
+ {
+ return getWorkspaceName().equals(workspaceName);
+ }
+
+ public String getHref(boolean isCollection)
+ {
+ // avoid doubled trailing '/' for the root item
+ String suffix = (isCollection && !isRootLocation()) ? "/" : "";
+ return href + suffix;
+ }
+
+ public boolean isRootLocation()
+ {
+ return "/".equals(resourcePath);
+ }
+
+ public DavLocatorFactory getFactory()
+ {
+ return davLocatorFactory;
+ }
+
+ public String getRepositoryPath()
+ {
+ return getResourcePath();
+ }
+
+ /**
+ * Computes the hash code from the href, which is built using the final
+ * fields prefix and resourcePath.
+ *
+ * @return the hash code
+ */
+ public int hashCode()
+ {
+ return href.hashCode();
+ }
+
+ /**
+ * Equality of path is achieved if the specified object is a DavResourceLocator
+ * object with the same hash code.
+ *
+ * @param obj the object to compare to
+ * @return true if the 2 objects are equal;
+ * false otherwise
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof DavResourceLocator)
+ {
+ DavResourceLocator other = (DavResourceLocator) obj;
+ return hashCode() == other.hashCode();
+ }
+ return false;
+ }
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/AbstractWebDavServlet.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/AbstractWebDavServlet.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/AbstractWebDavServlet.java (working copy)
@@ -1,164 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.servlet;
-
-import org.apache.commons.lang.BooleanUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.webdav.DavServerManager;
-import org.codehaus.plexus.spring.PlexusToSpringUtils;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.Enumeration;
-
-/**
- * AbstractWebDavServlet
- *
- * @author Joakim Erdfelt
- * @version $Id: AbstractWebDavServlet.java 7009 2007-10-25 23:34:43Z joakime $
- */
-public abstract class AbstractWebDavServlet
- extends HttpServlet
-{
- public static final String INIT_USE_INDEX_HTML = "dav.use.index.html";
-
- private boolean debug = false;
-
- protected DavServerManager davManager;
-
- public String getServletInfo()
- {
- return "Plexus WebDAV Servlet";
- }
-
- public void init( ServletConfig config )
- throws ServletException
- {
- super.init( config );
-
- WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext( config.getServletContext() );
- davManager = (DavServerManager) wac.getBean( PlexusToSpringUtils.buildSpringId( DavServerManager.ROLE ) );
- if ( davManager == null )
- {
- throw new ServletException( "Unable to lookup davManager" );
- }
- }
-
- /**
- * Perform any authentication steps here.
- *
- * If authentication fails, it is the responsibility of the implementor to issue
- * the appropriate status codes and/or challenge back on the response object, then
- * return false on the overridden version of this method.
- *
- * To effectively not have authentication, just implement this method and always
- * return true.
- *
- * @param davRequest the incoming dav request.
- * @param httpResponse the outgoing http response.
- * @return true if user is authenticated, false if not.
- * @throws ServletException if there was a problem performing authencation.
- * @throws IOException if there was a problem obtaining credentials or issuing challenge.
- */
- public boolean isAuthenticated( DavServerRequest davRequest, HttpServletResponse httpResponse )
- throws ServletException, IOException
- {
- // Always return true. Effectively no Authentication done.
- return true;
- }
-
- /**
- * Perform any authorization steps here.
- *
- * If authorization fails, it is the responsibility of the implementor to issue
- * the appropriate status codes and/or challenge back on the response object, then
- * return false on the overridden version of this method.
- *
- * to effectively not have authorization, just implement this method and always
- * return true.
- *
- * @param davRequest
- * @param httpResponse
- * @return
- * @throws ServletException
- * @throws IOException
- */
- public boolean isAuthorized( DavServerRequest davRequest, HttpServletResponse httpResponse )
- throws ServletException, IOException
- {
- // Always return true. Effectively no Authorization done.
- return true;
- }
-
- public boolean isDebug()
- {
- return debug;
- }
-
- public void setDebug( boolean debug )
- {
- this.debug = debug;
- }
-
- protected void requestDebug( HttpServletRequest request )
- {
- if ( debug )
- {
- System.out.println( "-->>> request ----------------------------------------------------------" );
- System.out.println( "--> " + request.getScheme() + "://" + request.getServerName() + ":"
- + request.getServerPort() + request.getServletPath() );
- System.out.println( request.getMethod() + " " + request.getRequestURI()
- + ( request.getQueryString() != null ? "?" + request.getQueryString() : "" ) + " " + "HTTP/1.1" );
-
- Enumeration enHeaders = request.getHeaderNames();
- while ( enHeaders.hasMoreElements() )
- {
- String headerName = (String) enHeaders.nextElement();
- String headerValue = request.getHeader( headerName );
- System.out.println( headerName + ": " + headerValue );
- }
-
- System.out.println();
-
- System.out.println( "------------------------------------------------------------------------" );
- }
- }
-
- public abstract void setUseIndexHtml( boolean useIndexHtml );
-
- public boolean getUseIndexHtml( ServletConfig config )
- throws ServletException
- {
- String useIndexHtml = config.getInitParameter( INIT_USE_INDEX_HTML );
-
- if ( StringUtils.isEmpty( useIndexHtml ) )
- {
- return false;
- }
-
- return BooleanUtils.toBoolean( useIndexHtml );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/basic/BasicWebDavServlet.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/basic/BasicWebDavServlet.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/basic/BasicWebDavServlet.java (working copy)
@@ -1,142 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.servlet.basic;
-
-import org.apache.maven.archiva.webdav.DavServerComponent;
-import org.apache.maven.archiva.webdav.DavServerException;
-import org.apache.maven.archiva.webdav.servlet.AbstractWebDavServlet;
-import org.apache.maven.archiva.webdav.servlet.DavServerRequest;
-import org.apache.maven.archiva.webdav.util.WrappedRepositoryRequest;
-import org.codehaus.plexus.util.StringUtils;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-
-/**
- * BasicWebDavServlet - Basic implementation of a single WebDAV server as servlet.
- *
- * @author Joakim Erdfelt
- * @version $Id: BasicWebDavServlet.java 6017 2007-03-06 00:39:53Z joakime $
- */
-public class BasicWebDavServlet
- extends AbstractWebDavServlet
-{
- public static final String INIT_ROOT_DIRECTORY = "dav.root";
-
- private DavServerComponent davServer;
-
- // -----------------------------------------------------------------------
- // Servlet Implementation
- // -----------------------------------------------------------------------
-
- public void init( ServletConfig config )
- throws ServletException
- {
- super.init( config );
-
- String prefix = config.getServletName();
-
- boolean useIndexHtml = getUseIndexHtml( config );
- File rootDir = getRootDirectory( config );
-
- if ( rootDir != null && !rootDir.isDirectory() )
- {
- log( "Invalid configuration, the dav root " + rootDir.getPath()
- + " is not a directory: [" + rootDir.getAbsolutePath() + "]" );
- }
-
- try
- {
- davServer = davManager.createServer( prefix, rootDir );
- davServer.setUseIndexHtml( useIndexHtml );
- davServer.init( config );
- }
- catch ( DavServerException e )
- {
- throw new ServletException( "Unable to create DAV Server component for prefix [" + prefix
- + "] mapped to root directory [" + rootDir.getPath() + "]", e );
- }
- }
-
- public File getRootDirectory( ServletConfig config )
- throws ServletException
- {
- String rootDirName = config.getInitParameter( INIT_ROOT_DIRECTORY );
-
- if ( StringUtils.isEmpty( rootDirName ) )
- {
- log( "Init Parameter '" + INIT_ROOT_DIRECTORY + "' is empty." );
- return null;
- }
-
- return new File( rootDirName );
- }
-
- protected void service( HttpServletRequest httpRequest, HttpServletResponse httpResponse )
- throws ServletException, IOException
- {
- DavServerRequest davRequest = new BasicDavServerRequest( new WrappedRepositoryRequest( httpRequest ) );
-
- if ( davServer == null )
- {
- throw new ServletException( "Unable to service DAV request due to unconfigured DavServerComponent." );
- }
-
- requestDebug( httpRequest );
-
- if ( !isAuthenticated( davRequest, httpResponse ) )
- {
- return;
- }
-
- if ( !isAuthorized( davRequest, httpResponse ) )
- {
- return;
- }
-
- try
- {
- davServer.process( davRequest, httpResponse );
- }
- catch ( DavServerException e )
- {
- throw new ServletException( "Unable to process request.", e );
- }
- }
-
- public void setUseIndexHtml( boolean useIndexHtml )
- {
- davServer.setUseIndexHtml( useIndexHtml );
- }
-
- public DavServerComponent getDavServer()
- {
- return davServer;
- }
-
- public void setDavServer( DavServerComponent davServer )
- {
- this.davServer = davServer;
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/basic/BasicDavServerRequest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/basic/BasicDavServerRequest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/basic/BasicDavServerRequest.java (working copy)
@@ -1,67 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.servlet.basic;
-
-import org.apache.maven.archiva.webdav.servlet.DavServerRequest;
-import org.apache.maven.archiva.webdav.util.WrappedRepositoryRequest;
-
-/**
- * BasicDavServerRequest - for requests that have a prefix based off of the servlet path id.
- *
- * @author Joakim Erdfelt
- * @version $Id: BasicDavServerRequest.java 7073 2007-11-22 04:04:50Z brett $
- */
-public class BasicDavServerRequest
- implements DavServerRequest
-{
- private WrappedRepositoryRequest request;
-
- private String prefix;
-
- private String logicalResource;
-
- public BasicDavServerRequest( WrappedRepositoryRequest request )
- {
- this.request = request;
- this.prefix = request.getServletPath();
- this.logicalResource = request.getPathInfo();
- }
-
- public void setLogicalResource( String logicalResource )
- {
- this.logicalResource = logicalResource;
- this.request.setPathInfo( logicalResource );
- }
-
- public String getLogicalResource()
- {
- return this.logicalResource;
- }
-
- public String getPrefix()
- {
- return this.prefix;
- }
-
- public WrappedRepositoryRequest getRequest()
- {
- return request;
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/DavServerRequest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/DavServerRequest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/DavServerRequest.java (working copy)
@@ -1,39 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.servlet;
-
-import org.apache.maven.archiva.webdav.util.WrappedRepositoryRequest;
-
-/**
- * DavServerRequest
- *
- * @author Joakim Erdfelt
- * @version $Id: DavServerRequest.java 7073 2007-11-22 04:04:50Z brett $
- */
-public interface DavServerRequest
-{
- public String getPrefix();
-
- public String getLogicalResource();
-
- public void setLogicalResource( String logicalResource );
-
- public WrappedRepositoryRequest getRequest();
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedDavServerRequest.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedDavServerRequest.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedDavServerRequest.java (working copy)
@@ -1,123 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.servlet.multiplexed;
-
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.webdav.servlet.DavServerRequest;
-import org.apache.maven.archiva.webdav.util.WrappedRepositoryRequest;
-
-/**
- *
- * MultiplexedDavServerRequest - For requests that contain the server prefix information within the requested
- * servlet's pathInfo parameter (as the first path entry).
- *
- *
- *
- * You would use this dav server request object when you are working with a single servlet that is handling
- * multiple dav server components.
- *
- *
- * @author Joakim Erdfelt
- * @version $Id: MultiplexedDavServerRequest.java 7073 2007-11-22 04:04:50Z brett $
- */
-public class MultiplexedDavServerRequest
- implements DavServerRequest
-{
- private WrappedRepositoryRequest request;
-
- private String prefix;
-
- private String logicalResource;
-
- public MultiplexedDavServerRequest( WrappedRepositoryRequest request )
- {
- String requestPathInfo = StringUtils.defaultString( request.getPathInfo() );
-
- // Remove prefixing slash as the repository id doesn't contain it;
- if ( requestPathInfo.startsWith( "/" ) )
- {
- requestPathInfo = requestPathInfo.substring( 1 );
- }
-
- // Find first element, if slash exists.
- int slash = requestPathInfo.indexOf( '/' );
- if ( slash > 0 )
- {
- // Filtered: "central/org/apache/maven/" -> "central"
- this.prefix = requestPathInfo.substring( 0, slash );
-
- this.logicalResource = requestPathInfo.substring( slash );
-
- if ( this.logicalResource.endsWith( "/.." ) )
- {
- this.logicalResource += "/";
- }
-
- /* Perform a simple security normalization of the requested pathinfo.
- * This is to prevent requests for information outside of the root directory.
- */
- this.logicalResource = FilenameUtils.normalize( logicalResource );
-
- if ( logicalResource != null )
- {
- logicalResource = logicalResource.replace( '\\', '/' );
-
- if ( logicalResource.startsWith( "//" ) )
- {
- logicalResource = logicalResource.substring( 1 );
- }
- }
- else
- {
- this.logicalResource = "/";
- }
- }
- else
- {
- this.prefix = requestPathInfo;
- this.logicalResource = "/";
- }
-
- this.request = request;
- this.request.setPathInfo( logicalResource );
- }
-
- public void setLogicalResource( String logicalResource )
- {
- this.logicalResource = logicalResource;
- this.request.setPathInfo( logicalResource );
- }
-
- public String getLogicalResource()
- {
- return this.logicalResource;
- }
-
- public String getPrefix()
- {
- return this.prefix;
- }
-
- public WrappedRepositoryRequest getRequest()
- {
- return request;
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedWebDavServlet.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedWebDavServlet.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/servlet/multiplexed/MultiplexedWebDavServlet.java (working copy)
@@ -1,137 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.servlet.multiplexed;
-
-import org.apache.maven.archiva.webdav.DavServerComponent;
-import org.apache.maven.archiva.webdav.DavServerException;
-import org.apache.maven.archiva.webdav.DavServerManager;
-import org.apache.maven.archiva.webdav.servlet.AbstractWebDavServlet;
-import org.apache.maven.archiva.webdav.servlet.DavServerRequest;
-import org.apache.maven.archiva.webdav.util.WrappedRepositoryRequest;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.util.Iterator;
-
-/**
- *
- * MultiplexedWebDavServlet - and abstracted multiplexed webdav servlet.
- *
- *
- *
- * Implementations of this servlet should override the {@link #initServers} method and create all of the
- * appropriate DavServerComponents needed using the {@link DavServerManager} obtained via the {@link #getDavManager()}
- * method.
- *
- *
- * @author Joakim Erdfelt
- * @version $Id: MultiplexedWebDavServlet.java 6000 2007-03-04 22:01:49Z joakime $
- */
-public abstract class MultiplexedWebDavServlet
- extends AbstractWebDavServlet
-{
- private boolean useIndexHtml = false;
-
- public void init( ServletConfig config )
- throws ServletException
- {
- super.init( config );
-
- this.useIndexHtml = getUseIndexHtml( config );
-
- try
- {
- initServers( config );
- }
- catch ( DavServerException e )
- {
- throw new ServletException( e );
- }
- }
-
- /**
- * Create any DavServerComponents here.
- * Use the {@link #createServer(String, File, ServletConfig)} method to create your servers.
- *
- * @param config the config to use.
- * @throws DavServerException if there was a problem initializing the server components.
- */
- public abstract void initServers( ServletConfig config )
- throws DavServerException;
-
- public DavServerComponent createServer( String prefix, File rootDirectory, ServletConfig config )
- throws DavServerException
- {
- DavServerComponent serverComponent = davManager.createServer( prefix, rootDirectory );
- serverComponent.setUseIndexHtml( useIndexHtml );
- serverComponent.init( config );
- return serverComponent;
- }
-
- protected void service( HttpServletRequest httpRequest, HttpServletResponse httpResponse )
- throws ServletException, IOException
- {
- DavServerRequest davRequest = new MultiplexedDavServerRequest( new WrappedRepositoryRequest( httpRequest ) );
-
- DavServerComponent davServer = davManager.getServer( davRequest.getPrefix() );
-
- if ( davServer == null )
- {
- String errorMessage = "[" + davRequest.getPrefix() + "] Not Found (Likely Unconfigured).";
- httpResponse.sendError( HttpURLConnection.HTTP_NOT_FOUND, errorMessage );
- return;
- }
-
- requestDebug( httpRequest );
-
- if ( !isAuthenticated( davRequest, httpResponse ) )
- {
- return;
- }
-
- if ( !isAuthorized( davRequest, httpResponse ) )
- {
- return;
- }
-
- try
- {
- davServer.process( davRequest, httpResponse );
- }
- catch ( DavServerException e )
- {
- throw new ServletException( "Unable to process request.", e );
- }
- }
-
- public void setUseIndexHtml( boolean useIndexHtml )
- {
- for ( Iterator it = davManager.getServers().iterator(); it.hasNext(); )
- {
- DavServerComponent davServer = (DavServerComponent) it.next();
- davServer.setUseIndexHtml( useIndexHtml );
- }
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerListener.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerListener.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerListener.java (working copy)
@@ -1,39 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav;
-
-/**
- * DavServerListener
- *
- * @author Joakim Erdfelt
- * @version $Id: DavServerListener.java 5379 2007-01-07 22:54:41Z joakime $
- */
-public interface DavServerListener
-{
- public void serverCollectionCreated( DavServerComponent server, String resource );
-
- public void serverCollectionRemoved( DavServerComponent server, String resource );
-
- public void serverResourceCreated( DavServerComponent server, String resource );
-
- public void serverResourceRemoved( DavServerComponent server, String resource );
-
- public void serverResourceModified( DavServerComponent server, String resource );
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/AbstractDavServerComponent.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/AbstractDavServerComponent.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/AbstractDavServerComponent.java (working copy)
@@ -1,159 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * AbstractDavServerComponent
- *
- * @author Joakim Erdfelt
- * @version $Id: AbstractDavServerComponent.java 6000 2007-03-04 22:01:49Z joakime $
- */
-public abstract class AbstractDavServerComponent
- implements DavServerComponent
-{
- private List listeners;
- protected boolean useIndexHtml = false;
-
- public AbstractDavServerComponent()
- {
- listeners = new ArrayList();
- }
-
- public void addListener( DavServerListener listener )
- {
- listeners.add( listener );
- }
-
- public void removeListener( DavServerListener listener )
- {
- listeners.remove( listener );
- }
-
- protected void triggerCollectionCreated( String resource )
- {
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
- {
- DavServerListener listener = (DavServerListener) it.next();
- try
- {
- listener.serverCollectionCreated( this, resource );
- }
- catch ( Exception e )
- {
- /* ignore error */
- }
- }
- }
-
- protected void triggerCollectionRemoved( String resource )
- {
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
- {
- DavServerListener listener = (DavServerListener) it.next();
- try
- {
- listener.serverCollectionRemoved( this, resource );
- }
- catch ( Exception e )
- {
- /* ignore error */
- }
- }
- }
-
- protected void triggerResourceCreated( String resource )
- {
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
- {
- DavServerListener listener = (DavServerListener) it.next();
- try
- {
- listener.serverResourceCreated( this, resource );
- }
- catch ( Exception e )
- {
- /* ignore error */
- }
- }
- }
-
- protected void triggerResourceRemoved( String resource )
- {
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
- {
- DavServerListener listener = (DavServerListener) it.next();
- try
- {
- listener.serverResourceRemoved( this, resource );
- }
- catch ( Exception e )
- {
- /* ignore error */
- }
- }
- }
-
- protected void triggerResourceModified( String resource )
- {
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
- {
- DavServerListener listener = (DavServerListener) it.next();
- try
- {
- listener.serverResourceModified( this, resource );
- }
- catch ( Exception e )
- {
- /* ignore error */
- }
- }
- }
-
- public boolean hasResource( String resource )
- {
- File rootDir = getRootDirectory();
- if ( rootDir == null )
- {
- return false;
- }
- File resourceFile = new File( rootDir, resource );
- return resourceFile.exists();
- }
-
- public boolean isUseIndexHtml()
- {
- return this.useIndexHtml;
- }
-
- public void setUseIndexHtml( boolean useIndexHtml )
- {
- this.useIndexHtml = useIndexHtml;
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java (revision 0)
@@ -0,0 +1,477 @@
+package org.apache.maven.archiva.webdav;
+
+import org.apache.jackrabbit.webdav.*;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.RepositoryNotFoundException;
+import org.apache.maven.archiva.repository.RepositoryException;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+import org.apache.maven.archiva.repository.content.RepositoryRequest;
+import org.apache.maven.archiva.repository.audit.AuditListener;
+import org.apache.maven.archiva.repository.audit.Auditable;
+import org.apache.maven.archiva.repository.audit.AuditEvent;
+import org.apache.maven.archiva.repository.metadata.MetadataTools;
+import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
+import org.apache.maven.archiva.webdav.util.WebdavMethodUtil;
+import org.apache.maven.archiva.webdav.util.MimeTypes;
+import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
+import org.apache.maven.archiva.proxy.RepositoryProxyConnectors;
+import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.ProjectReference;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.policies.ProxyDownloadException;
+import org.apache.maven.archiva.security.ArchivaXworkUser;
+import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Relocation;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.util.ArrayList;
+import java.util.List;
+import java.io.*;
+
+/**
+ * @author James William Dumay
+ * @plexus.component role="org.apache.maven.archiva.webdav.ArchivaDavResourceFactory"
+ */
+public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable
+{
+ private Logger log = LoggerFactory.getLogger(ArchivaDavResourceFactory.class);
+
+ /**
+ * @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener"
+ */
+ private List auditListeners = new ArrayList();
+
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryContentFactory repositoryFactory;
+
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryRequest repositoryRequest;
+
+ /**
+ * @plexus.requirement role-hint="default"
+ */
+ private RepositoryProxyConnectors connectors;
+
+ /**
+ * @plexus.requirement
+ */
+ private MetadataTools metadataTools;
+
+ /**
+ * @plexus.requirement
+ */
+ private MimeTypes mimeTypes;
+
+ public DavResource createResource(final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response) throws DavException
+ {
+ final ManagedRepositoryContent managedRepository = getManagedRepository(locator.getWorkspaceName());
+ final LogicalResource logicalResource = new LogicalResource(RepositoryPathUtil.getLogicalResource(locator.getResourcePath()));
+
+ DavResource resource = null;
+
+ if (managedRepository != null)
+ {
+ final boolean isGet = WebdavMethodUtil.isReadMethod( request.getMethod() );
+ final boolean isPut = WebdavMethodUtil.isWriteMethod( request.getMethod() );
+
+ if (isGet)
+ {
+ resource = doGet(managedRepository, request, locator, logicalResource);
+ }
+
+ if (isPut)
+ {
+ resource = doPut(managedRepository, request, locator, logicalResource);
+ }
+ }
+ else
+ {
+ throw new DavException(HttpServletResponse.SC_NOT_FOUND, "Repository does not exist");
+ }
+
+ if (resource != null)
+ {
+ setHeaders(locator, response);
+ return resource;
+ }
+
+ throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get resource for method " + request.getMethod());
+ }
+
+ public DavResource createResource(final DavResourceLocator locator, final DavSession davSession) throws DavException
+ {
+ final ManagedRepositoryContent managedRepository = getManagedRepository(locator.getWorkspaceName());
+ final String logicalResource = RepositoryPathUtil.getLogicalResource(locator.getResourcePath());
+ final File resourceFile = new File ( managedRepository.getRepoRoot(), logicalResource);
+
+ return new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource, mimeTypes, locator, this, null);
+ }
+
+ private DavResource doGet(ManagedRepositoryContent managedRepository, DavServletRequest request, DavResourceLocator locator, LogicalResource logicalResource) throws DavException
+ {
+ File resourceFile = new File ( managedRepository.getRepoRoot(), logicalResource.getPath());
+ ArchivaDavResource resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this, null);
+
+ if ( !resource.isCollection() )
+ {
+ // At this point the incoming request can either be in default or
+ // legacy layout format.
+ try
+ {
+ boolean fromProxy = fetchContentFromProxies(managedRepository, request, logicalResource );
+
+ // Perform an adjustment of the resource to the managed
+ // repository expected path.
+ String localResourcePath = repositoryRequest.toNativePath( logicalResource.getPath(), managedRepository );
+ resourceFile = new File( managedRepository.getRepoRoot(), localResourcePath );
+
+ boolean previouslyExisted = resourceFile.exists();
+
+ // Attempt to fetch the resource from any defined proxy.
+ if ( fromProxy )
+ {
+ processAuditEvents(request, locator.getWorkspaceName(), logicalResource.getPath(), previouslyExisted, resourceFile, " (proxied)");
+ }
+ resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this, null);
+
+ }
+ catch ( LayoutException e )
+ {
+ throw new DavException(HttpServletResponse.SC_NOT_FOUND, e);
+ }
+ }
+ return resource;
+ }
+
+ private DavResource doPut(ManagedRepositoryContent managedRepository, DavServletRequest request, DavResourceLocator locator, LogicalResource logicalResource) throws DavException
+ {
+ /*
+ * Create parent directories that don't exist when writing a file
+ * This actually makes this implementation not compliant to the
+ * WebDAV RFC - but we have enough knowledge about how the
+ * collection is being used to do this reasonably and some versions
+ * of Maven's WebDAV don't correctly create the collections
+ * themselves.
+ */
+
+ File rootDirectory = new File(managedRepository.getRepoRoot());
+ File destDir = new File( rootDirectory, logicalResource.getPath() ).getParentFile();
+ if ( !destDir.exists() )
+ {
+ destDir.mkdirs();
+ String relPath =
+ PathUtil.getRelative( rootDirectory.getAbsolutePath(), destDir );
+ triggerAuditEvent(request, logicalResource.getPath(), relPath, AuditEvent.CREATE_DIR );
+ }
+
+ File resourceFile = new File( managedRepository.getRepoRoot(), logicalResource.getPath() );
+
+ boolean previouslyExisted = resourceFile.exists();
+
+ processAuditEvents(request, locator.getWorkspaceName(), logicalResource.getPath(), previouslyExisted, resourceFile, null );
+
+ return new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this, null);
+ }
+
+ private boolean fetchContentFromProxies( ManagedRepositoryContent managedRepository, DavServletRequest request, LogicalResource resource )
+ throws DavException
+ {
+ if ( repositoryRequest.isSupportFile( resource.getPath() ) )
+ {
+ // Checksums are fetched with artifact / metadata.
+
+ // Need to adjust the path for the checksum resource.
+ return false;
+ }
+
+ // Is it a Metadata resource?
+ if ( repositoryRequest.isDefault( resource.getPath() ) && repositoryRequest.isMetadata( resource.getPath() ) )
+ {
+ return fetchMetadataFromProxies(managedRepository, request, resource );
+ }
+
+ // Not any of the above? Then it's gotta be an artifact reference.
+ try
+ {
+ // Get the artifact reference in a layout neutral way.
+ ArtifactReference artifact = repositoryRequest.toArtifactReference( resource.getPath() );
+
+ if ( artifact != null )
+ {
+ applyServerSideRelocation(managedRepository, artifact );
+
+ File proxiedFile = connectors.fetchFromProxies( managedRepository, artifact );
+
+ resource.setPath( managedRepository.toPath( artifact ) );
+
+ return ( proxiedFile != null );
+ }
+ }
+ catch ( LayoutException e )
+ {
+ /* eat it */
+ }
+ catch ( ProxyDownloadException e )
+ {
+ log.error(e.getMessage(), e);
+ throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to fetch artifact resource.");
+ }
+ return false;
+ }
+
+ private boolean fetchMetadataFromProxies(ManagedRepositoryContent managedRepository, DavServletRequest request, LogicalResource resource )
+ throws DavException
+ {
+ ProjectReference project;
+ VersionedReference versioned;
+
+ try
+ {
+
+ versioned = metadataTools.toVersionedReference( resource.getPath() );
+ if ( versioned != null )
+ {
+ connectors.fetchFromProxies( managedRepository, versioned );
+ return true;
+ }
+ }
+ catch ( RepositoryMetadataException e )
+ {
+ log.error(e.getMessage(), e);
+ }
+
+ try
+ {
+ project = metadataTools.toProjectReference( resource.getPath() );
+ if ( project != null )
+ {
+ connectors.fetchFromProxies( managedRepository, project );
+ return true;
+ }
+ }
+ catch ( RepositoryMetadataException e )
+ {
+ log.error(e.getMessage(), e);
+ }
+
+ return false;
+ }
+
+ /**
+ * A relocation capable client will request the POM prior to the artifact,
+ * and will then read meta-data and do client side relocation. A simplier
+ * client (like maven 1) will only request the artifact and not use the
+ * metadatas.
+ *
+ * For such clients, archiva does server-side relocation by reading itself
+ * the <relocation> element in metadatas and serving the expected
+ * artifact.
+ */
+ protected void applyServerSideRelocation( ManagedRepositoryContent managedRepository, ArtifactReference artifact )
+ throws ProxyDownloadException
+ {
+ if ( "pom".equals( artifact.getType() ) )
+ {
+ return;
+ }
+
+ // Build the artifact POM reference
+ ArtifactReference pomReference = new ArtifactReference();
+ pomReference.setGroupId( artifact.getGroupId() );
+ pomReference.setArtifactId( artifact.getArtifactId() );
+ pomReference.setVersion( artifact.getVersion() );
+ pomReference.setType( "pom" );
+
+ // Get the artifact POM from proxied repositories if needed
+ connectors.fetchFromProxies( managedRepository, pomReference );
+
+ // Open and read the POM from the managed repo
+ File pom = managedRepository.toFile( pomReference );
+
+ if ( !pom.exists() )
+ {
+ return;
+ }
+
+ try
+ {
+ Model model = new MavenXpp3Reader().read( new FileReader( pom ) );
+ DistributionManagement dist = model.getDistributionManagement();
+ if ( dist != null )
+ {
+ Relocation relocation = dist.getRelocation();
+ if ( relocation != null )
+ {
+ // artifact is relocated : update the repositoryPath
+ if ( relocation.getGroupId() != null )
+ {
+ artifact.setGroupId( relocation.getGroupId() );
+ }
+ if ( relocation.getArtifactId() != null )
+ {
+ artifact.setArtifactId( relocation.getArtifactId() );
+ }
+ if ( relocation.getVersion() != null )
+ {
+ artifact.setVersion( relocation.getVersion() );
+ }
+ }
+ }
+ }
+ catch ( FileNotFoundException e )
+ {
+ // Artifact has no POM in repo : ignore
+ }
+ catch ( IOException e )
+ {
+ // Unable to read POM : ignore.
+ }
+ catch ( XmlPullParserException e )
+ {
+ // Invalid POM : ignore
+ }
+ }
+
+ private void processAuditEvents( DavServletRequest request, String repositoryId, String resource,
+ boolean previouslyExisted, File resourceFile, String suffix )
+ {
+ if ( suffix == null )
+ {
+ suffix = "";
+ }
+
+ // Process Create Audit Events.
+ if ( !previouslyExisted && resourceFile.exists() )
+ {
+ if ( resourceFile.isFile() )
+ {
+ triggerAuditEvent( request, repositoryId, resource, AuditEvent.CREATE_FILE + suffix );
+ }
+ else if ( resourceFile.isDirectory() )
+ {
+ triggerAuditEvent( request, repositoryId, resource, AuditEvent.CREATE_DIR + suffix );
+ }
+ }
+ // Process Remove Audit Events.
+ else if ( previouslyExisted && !resourceFile.exists() )
+ {
+ if ( resourceFile.isFile() )
+ {
+ triggerAuditEvent( request, repositoryId, resource, AuditEvent.REMOVE_FILE + suffix );
+ }
+ else if ( resourceFile.isDirectory() )
+ {
+ triggerAuditEvent( request, repositoryId, resource, AuditEvent.REMOVE_DIR + suffix );
+ }
+ }
+ // Process modify events.
+ else
+ {
+ if ( resourceFile.isFile() )
+ {
+ triggerAuditEvent( request, repositoryId, resource, AuditEvent.MODIFY_FILE + suffix );
+ }
+ }
+ }
+
+ private void triggerAuditEvent( String user, String remoteIP, String repositoryId, String resource, String action )
+ {
+ AuditEvent event = new AuditEvent( repositoryId, user, resource, action );
+ event.setRemoteIP( remoteIP );
+
+ for ( AuditListener listener : auditListeners )
+ {
+ listener.auditEvent( event );
+ }
+ }
+
+ private void triggerAuditEvent( DavServletRequest request, String repositoryId, String resource, String action )
+ {
+ triggerAuditEvent( ArchivaXworkUser.getActivePrincipal(), getRemoteIP( request ), repositoryId, resource, action );
+ }
+
+ private String getRemoteIP( DavServletRequest request )
+ {
+ return request.getRemoteAddr();
+ }
+
+ public void addAuditListener( AuditListener listener )
+ {
+ this.auditListeners.add( listener );
+ }
+
+ public void clearAuditListeners()
+ {
+ this.auditListeners.clear();
+ }
+
+ public void removeAuditListener( AuditListener listener )
+ {
+ this.auditListeners.remove( listener );
+ }
+
+ private void setHeaders(DavResourceLocator locator, DavServletResponse response)
+ {
+ // [MRM-503] - Metadata file need Pragma:no-cache response
+ // header.
+ if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" ) )
+ {
+ response.addHeader( "Pragma", "no-cache" );
+ response.addHeader( "Cache-Control", "no-cache" );
+ }
+
+ // TODO: [MRM-524] determine http caching options for other types of files (artifacts, sha1, md5, snapshots)
+ }
+
+ private ManagedRepositoryContent getManagedRepository(String respositoryId) throws DavException
+ {
+ if (respositoryId != null)
+ {
+ try
+ {
+ return repositoryFactory.getManagedRepositoryContent(respositoryId);
+ }
+ catch (RepositoryNotFoundException e)
+ {
+ throw new DavException(HttpServletResponse.SC_NOT_FOUND, e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new DavException(HttpServletResponse.SC_NOT_FOUND, e);
+ }
+ }
+ return null;
+ }
+
+ class LogicalResource
+ {
+ private String path;
+
+ public LogicalResource(String path)
+ {
+ this.path = path;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public void setPath(String path)
+ {
+ this.path = path;
+ }
+ }
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/ReplacementGetMethod.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/ReplacementGetMethod.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/ReplacementGetMethod.java (working copy)
@@ -1,303 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.simple;
-
-import it.could.util.StreamTools;
-import it.could.webdav.DAVException;
-import it.could.webdav.DAVInputStream;
-import it.could.webdav.DAVMethod;
-import it.could.webdav.DAVNotModified;
-import it.could.webdav.DAVResource;
-import it.could.webdav.DAVTransaction;
-import it.could.webdav.DAVUtilities;
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.webdav.util.MimeTypes;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.TreeSet;
-
-/**
- * ReplacementGetMethod
- *
- * @author Pier Fumagalli (Original it.could.webdav 0.4 version)
- * @author Joakim Erdfelt (Replacement Version)
- * @version $Id: ReplacementGetMethod.java 7002 2007-10-23 22:40:37Z joakime $
- *
- * @plexus.component
- * role="it.could.webdav.DAVMethod"
- * role-hint="get-with-indexing"
- */
-public class ReplacementGetMethod implements DAVMethod
-{
- /**
The encoding charset to repsesent collections.
*/
- public static final String ENCODING = "UTF-8";
-
- /** The mime type that {@link ReplacementGetMethod} will use serving index.html files.
*/
- public static final String HTML_MIME_TYPE = "text/html";
-
- /** The mime type that {@link ReplacementGetMethod} will use serving collections.
*/
- public static final String COLLECTION_MIME_TYPE = HTML_MIME_TYPE + "; charset=\"" + ENCODING + "\"";
-
- /** The header for content disposition.
*/
- public static final String CONTENT_DISPOSITION = "Content-Disposition";
-
- /** The content-disposition for fancy-indexing.
*/
- public static final String INLINE_INDEX_HTML = "inline; filename=\"index.html\"";
-
- /**
- * @plexus.requirement
- */
- private MimeTypes mimeTypes;
-
- private boolean useIndexHtml = false;
-
- /**
- * Create a new {@link ReplacementGetMethod} instance.
- */
- public ReplacementGetMethod()
- {
- super();
- }
-
- /**
- * Process the GET method.
- */
- public void process( DAVTransaction transaction, DAVResource resource ) throws IOException
- {
- // Handle boilerplate
- if ( resource.isNull() )
- throw new DAVException( 404, "Not found", resource );
-
- notModified( transaction, resource );
-
- copyHeaders( transaction, resource );
-
- // Process the request.
- final String originalPath = transaction.getOriginalPath();
- final String normalizedPath = transaction.getNormalizedPath();
- final String current;
- final String parent;
-
- if ( originalPath.equals( normalizedPath ) )
- {
- final String relativePath = resource.getRelativePath();
- if ( relativePath.equals( "" ) )
- {
- current = transaction.lookup( resource ).toASCIIString();
- }
- else
- {
- current = relativePath;
- }
- parent = "./";
- }
- else
- {
- current = "./";
- parent = "../";
- }
-
- if ( resource.isCollection() )
- {
- DAVResource indexHtml = null;
-
- if ( useIndexHtml )
- {
- for ( Iterator it = resource.getChildren(); it.hasNext(); )
- {
- DAVResource child = (DAVResource) it.next();
- String name = child.getDisplayName().toLowerCase();
- if ( StringUtils.equals( "index.html", name ) || StringUtils.equals( "index.htm", name ) )
- {
- indexHtml = child;
- break;
- }
- }
- }
-
- if ( useIndexHtml && indexHtml != null )
- {
- transaction.setContentType( COLLECTION_MIME_TYPE );
- transaction.setHeader( CONTENT_DISPOSITION, INLINE_INDEX_HTML );
- sendResource( transaction, indexHtml );
- }
- else
- {
- transaction.setContentType( COLLECTION_MIME_TYPE );
- transaction.setHeader( CONTENT_DISPOSITION, INLINE_INDEX_HTML );
- sendFancyIndex( transaction, resource, current, parent );
- }
- }
- else
- {
- /* Processing a normal resource request */
- transaction.setContentType( mimeTypes.getMimeType( resource.getDisplayName() ) );
- transaction.setHeader( CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getDisplayName() + "\"" );
- sendResource( transaction, resource );
- }
- }
-
- private void copyHeaders( DAVTransaction transaction, DAVResource resource )
- {
- /* Get the headers of this method */
- String ctyp = resource.getContentType();
- String etag = resource.getEntityTag();
- String lmod = DAVUtilities.formatHttpDate( resource.getLastModified() );
- String clen = DAVUtilities.formatNumber( resource.getContentLength() );
-
- /* Set the normal headers that are required for a GET */
- if ( ctyp != null )
- {
- transaction.setContentType( ctyp );
- }
-
- if ( etag != null )
- {
- transaction.setHeader( "ETag", etag );
- }
-
- if ( lmod != null )
- {
- transaction.setHeader( "Last-Modified", lmod );
- }
-
- if ( clen != null )
- {
- transaction.setHeader( "Content-Length", clen );
- }
- }
-
- private void sendResource( DAVTransaction transaction, DAVResource resource ) throws IOException
- {
- OutputStream out = null;
- DAVInputStream in = null;
-
- try
- {
- out = transaction.write();
- in = resource.read();
-
- byte buffer[] = new byte[4096 * 16];
- int k = -1;
- while ( ( k = in.read( buffer ) ) != -1 )
- {
- out.write( buffer, 0, k );
- }
-
- out.flush();
- }
- finally
- {
- StreamTools.close( in );
- StreamTools.close( out );
- }
- }
-
- private void sendFancyIndex( DAVTransaction transaction, DAVResource resource, final String current,
- final String parent ) throws IOException
- {
- PrintWriter out = transaction.write( ENCODING );
- String path = resource.getRelativePath();
- out.println( "" );
- out.println( "" );
- out.println( "Collection: /" + path + "" );
- out.println( "" );
- out.println( "" );
- out.println( "Collection: /" + path + "
" );
- out.println( "" );
- out.println( "" );
- }
-
- /* Process the children (in two sorted sets, for nice ordering) */
- Set resources = new TreeSet();
- Set collections = new TreeSet();
- Iterator iterator = resource.getChildren();
- while ( iterator.hasNext() )
- {
- final DAVResource child = (DAVResource) iterator.next();
- final StringBuffer buffer = new StringBuffer();
- final String childPath = child.getDisplayName();
- buffer.append( "- " );
- buffer.append( childPath );
- buffer.append( "
" );
- if ( child.isCollection() )
- {
- collections.add( buffer.toString() );
- }
- else
- {
- resources.add( buffer.toString() );
- }
- }
-
- /* Spit out the collections first and the resources then */
- for ( Iterator i = collections.iterator(); i.hasNext(); )
- out.println( i.next() );
- for ( Iterator i = resources.iterator(); i.hasNext(); )
- out.println( i.next() );
-
- out.println( "
" );
- out.println( "" );
- out.println( "" );
- out.flush();
- }
-
- private void notModified( DAVTransaction transaction, DAVResource resource )
- {
- Date ifmod = transaction.getIfModifiedSince();
- Date lsmod = resource.getLastModified();
- if ( resource.isResource() && ( ifmod != null ) && ( lsmod != null ) )
- {
- /* HTTP doesn't send milliseconds, but Java does, so, reset them */
- lsmod = new Date( ( (long) ( lsmod.getTime() / 1000 ) ) * 1000 );
- if ( !ifmod.before( lsmod ) )
- throw new DAVNotModified( resource );
- }
- }
-
- public boolean isUseIndexHtml()
- {
- return useIndexHtml;
- }
-
- public void setUseIndexHtml( boolean useIndexHtml )
- {
- this.useIndexHtml = useIndexHtml;
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/HackedMoveMethod.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/HackedMoveMethod.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/HackedMoveMethod.java (working copy)
@@ -1,130 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.simple;
-
-import it.could.webdav.DAVException;
-import it.could.webdav.DAVMethod;
-import it.could.webdav.DAVMultiStatus;
-import it.could.webdav.DAVResource;
-import it.could.webdav.DAVTransaction;
-
-import java.io.IOException;
-import java.net.URI;
-
-/**
- * HackedMoveMethod - Created to address the needs for inter-repository moves.
- *
- * @author Pier Fumagalli (Original it.could.webdav 0.4 version)
- * @author Joakim Erdfelt (Hacked Version)
- * @version $Id: HackedMoveMethod.java 6000 2007-03-04 22:01:49Z joakime $
- */
-public class HackedMoveMethod
- implements DAVMethod
-{
-
- public HackedMoveMethod()
- {
- super();
- }
-
- /**
- * Process the MOVE method.
- */
- public void process( DAVTransaction transaction, DAVResource resource )
- throws IOException
- {
- URI target = transaction.getDestination();
- if ( target == null )
- throw new DAVException( 412, "No destination" );
-
- if ( target.getScheme() == null )
- {
- // This is a relative file system destination target.
- DAVResource dest = resource.getRepository().getResource( target );
- moveWithinRepository( transaction, resource, dest );
- }
- else
- {
- // This is a inter-repository move request.
- URI dest = target;
- moveInterRepository( transaction, resource, dest );
- }
- }
-
- private void moveInterRepository( DAVTransaction transaction, DAVResource resource, URI dest )
- throws DAVException
- {
- /* TODO: Figure out how to handle a Repository to Repository MOVE of content, and still maintain
- * the security credentials from the original request. (Need to support NTLM, Digest, BASIC)
- *
- * IDEA: Could support non-secured Webdav Destination using slide client libraries.
- */
- transaction.setStatus( 501 );
- throw new DAVException( 501, "Server side MOVE to external WebDAV instance not supported." );
- }
-
- private void moveWithinRepository( DAVTransaction transaction, DAVResource resource, DAVResource dest )
- throws IOException
- {
- int depth = transaction.getDepth();
- boolean recursive = false;
- if ( depth == 0 )
- {
- recursive = false;
- }
- else if ( depth == DAVTransaction.INFINITY )
- {
- recursive = true;
- }
- else
- {
- throw new DAVException( 412, "Invalid Depth specified" );
- }
-
- try
- {
- int status;
- if ( !dest.isNull() && !transaction.getOverwrite() )
- {
- status = 412; // MOVE-on-existing should fail with 412
- }
- else
- {
- resource.copy( dest, transaction.getOverwrite(), recursive );
- resource.delete();
-
- if ( transaction.getOverwrite() )
- {
- status = 204; // No Content
- }
- else
- {
- status = 201; // Created
- }
- }
- transaction.setStatus( status );
- }
- catch ( DAVMultiStatus multistatus )
- {
- multistatus.write( transaction );
- }
- }
-
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponent.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponent.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/simple/SimpleDavServerComponent.java (working copy)
@@ -1,185 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav.simple;
-
-import it.could.webdav.DAVListener;
-import it.could.webdav.DAVProcessor;
-import it.could.webdav.DAVRepository;
-import it.could.webdav.DAVResource;
-import it.could.webdav.DAVTransaction;
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.webdav.AbstractDavServerComponent;
-import org.apache.maven.archiva.webdav.DavServerException;
-import org.apache.maven.archiva.webdav.servlet.DavServerRequest;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-
-/**
- * SimpleDavServerComponent
- *
- * @author Joakim Erdfelt
- * @version $Id: SimpleDavServerComponent.java 7097 2007-11-30 12:57:29Z handyande $
- *
- * @plexus.component role="org.apache.maven.archiva.webdav.DavServerComponent"
- * role-hint="simple"
- * instantiation-strategy="per-lookup"
- */
-public class SimpleDavServerComponent
- extends AbstractDavServerComponent
- implements DAVListener
-{
- /**
- * @plexus.requirement
- * role="it.could.webdav.DAVMethod"
- * role-hint="get-with-indexing"
- */
- public ReplacementGetMethod methodGet;
-
- private String prefix;
-
- private File rootDirectory;
-
- private DAVRepository davRepository;
-
- private DAVProcessor davProcessor;
-
- public String getPrefix()
- {
- return prefix;
- }
-
- public File getRootDirectory()
- {
- return rootDirectory;
- }
-
- public void setPrefix( String prefix )
- {
- this.prefix = prefix;
- }
-
- public void setRootDirectory( File rootDirectory )
- {
- this.rootDirectory = rootDirectory;
- }
-
- public void init( ServletConfig servletConfig )
- throws DavServerException
- {
- servletConfig.getServletContext().log( "Initializing " + this.getClass().getName() );
- try
- {
- davRepository = new DAVRepository( rootDirectory );
- davProcessor = new DAVProcessor( davRepository );
- davRepository.addListener( this );
-
- hackDavProcessor( davProcessor );
- }
- catch ( IOException e )
- {
- throw new DavServerException( "Unable to initialize DAVRepository.", e );
- }
- }
-
- /**
- * Replace the problematic dav methods with local hacked versions.
- *
- * @param davProcessor
- * @throws DavServerException
- */
- private void hackDavProcessor( DAVProcessor davProcessor )
- throws DavServerException
- {
- davProcessor.setMethod( "MOVE", new HackedMoveMethod() );
- davProcessor.setMethod( "GET", methodGet );
-
- /* Reflection based technique.
- try
- {
- Field fldInstance = davProcessor.getClass().getDeclaredField( "INSTANCES" );
- fldInstance.setAccessible( true );
-
- Map mapInstances = (Map) fldInstance.get( davProcessor );
-
- // Replace MOVE method.
- // TODO: Remove MOVE method when upgrading it.could.webdav to v0.5
- mapInstances.put( "MOVE", (DAVMethod) new HackedMoveMethod() );
-
- // Replace GET method.
- mapInstances.put( "GET", (DAVMethod) methodGet );
- }
- catch ( Throwable e )
- {
- throw new DavServerException( "Unable to twiddle DAVProcessor.INSTANCES field.", e );
- }
- */
- }
-
- public void process( DavServerRequest request, HttpServletResponse response )
- throws ServletException, IOException
- {
- DAVTransaction transaction = new DAVTransaction( request.getRequest(), response );
-
- /* BEGIN - it.could.webdav hacks
- * TODO: Remove hacks with release of it.could.webdav 0.5 (or newer)
- */
- String depthValue = request.getRequest().getHeader( "Depth" );
- if ( StringUtils.equalsIgnoreCase( "infinity", depthValue ) )
- {
- // See - http://could.it/bugs/browse/DAV-3
- request.getRequest().setHeader( "Depth", "infinity" );
- }
- /* END - it.could.webdav hacks */
-
- davProcessor.process( transaction );
- }
-
- public void notify( DAVResource resource, int event )
- {
- switch ( event )
- {
- case DAVListener.COLLECTION_CREATED:
- triggerCollectionCreated( resource.getRelativePath() );
- break;
- case DAVListener.COLLECTION_REMOVED:
- triggerCollectionRemoved( resource.getRelativePath() );
- break;
- case DAVListener.RESOURCE_CREATED:
- triggerResourceCreated( resource.getRelativePath() );
- break;
- case DAVListener.RESOURCE_REMOVED:
- triggerResourceRemoved( resource.getRelativePath() );
- break;
- case DAVListener.RESOURCE_MODIFIED:
- triggerResourceModified( resource.getRelativePath() );
- break;
- }
- }
-
- public void setUseIndexHtml( boolean useIndexHtml )
- {
- super.setUseIndexHtml( useIndexHtml );
- this.methodGet.setUseIndexHtml( useIndexHtml );
- }
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java (revision 0)
@@ -0,0 +1,34 @@
+package org.apache.maven.archiva.webdav;
+
+import org.apache.jackrabbit.webdav.DavSession;
+
+/**
+ * @author James William Dumay
+ */
+public class ArchivaDavSession implements DavSession
+{
+ public void addReference(Object o)
+ {
+ throw new UnsupportedOperationException("No yet implemented.");
+ }
+
+ public void removeReference(Object o)
+ {
+ throw new UnsupportedOperationException("No yet implemented.");
+ }
+
+ public void addLockToken(String s)
+ {
+ throw new UnsupportedOperationException("No yet implemented.");
+ }
+
+ public String[] getLockTokens()
+ {
+ throw new UnsupportedOperationException("No yet implemented.");
+ }
+
+ public void removeLockToken(String s)
+ {
+ throw new UnsupportedOperationException("No yet implemented.");
+ }
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java (revision 0)
@@ -0,0 +1,282 @@
+package org.apache.maven.archiva.webdav;
+
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.io.InputContext;
+import org.apache.jackrabbit.webdav.io.OutputContext;
+import org.apache.jackrabbit.webdav.lock.*;
+import org.apache.jackrabbit.util.Text;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.webdav.util.MimeTypes;
+import org.apache.maven.archiva.webdav.util.IndexWriter;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.Date;
+import java.io.*;
+
+/**
+ * @author James William Dumay
+ */
+public class ArchivaDavResource implements DavResource
+{
+ private final MimeTypes mimeTypes;
+
+ private final DavResourceLocator locator;
+
+ private final DavResourceFactory factory;
+
+ private final DavSession session;
+
+ private final File localResource;
+
+ private final String logicalResource;
+
+ private static final String METHODS = "OPTIONS, GET, HEAD, POST, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, PUT, DELETE, MOVE";
+
+ private static final String COMPLIANCE_CLASS = "1";
+
+ private DavPropertySet properties;
+
+ public ArchivaDavResource(String localResource, String logicalResource, MimeTypes mimeTypes, DavResourceLocator locator, DavResourceFactory factory, DavSession session)
+ {
+ this.mimeTypes = mimeTypes;
+ this.localResource = new File(localResource);
+ this.logicalResource = logicalResource;
+ this.locator = locator;
+ this.factory = factory;
+ this.session = session;
+ this.properties = new DavPropertySet();
+ }
+
+ public String getContentType()
+ {
+ return mimeTypes.getMimeType(localResource.getName());
+ }
+
+ public String getComplianceClass()
+ {
+ return COMPLIANCE_CLASS;
+ }
+
+ public String getSupportedMethods()
+ {
+ return METHODS;
+ }
+
+ public boolean exists()
+ {
+ return localResource.exists();
+ }
+
+ public boolean isCollection()
+ {
+ return localResource.isDirectory();
+ }
+
+ public String getDisplayName()
+ {
+ String resPath = getResourcePath();
+ return (resPath != null) ? Text.getName(resPath) : resPath;
+ }
+
+ public DavResourceLocator getLocator()
+ {
+ return locator;
+ }
+
+ public String getResourcePath()
+ {
+ return locator.getResourcePath();
+ }
+
+ public String getHref()
+ {
+ return locator.getHref(isCollection());
+ }
+
+ public long getModificationTime()
+ {
+ return localResource.lastModified();
+ }
+
+ public long getContentLength()
+ {
+ return localResource.length();
+ }
+
+ public void spool(OutputContext outputContext) throws IOException
+ {
+ if (!isCollection())
+ {
+ IOUtils.copy(new FileInputStream(localResource), outputContext.getOutputStream());
+ }
+ else
+ {
+ IndexWriter writer = new IndexWriter(this, localResource, logicalResource);
+ writer.write(outputContext);
+ }
+ }
+
+ public DavPropertyName[] getPropertyNames()
+ {
+ return new DavPropertyName[0];
+ }
+
+ public DavProperty getProperty(DavPropertyName name)
+ {
+ return null;
+ }
+
+ public DavPropertySet getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperty(DavProperty property) throws DavException
+ {
+ }
+
+ public void removeProperty(DavPropertyName propertyName) throws DavException
+ {
+ }
+
+ public MultiStatusResponse alterProperties(DavPropertySet setProperties, DavPropertyNameSet removePropertyNames) throws DavException
+ {
+ return null;
+ }
+
+ public MultiStatusResponse alterProperties(List changeList) throws DavException
+ {
+ return null;
+ }
+
+ public DavResource getCollection()
+ {
+ DavResource parent = null;
+ if (getResourcePath() != null && !getResourcePath().equals("/")) {
+ String parentPath = Text.getRelativeParent(getResourcePath(), 1);
+ if (parentPath.equals("")) {
+ parentPath = "/";
+ }
+ DavResourceLocator parentloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), parentPath);
+ try {
+ parent = factory.createResource(parentloc, session);
+ } catch (DavException e) {
+ // should not occur
+ }
+ }
+ return parent;
+ }
+
+ public void addMember(DavResource resource, InputContext inputContext) throws DavException
+ {
+ File localFile = new File(localResource, resource.getDisplayName());
+ if (!resource.isCollection() && isCollection() && inputContext.hasStream()) //New File
+ {
+ boolean deleteFile = false;
+ FileOutputStream stream = null;
+ try
+ {
+ stream = new FileOutputStream(localFile);
+ IOUtils.copy(inputContext.getInputStream(), stream);
+ if (inputContext.getContentLength() != localFile.length())
+ {
+ deleteFile = true;
+ throw new DavException(HttpServletResponse.SC_BAD_REQUEST, "Content Header length was "
+ + inputContext.getContentLength() + " but was " + localFile.length());
+ }
+ }
+ catch (IOException e)
+ {
+ throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(stream);
+ if (deleteFile)
+ {
+ FileUtils.deleteQuietly(localFile);
+ }
+ }
+ }
+ else if (resource.isCollection() && isCollection()) //New directory
+ {
+ localFile.mkdir();
+ }
+ else
+ {
+ throw new DavException(HttpServletResponse.SC_BAD_REQUEST, "Could not write member "
+ + resource.getResourcePath() + " at " + getResourcePath());
+ }
+ }
+
+ public DavResourceIterator getMembers()
+ {
+ return null;
+ }
+
+ public void removeMember(DavResource member) throws DavException
+ {
+ }
+
+ public void move(DavResource destination) throws DavException
+ {
+ }
+
+ public void copy(DavResource destination, boolean shallow) throws DavException
+ {
+ }
+
+ public boolean isLockable(Type type, Scope scope)
+ {
+ return false;
+ }
+
+ public boolean hasLock(Type type, Scope scope)
+ {
+ return false;
+ }
+
+ public ActiveLock getLock(Type type, Scope scope)
+ {
+ return null;
+ }
+
+ public ActiveLock[] getLocks()
+ {
+ return new ActiveLock[0];
+ }
+
+ public ActiveLock lock(LockInfo reqLockInfo) throws DavException
+ {
+ return null;
+ }
+
+ public ActiveLock refreshLock(LockInfo reqLockInfo, String lockToken) throws DavException
+ {
+ return null;
+ }
+
+ public void unlock(String lockToken) throws DavException
+ {
+ }
+
+ public void addLockManager(LockManager lockmgr)
+ {
+ }
+
+ public DavResourceFactory getFactory()
+ {
+ return factory;
+ }
+
+ public DavSession getSession()
+ {
+ return session;
+ }
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerException.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerException.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerException.java (working copy)
@@ -1,51 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav;
-
-/**
- * DavServerException
- *
- * @author Joakim Erdfelt
- * @version $Id: DavServerException.java 5379 2007-01-07 22:54:41Z joakime $
- */
-public class DavServerException
- extends Exception
-{
-
- public DavServerException()
- {
- }
-
- public DavServerException( String message )
- {
- super( message );
- }
-
- public DavServerException( Throwable cause )
- {
- super( cause );
- }
-
- public DavServerException( String message, Throwable cause )
- {
- super( message, cause );
- }
-
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java (revision 0)
@@ -0,0 +1,19 @@
+package org.apache.maven.archiva.webdav;
+
+/**
+ * @author James William Dumay
+ */
+public class LogicalResource
+{
+ private String path;
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public void setPath(String path)
+ {
+ this.path = path;
+ }
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavLocatorFactory.java (revision 0)
@@ -0,0 +1,53 @@
+package org.apache.maven.archiva.webdav;
+
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.util.Text;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
+
+/**
+ * @author James William Dumay
+ */
+public class ArchivaDavLocatorFactory implements DavLocatorFactory
+{
+ public DavResourceLocator createResourceLocator(String prefix, String href)
+ {
+ // build prefix string and remove all prefixes from the given href.
+ StringBuilder b = new StringBuilder();
+ if (prefix != null && prefix.length() > 0) {
+ b.append(prefix);
+ if (!prefix.endsWith("/"))
+ {
+ b.append('/');
+ }
+ if (href.startsWith(prefix)) {
+ href = href.substring(prefix.length());
+ }
+ }
+
+ // special treatment for root item, that has no name but '/' path.
+ if (href == null || "".equals(href)) {
+ href = "/";
+ }
+
+ final String workspaceName = RepositoryPathUtil.getRepositoryName(href);
+
+ return new ArchivaDavResourceLocator(b.toString(), Text.unescape(href), workspaceName, this);
+ }
+
+ public DavResourceLocator createResourceLocator(String prefix, String workspacePath, String resourcePath)
+ {
+ return createResourceLocator(prefix, workspacePath, resourcePath, true);
+ }
+
+ public DavResourceLocator createResourceLocator(String prefix, String workspacePath,
+ String path, boolean isResourcePath)
+ {
+ final String repository = RepositoryPathUtil.getRepositoryName(path);
+ return new ArchivaDavResourceLocator(prefix, path, repository, this);
+ }
+
+
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerComponent.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerComponent.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerComponent.java (working copy)
@@ -1,143 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav;
-
-import org.apache.maven.archiva.webdav.servlet.DavServerRequest;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-
-/**
- * DavServerComponent
- *
- * @author Joakim Erdfelt
- * @version $Id: DavServerComponent.java 6000 2007-03-04 22:01:49Z joakime $
- */
-public interface DavServerComponent
-{
- /** The Plexus ROLE name */
- public static final String ROLE = DavServerComponent.class.getName();
-
- /**
- * Get the Prefix for this server component.
- * @return the prefix associated with this component.
- */
- public String getPrefix();
-
- /**
- * Set the prefix for this server component.
- * @param prefix the prefix to use.
- */
- public void setPrefix( String prefix );
-
- /**
- *
- * Flag to indicate how the dav server component should treat a GET request against
- * a DAV Collection.
- *
- *
- *
- * If true, the collection being requested will be searched for an index.html (or index.htm)
- * file to serve back, before it defaults to displaying the collection (directory) contents.
- *
- *
- *
- * If false, the collection will always be presented in as a list of contents.
- *
- *
- * @return true to use the index.html instead of directory contents.
- */
- public boolean isUseIndexHtml();
-
- /**
- *
- * Flag to indicate how the dav server component should treat a GET request against
- * a DAV Collection.
- *
- *
- *
- * If true, the collection being requested will be searched for an index.html (or index.htm)
- * file to serve back, before it defaults to displaying the collection (directory) contents.
- *
- *
- *
- * If false, the collection will always be presented in as a list of contents.
- *
- *
- * @param useIndexHtml true to use the index.html instead of directory contents.
- */
- public void setUseIndexHtml( boolean useIndexHtml );
-
- /**
- * Get the root directory for this server.
- *
- * @return the root directory for this server.
- */
- public File getRootDirectory();
-
- /**
- * Set the root directory for this server's content.
- *
- * @param rootDirectory the root directory for this server's content.
- */
- public void setRootDirectory( File rootDirectory );
-
- /**
- * Add a Server Listener for this server component.
- *
- * @param listener the listener to add for this component.
- */
- public void addListener( DavServerListener listener );
-
- /**
- * Remove a server listener for this server component.
- *
- * @param listener the listener to remove.
- */
- public void removeListener( DavServerListener listener );
-
- /**
- * Perform any initialization needed.
- *
- * @param servletConfig the servlet config that might be needed.
- * @throws DavServerException if there was a problem initializing the server component.
- */
- public void init( ServletConfig servletConfig ) throws DavServerException;
-
- /**
- * Performs a simple filesystem check for the specified resource.
- *
- * @param resource the resource to check for.
- * @return true if the resource exists.
- */
- public boolean hasResource( String resource );
-
- /**
- * Process incoming request.
- *
- * @param request the incoming request to process.
- * @param response the outgoing response to provide.
- */
- public void process( DavServerRequest request, HttpServletResponse response )
- throws DavServerException, ServletException, IOException;
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java (revision 0)
@@ -0,0 +1,135 @@
+package org.apache.maven.archiva.webdav;
+
+import org.apache.jackrabbit.webdav.DavSessionProvider;
+import org.apache.jackrabbit.webdav.WebdavRequest;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletRequest;
+import org.apache.maven.archiva.webdav.util.WebdavMethodUtil;
+import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
+import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.spring.PlexusToSpringUtils;
+import org.springframework.web.context.WebApplicationContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * @author James William Dumay
+ */
+public class ArchivaDavSessionProvider implements DavSessionProvider
+{
+ private Logger log = LoggerFactory.getLogger(ArchivaDavSessionProvider.class);
+
+ private SecuritySystem securitySystem;
+
+ private HttpAuthenticator httpAuth;
+
+ public ArchivaDavSessionProvider(WebApplicationContext applicationContext)
+ {
+ securitySystem = (SecuritySystem) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( SecuritySystem.ROLE ) );
+ httpAuth = (HttpAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
+ }
+
+ public boolean attachSession(WebdavRequest request) throws DavException
+ {
+ final String repositoryId = RepositoryPathUtil.getRepositoryName(removeContextPath(request));
+ return isAuthenticated(request, repositoryId) && isAuthorized(request, repositoryId);
+ }
+
+ public void releaseSession(WebdavRequest webdavRequest)
+ {
+ }
+
+ protected boolean isAuthenticated( WebdavRequest request, String repositoryId )
+ throws DavException
+ {
+ // Authentication Tests.
+ try
+ {
+ AuthenticationResult result = httpAuth.getAuthenticationResult(request, null);
+
+ if ( result == null || !result.isAuthenticated() )
+ {
+ //Unfortunatly, the DavSessionProvider does not pass in the response
+ httpAuth.authenticate(request, null);
+ }
+ }
+ catch ( AuthenticationException e )
+ {
+ throw new UnauthorizedDavException(repositoryId, "You are not authenticated");
+ }
+ catch ( AccountLockedException e )
+ {
+ throw new UnauthorizedDavException(repositoryId, "User account is locked.");
+ }
+ catch ( MustChangePasswordException e )
+ {
+ throw new UnauthorizedDavException(repositoryId, "You must change your password.");
+ }
+
+ return true;
+ }
+
+ protected boolean isAuthorized( WebdavRequest request, String repositoryId )
+ throws DavException
+ {
+ // Authorization Tests.
+ final boolean isWriteRequest = WebdavMethodUtil.isWriteMethod( request.getMethod() );
+
+ SecuritySession securitySession = httpAuth.getSecuritySession();
+ try
+ {
+ String permission = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
+
+ if ( isWriteRequest )
+ {
+ permission = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
+ }
+
+ //DavServletRequestInfo requestInfo = new DavServletRequestInfo(request);
+
+ AuthorizationResult authzResult =
+ securitySystem.authorize( securitySession, permission, repositoryId);
+
+ if ( !authzResult.isAuthorized() )
+ {
+ if ( authzResult.getException() != null )
+ {
+ log.info( "Authorization Denied [ip=" + request.getRemoteAddr() + ",isWriteRequest=" + isWriteRequest +
+ ",permission=" + permission + ",repo=" + repositoryId + "] : " +
+ authzResult.getException().getMessage() );
+ }
+ throw new DavException(HttpServletResponse.SC_UNAUTHORIZED, "Access denied for repository " + repositoryId);
+ }
+ }
+ catch ( AuthorizationException e )
+ {
+ log.error(e.getMessage(), e);
+ throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Fatal Authorization Subsystem Error." );
+ }
+
+ return true;
+ }
+
+ private String removeContextPath(final DavServletRequest request)
+ {
+ String path = request.getRequestURI();
+ String ctx = request.getContextPath();
+ if (path.startsWith(ctx)) {
+ path = path.substring(ctx.length());
+ }
+ return path;
+ }
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java (revision 0)
@@ -0,0 +1,24 @@
+package org.apache.maven.archiva.webdav;
+
+import org.apache.jackrabbit.webdav.DavException;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author James William Dumay
+ */
+public class UnauthorizedDavException extends DavException
+{
+ final private String repositoryName;
+
+ public UnauthorizedDavException(String repositoryName, String message)
+ {
+ super(HttpServletResponse.SC_UNAUTHORIZED, message);
+ this.repositoryName = repositoryName;
+ }
+
+ public String getRepositoryName()
+ {
+ return repositoryName;
+ }
+}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerManager.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerManager.java (revision 649058)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/DavServerManager.java (working copy)
@@ -1,74 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.maven.archiva.webdav;
-
-import java.io.File;
-import java.util.Collection;
-
-/**
- * DavServerManager
- *
- * @author Joakim Erdfelt
- * @version $Id: DavServerManager.java 6017 2007-03-06 00:39:53Z joakime $
- */
-public interface DavServerManager
-{
- /** The Plexus ROLE name. */
- public static final String ROLE = DavServerManager.class.getName();
-
- /**
- * Create a DavServerComponent and start tracking it.
- *
- * @param prefix the prefix for this component.
- * @param rootDirectory the root directory for this component's content. null to not set a root directory.
- * @return the created component, suitable for use.
- * @throws DavServerException
- */
- public DavServerComponent createServer( String prefix, File rootDirectory ) throws DavServerException;
-
- /**
- * Get the collection of tracked servers.
- *
- * @return Collection of {@link DavServerComponent} objects.
- */
- public Collection getServers();
-
- /**
- * Removes a specific server from the tracked list of servers.
- *
- * NOTE: This does not remove the associated files on disk, merely the reference being tracked.
- *
- * @param prefix the prefix to remove.
- */
- public void removeServer( String prefix );
-
- /**
- * Get the {@link DavServerComponent} associated with the specified prefix.
- *
- * @param prefix the prefix for the dav server component to use.
- * @return the DavServerComponent, or null if not found.
- */
- public DavServerComponent getServer( String prefix );
-
- /**
- * Remove all servers being tracked by the manager.
- */
- public void removeAllServers();
-}
Index: archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java
===================================================================
--- archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java (revision 0)
+++ archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java (revision 0)
@@ -0,0 +1,92 @@
+package org.apache.maven.archiva.webdav.util;
+
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.io.OutputContext;
+
+import java.util.Date;
+import java.io.PrintWriter;
+import java.io.File;
+
+/**
+ * @author James William Dumay
+ */
+public class IndexWriter
+{
+ private final DavResource resource;
+
+ private final File localResource;
+
+ private final String logicalResource;
+
+ public IndexWriter(DavResource resource, File localResource, String logicalResource)
+ {
+ this.resource = resource;
+ this.localResource = localResource;
+ this.logicalResource = logicalResource;
+ }
+
+ public void write(OutputContext outputContext)
+ {
+ outputContext.setModificationTime(new Date().getTime());
+ outputContext.setContentType("text/html");
+ outputContext.setETag("");
+ if (outputContext.hasStream())
+ {
+ PrintWriter writer = new PrintWriter(outputContext.getOutputStream());
+ writeDocumentStart(writer);
+ writeHyperlinks(writer);
+ writeDocumentEnd(writer);
+ writer.flush();
+ writer.close();
+ }
+ }
+
+ private void writeDocumentStart(PrintWriter writer)
+ {
+ writer.println("");
+ writer.println("");
+ writer.println("Collection: " + logicalResource + "");
+ writer.println("");
+ writer.println("Collection: " + logicalResource + "
");
+
+ //Check if not root
+ if (!"/".equals(logicalResource))
+ {
+ File file = new File(logicalResource);
+ String parentName = file.getParent().equals("") ? "/" : file.getParent();
+
+ writer.println("");
+ }
+
+ writer.println("");
+ }
+
+ private void writeDocumentEnd(PrintWriter writer)
+ {
+ writer.println("
");
+ writer.println("");
+ writer.println("