diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java index 203b707ac..fed837c75 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java @@ -53,7 +53,6 @@ import java.util.Map; /** * RepositoryServlet - * */ public class RepositoryServlet extends AbstractWebdavServlet @@ -83,7 +82,7 @@ public class RepositoryServlet /** * Service the given request. This method has been overridden and copy/pasted to allow better exception handling and * to support different realms - * + * * @param request * @param response * @throws ServletException @@ -96,9 +95,8 @@ public class RepositoryServlet WebdavRequest webdavRequest = new WebdavRequestImpl( request, getLocatorFactory() ); // DeltaV requires 'Cache-Control' header for all methods except 'VERSION-CONTROL' and 'REPORT'. int methodCode = DavMethods.getMethodCode( request.getMethod() ); - boolean noCache = - DavMethods.isDeltaVMethod( webdavRequest ) - && !( DavMethods.DAV_VERSION_CONTROL == methodCode || DavMethods.DAV_REPORT == methodCode ); + boolean noCache = DavMethods.isDeltaVMethod( webdavRequest ) && !( DavMethods.DAV_VERSION_CONTROL == methodCode + || DavMethods.DAV_REPORT == methodCode ); WebdavResponse webdavResponse = new WebdavResponseImpl( response, noCache ); DavResource resource = null; @@ -182,7 +180,7 @@ public class RepositoryServlet } } - resourceFactory = wac.getBean (DavResourceFactory.class); + resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class ); locatorFactory = new ArchivaDavLocatorFactory(); ServletAuthenticator servletAuth = wac.getBean( ServletAuthenticator.class ); @@ -280,14 +278,14 @@ public class RepositoryServlet public void destroy() { configuration.removeListener( this ); - + resourceFactory = null; configuration = null; locatorFactory = null; sessionProvider = null; repositoryMap.clear(); repositoryMap = null; - + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext( getServletContext() ); if ( wac instanceof ConfigurableApplicationContext ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java index 29c7a5282..bb60f61bc 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java @@ -52,6 +52,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -80,7 +81,6 @@ public class RepositoryServletSecurityTest private ServletRunner sr; - @Inject protected ArchivaConfiguration archivaConfiguration; private DavSessionProvider davSessionProvider; @@ -95,26 +95,33 @@ public class RepositoryServletSecurityTest private RepositoryServlet servlet; + @Inject + ApplicationContext applicationContext; + @Before public void setUp() throws Exception { super.setUp(); - String appserverBase = new File( "target/appserver-base" ).getAbsolutePath(); - System.setProperty( "appserver.base", appserverBase ); + String appserverBase = System.getProperty( "appserver.base", new File( "target/appserver-base" ).getAbsolutePath() ); File testConf = new File( "src/test/resources/repository-archiva.xml" ); File testConfDest = new File( appserverBase, "conf/archiva.xml" ); FileUtils.copyFile( testConf, testConfDest ); repoRootInternal = new File( appserverBase, "data/repositories/internal" ); + + archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class ); Configuration config = archivaConfiguration.getConfiguration(); - config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) ); + if (!config.getManagedRepositoriesAsMap().containsKey( REPOID_INTERNAL )) + { + config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) ); + } saveConfiguration( archivaConfiguration ); - CacheManager.getInstance().removeCache( "url-failures-cache" ); + CacheManager.getInstance().clearAll(); HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml index 7e3c83277..f1defb60f 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml @@ -32,7 +32,7 @@ contextConfigLocation classpath*:/META-INF/spring-context.xml - classpath*:/spring-context.xml + classpath*:/spring-context-servlet-security-test.xml diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml new file mode 100644 index 000000000..b5e2e43f9 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + scheduler1 + org.quartz.simpl.SimpleThreadPool + 1 + 4 + org.quartz.simpl.RAMJobStore + + + + + + + + + + + + + + + + + + + + ]]> + + + + + + \ No newline at end of file