]> source.dussan.org Git - archiva.git/commitdiff
MRM-781 - Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav
authorJames William Dumay <jdumay@apache.org>
Fri, 30 May 2008 10:15:05 +0000 (10:15 +0000)
committerJames William Dumay <jdumay@apache.org>
Fri, 30 May 2008 10:15:05 +0000 (10:15 +0000)
* Adding tests for DavSession attachment and release
* Changed the ArchivaDavSessionProvider so that it does not rely on the WebApplicationContext

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@661630 13f79535-47bb-0310-9956-ffa450edef68

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/RepositoryServlet.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProviderTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedDavSessionProvider.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedRepositoryServlet.java

index b2200aac69a9126a349c7a709ab9c7d1ea0cb43d..085a6e77024f7772d469998ece0394b229098d5d 100644 (file)
@@ -30,10 +30,9 @@ import org.codehaus.plexus.redback.authentication.AuthenticationResult;
 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
 import org.codehaus.plexus.redback.policy.AccountLockedException;
 import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
-import org.codehaus.plexus.spring.PlexusToSpringUtils;
-import org.springframework.web.context.WebApplicationContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
 
 /**
  * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
@@ -47,13 +46,10 @@ public class ArchivaDavSessionProvider
 
     private HttpAuthenticator httpAuth;
     
-    public ArchivaDavSessionProvider( WebApplicationContext applicationContext )
+    public ArchivaDavSessionProvider( ServletAuthenticator servletAuth, HttpAuthenticator httpAuth )
     {
-        servletAuth =
-            (ServletAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( ServletAuthenticator.class.getName() ) );
-        httpAuth =
-            (HttpAuthenticator) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE,
-                                                                                               "basic" ) );
+        this.servletAuth = servletAuth;
+        this.httpAuth = httpAuth;
     }
 
     public boolean attachSession( WebdavRequest request )
@@ -86,11 +82,7 @@ public class ArchivaDavSessionProvider
 
     public void releaseSession( WebdavRequest request )
     {
-        //Remove DavSession
-        if (request.getDavSession() != null)
-        {
-            request.setDavSession(null);
-        }
+        request.setDavSession(null);
     }
     
     private String removeContextPath( final DavServletRequest request )
index ca6cc9bc79e8f8dd38f8b0b3cfad6205cab7c40f..969b75da3cb4e173b232ba85629760b3bd72b2ce 100644 (file)
@@ -38,6 +38,8 @@ import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.IOException;
 import java.util.Map;
+import org.apache.maven.archiva.security.ServletAuthenticator;
+import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
 
 /**
  * RepositoryServlet
@@ -175,7 +177,13 @@ public class RepositoryServlet
         resourceFactory =
             (DavResourceFactory) wac.getBean( PlexusToSpringUtils.buildSpringId( ArchivaDavResourceFactory.class ) );        
         locatorFactory = new ArchivaDavLocatorFactory();
-        sessionProvider = new ArchivaDavSessionProvider( wac );
+        
+        ServletAuthenticator servletAuth =
+            (ServletAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( ServletAuthenticator.class.getName() ) );
+        HttpAuthenticator httpAuth =
+            (HttpAuthenticator) wac.getBean( PlexusToSpringUtils.buildSpringId( HttpAuthenticator.ROLE, "basic" ) );
+        
+        sessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth );
     }
 
     public void configurationEvent( ConfigurationEvent event )
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProviderTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProviderTest.java
new file mode 100644 (file)
index 0000000..2a53bf9
--- /dev/null
@@ -0,0 +1,444 @@
+package org.apache.maven.archiva.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import junit.framework.TestCase;
+import org.apache.jackrabbit.webdav.DavSessionProvider;
+import org.apache.jackrabbit.webdav.WebdavRequest;
+import org.apache.jackrabbit.webdav.WebdavRequestImpl;
+import org.apache.maven.archiva.security.ServletAuthenticator;
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.UnauthorizedException;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
+
+public class ArchivaDavSessionProviderTest extends TestCase
+{
+    private DavSessionProvider sessionProvider;
+    
+    private WebdavRequest request;
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        sessionProvider = new ArchivaDavSessionProvider(new ServletAuthenticatorMock(), new HttpAuthenticatorMock());
+        request = new WebdavRequestImpl(new HttpServletRequestMock(), null);
+    }
+    
+    public void testAttachSession()
+        throws Exception
+    {
+        assertNull(request.getDavSession());
+        sessionProvider.attachSession(request);
+        assertNotNull(request.getDavSession());
+    }
+    
+    public void testReleaseSession()
+        throws Exception
+    {
+        assertNull(request.getDavSession());
+        sessionProvider.attachSession(request);
+        assertNotNull(request.getDavSession());
+        
+        sessionProvider.releaseSession(request);
+        assertNull(request.getDavSession());
+    }
+    
+    private class HttpServletRequestMock implements HttpServletRequest
+    {
+        public Object getAttribute(String arg0) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public Enumeration getAttributeNames() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getCharacterEncoding() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public int getContentLength() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getContentType() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public ServletInputStream getInputStream()
+            throws IOException
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getLocalAddr() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getLocalName() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public int getLocalPort() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public Locale getLocale() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public Enumeration getLocales()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getParameter(String arg0)
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public Map getParameterMap()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public Enumeration getParameterNames()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String[] getParameterValues(String arg0)
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getProtocol() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public BufferedReader getReader()
+            throws IOException 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getRealPath(String arg0)
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getRemoteAddr()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getRemoteHost()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public int getRemotePort()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public RequestDispatcher getRequestDispatcher(String arg0)
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getScheme()
+        {
+            return "";
+        }
+
+        public String getServerName()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public int getServerPort()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public boolean isSecure()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public void removeAttribute(String arg0)
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public void setAttribute(String arg0, Object arg1)
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public void setCharacterEncoding(String arg0)
+            throws UnsupportedEncodingException
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+        
+
+        public String getAuthType()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getContextPath()
+        {
+            return "/";
+        }
+
+        public Cookie[] getCookies()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public long getDateHeader(String arg0) 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getHeader(String arg0) {
+            return "";
+        }
+
+        public Enumeration getHeaderNames()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public Enumeration getHeaders(String arg0) 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public int getIntHeader(String arg0) 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getMethod()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getPathInfo()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getPathTranslated()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getQueryString()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getRemoteUser()
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getRequestURI()
+        {
+            return "/";
+        }
+
+        public StringBuffer getRequestURL() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getRequestedSessionId() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public String getServletPath() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public HttpSession getSession(boolean arg0) 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public HttpSession getSession() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public Principal getUserPrincipal() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public boolean isRequestedSessionIdFromCookie() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public boolean isRequestedSessionIdFromURL() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public boolean isRequestedSessionIdFromUrl() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public boolean isRequestedSessionIdValid() 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public boolean isUserInRole(String arg0) 
+        {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+    }
+    
+    private class ServletAuthenticatorMock implements ServletAuthenticator
+    {
+        public boolean isAuthenticated(HttpServletRequest arg0, AuthenticationResult arg1)
+            throws AuthenticationException, AccountLockedException, MustChangePasswordException
+        {
+            return true;
+        }
+
+        public boolean isAuthorized(HttpServletRequest arg0, SecuritySession arg1, String arg2, boolean arg3)
+            throws AuthorizationException, UnauthorizedException
+        {
+            return true;
+        }
+
+        public boolean isAuthorizedToAccessVirtualRepository(String arg0, String arg1)
+            throws UnauthorizedException
+        {
+            return true;
+        }   
+    }
+    
+    private class HttpAuthenticatorMock extends HttpAuthenticator
+    {
+        @Override
+        public void challenge(HttpServletRequest arg0, HttpServletResponse arg1, String arg2, AuthenticationException arg3)
+            throws IOException
+        {
+            //Do nothing
+        }
+
+        @Override
+        public AuthenticationResult getAuthenticationResult(HttpServletRequest arg0, HttpServletResponse arg1)
+            throws AuthenticationException, AccountLockedException, MustChangePasswordException
+        {
+            return new AuthenticationResult();
+        }
+        
+
+        @Override
+        public AuthenticationResult authenticate(AuthenticationDataSource arg0)
+            throws AuthenticationException, AccountLockedException, MustChangePasswordException
+        {
+            return new AuthenticationResult();
+        }
+
+        @Override
+        public void authenticate(HttpServletRequest arg0, HttpServletResponse arg1)
+            throws AuthenticationException
+        {
+            //Do nothing
+        }
+
+        @Override
+        public Map getContextSession()
+        {
+            return super.getContextSession();
+        }
+
+        @Override
+        public SecuritySession getSecuritySession()
+        {
+            return super.getSecuritySession();
+        }
+
+        @Override
+        public User getSessionUser()
+        {
+            return super.getSessionUser();
+        }
+
+        @Override
+        public boolean isAlreadyAuthenticated()
+        {
+            return super.isAlreadyAuthenticated();
+        }
+
+        @Override
+        public void setSecuritySession(SecuritySession session)
+        {
+            super.setSecuritySession(session);
+        }
+
+        @Override
+        public void setSessionUser(User user) {
+            super.setSessionUser(user);
+        }
+
+        @Override
+        public String storeDefaultUser(String user) {
+            return super.storeDefaultUser(user);
+        }
+        
+    }
+}
index 567f348f05059b566aed6779e8b61324dd067593..13082cf4d575e9d0aa448fd214d287dba5b3b4d4 100644 (file)
@@ -19,25 +19,24 @@ package org.apache.maven.archiva.webdav;
  * under the License.
  */
 
-import org.apache.maven.archiva.webdav.ArchivaDavSessionProvider;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.WebdavRequest;
-import org.springframework.web.context.WebApplicationContext;
 
 /**
  * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
  */
 public class UnauthenticatedDavSessionProvider extends ArchivaDavSessionProvider
 {
-    public UnauthenticatedDavSessionProvider(WebApplicationContext applicationContext)
+    public UnauthenticatedDavSessionProvider()
     {
-        super(applicationContext);
+        super(null, null);
     }
     
     @Override
     public boolean attachSession( WebdavRequest request )
         throws DavException
     {
+        request.setDavSession(new ArchivaDavSession());
         return true;
-    }    
+    }
 }
index 57f37931c080cedf464c6bfd844fd4c65bf9588c..d62ddf9ac5f0b52fcc83377a95fe6c69caf9e2a4 100644 (file)
@@ -19,10 +19,6 @@ package org.apache.maven.archiva.webdav;
  * under the License.
  */
 
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-import org.apache.maven.archiva.webdav.RepositoryServlet;
-
 import javax.servlet.ServletConfig;
 
 /**
@@ -38,10 +34,8 @@ public class UnauthenticatedRepositoryServlet
     public synchronized void initServers( ServletConfig servletConfig )
     {
         super.initServers(servletConfig);
-
-        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() );
-
-        UnauthenticatedDavSessionProvider sessionProvider = new UnauthenticatedDavSessionProvider(wac);
+        
+        UnauthenticatedDavSessionProvider sessionProvider = new UnauthenticatedDavSessionProvider();
         setDavSessionProvider(sessionProvider);
     }
 }