You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2008/04/18 05:06:06 UTC

svn commit: r649352 [2/2] - in /archiva/trunk: ./ archiva-jetty/ archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ archiva-modules/archiva-web/archiva-webapp/ archiva-modules/archiva-web/archiva-webapp/src/ma...

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java?rev=649352&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java Thu Apr 17 20:05:18 2008
@@ -0,0 +1,136 @@
+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 org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.util.Text;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+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 <code>DavResourceLocator</code>
+     * object with the same hash code.
+     *
+     * @param obj the object to compare to
+     * @return <code>true</code> if the 2 objects are equal;
+     *         <code>false</code> otherwise
+     */
+    public boolean equals(Object obj)
+    {
+        if (obj instanceof DavResourceLocator)
+        {
+            DavResourceLocator other = (DavResourceLocator) obj;
+            return hashCode() == other.hashCode();
+        }
+        return false;
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceLocator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java?rev=649352&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java Thu Apr 17 20:05:18 2008
@@ -0,0 +1,53 @@
+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 org.apache.jackrabbit.webdav.DavSession;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+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.");
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java?rev=649352&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java Thu Apr 17 20:05:18 2008
@@ -0,0 +1,154 @@
+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 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 <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+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;
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavSessionProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java?rev=649352&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java Thu Apr 17 20:05:18 2008
@@ -0,0 +1,38 @@
+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.
+ */
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class LogicalResource
+{
+    private String path;
+
+    public String getPath()
+    {
+        return path;
+    }
+
+    public void setPath(String path)
+    {
+        this.path = path;
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/LogicalResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java?rev=649352&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java Thu Apr 17 20:05:18 2008
@@ -0,0 +1,43 @@
+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 org.apache.jackrabbit.webdav.DavException;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+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;
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/UnauthorizedDavException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java?rev=649352&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java Thu Apr 17 20:05:18 2008
@@ -0,0 +1,111 @@
+package org.apache.maven.archiva.webdav.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.io.OutputContext;
+
+import java.util.Date;
+import java.io.PrintWriter;
+import java.io.File;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+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("<html>");
+        writer.println("<head>");
+        writer.println("<title>Collection: " + logicalResource + "<title>");
+        writer.println("</head>");
+        writer.println("<h3>Collection: " + logicalResource + "</h3>");
+
+        //Check if not root
+        if (!"/".equals(logicalResource))
+        {
+            File file = new File(logicalResource);
+            String parentName = file.getParent().equals("") ? "/" : file.getParent();
+
+            writer.println("<ul>");
+            writer.println("<li><a href=\"../\">" + parentName + "</a> <i><small>(Parent)</small></i></li>");
+            writer.println("</ul>");
+        }
+
+        writer.println("<ul>");
+    }
+
+    private void writeDocumentEnd(PrintWriter writer)
+    {
+        writer.println("</ul>");
+        writer.println("</body>");
+        writer.println("</html>");
+    }
+
+    private void writeHyperlinks(PrintWriter writer)
+    {
+        for (File file : localResource.listFiles())
+        {
+            writeHyperlink(writer, file.getName(), file.isDirectory());
+        }
+    }
+
+    private void writeHyperlink(PrintWriter writer, String resourceName, boolean directory)
+    {
+        if (directory)
+        {
+            writer.println("<li><a href=\"./" + resourceName + "/\">" + resourceName + "</a></li>");
+        }
+        else
+        {
+            writer.println("<li><a href=\"./" + resourceName + "\">" + resourceName + "</a></li>");
+        }
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/IndexWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/MimeTypes.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/MimeTypes.java?rev=649352&r1=649351&r2=649352&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/MimeTypes.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/MimeTypes.java Thu Apr 17 20:05:18 2008
@@ -1,3 +1,5 @@
+package org.apache.maven.archiva.webdav.util;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -7,7 +9,7 @@
  * "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
+ *  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
@@ -17,8 +19,6 @@
  * under the License.
  */
 
-package org.apache.maven.archiva.webdav.util;
-
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
@@ -49,10 +49,9 @@
     extends AbstractLogEnabled
     implements Initializable
 {
-    /**
-     * @plexus.configuration default-value="org/apache/maven/archiva/webdav/util/mime-types.txt"
-     */
-    private String resource;
+    private static final String DEFAULT_MIME_TYPE = "application/octet-stream";
+
+    private String resource = "org/apache/maven/archiva/webdav/util/mime.types";
     
     private Map mimeMap = new HashMap();
 
@@ -74,6 +73,13 @@
                 value = (String) mimeMap.get( filename.substring( index + 1 ).toLowerCase() );
             }
         }
+
+
+        if (value == null)
+        {
+            value = DEFAULT_MIME_TYPE;
+        }
+
         return value;
 
     }

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/RepositoryPathUtil.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/RepositoryPathUtil.java?rev=649352&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/RepositoryPathUtil.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/RepositoryPathUtil.java Thu Apr 17 20:05:18 2008
@@ -0,0 +1,105 @@
+package org.apache.maven.archiva.webdav.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.io.FilenameUtils;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class RepositoryPathUtil
+{
+    public static String getLogicalResource(final String href)
+    {
+        String logicalResource = null;
+        String requestPathInfo = StringUtils.defaultString( href );
+
+        //remove prefix ie /repository/blah becomes /blah
+        requestPathInfo = removePrefix(requestPathInfo);
+
+        // Remove prefixing slash as the repository id doesn't contain it;
+        if ( requestPathInfo.startsWith( "/" ) )
+        {
+            requestPathInfo = requestPathInfo.substring( 1 );
+        }        
+
+        int slash = requestPathInfo.indexOf( '/' );
+        if ( slash > 0 )
+        {
+            logicalResource = requestPathInfo.substring( slash );
+
+            if (logicalResource.endsWith( "/.." ) )
+            {
+                logicalResource += "/";
+            }
+
+            if ( logicalResource != null && logicalResource.startsWith( "//" ) )
+            {
+                logicalResource = logicalResource.substring( 1 );
+            }
+
+            if ( logicalResource == null )
+            {
+                logicalResource = "/";
+            }
+        }
+        else
+        {
+            logicalResource = "/";
+        }
+        return logicalResource;
+    }
+
+    public static String getRepositoryName(final String href)
+    {
+        String requestPathInfo = StringUtils.defaultString( href );
+
+        //remove prefix ie /repository/blah becomes /blah
+        requestPathInfo = removePrefix(requestPathInfo);
+
+        // 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"
+            return requestPathInfo.substring( 0, slash );
+        }
+        return requestPathInfo;
+    }
+
+    private static String removePrefix(final String href)
+    {
+        String[] parts = StringUtils.split(href, '/');
+        parts = (String[]) ArrayUtils.subarray(parts, 1, parts.length);
+        if (parts == null || parts.length == 0)
+        {
+            return "/";
+        }
+        return StringUtils.join(parts, '/');
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/RepositoryPathUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/WebdavMethodUtil.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/WebdavMethodUtil.java?rev=649352&r1=649351&r2=649352&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/WebdavMethodUtil.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/util/WebdavMethodUtil.java Thu Apr 17 20:05:18 2008
@@ -1,3 +1,5 @@
+package org.apache.maven.archiva.webdav.util;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -7,7 +9,7 @@
  * "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
+ *  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
@@ -16,8 +18,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
-package org.apache.maven.archiva.webdav.util;
 
 import org.apache.commons.lang.StringUtils;
 

Copied: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/resources/org/apache/maven/archiva/webdav/util/mime.types (from r649123, archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/resources/org/apache/maven/archiva/webdav/util/mime-types.txt)
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/resources/org/apache/maven/archiva/webdav/util/mime.types?p2=archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/resources/org/apache/maven/archiva/webdav/util/mime.types&p1=archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/resources/org/apache/maven/archiva/webdav/util/mime-types.txt&r1=649123&r2=649352&rev=649352&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/resources/org/apache/maven/archiva/webdav/util/mime-types.txt (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/main/resources/org/apache/maven/archiva/webdav/util/mime.types Thu Apr 17 20:05:18 2008
@@ -1,5 +1,3 @@
-# This is a comment. I love comments.
-
 # This file controls what Internet media types are sent to the client for
 # given file extension(s). Sending the correct media type to the client
 # is important so they know how to handle the content of the file.
@@ -21,6 +19,7 @@
 application/oda                          oda
 application/ogg                          ogg
 application/pdf                          pdf
+application/pgp-encrypted				 pgp
 application/postscript                   ai eps ps
 application/rdf+xml                      rdf
 application/smil                         smi smil
@@ -67,7 +66,7 @@
 application/x-ustar                      ustar
 application/x-wais-source                src
 application/xhtml+xml                    xhtml xht
-application/xml                          xml xsl
+application/xml                          xml xsl pom
 application/xml-dtd                      dtd
 application/xslt+xml                     xslt
 application/zip                          zip
@@ -110,7 +109,7 @@
 text/calendar                            ics ifb
 text/css                                 css
 text/html                                html htm
-text/plain                               asc txt
+text/plain                               asc txt sha1 md5
 text/richtext                            rtx
 text/rtf                                 rtf
 text/sgml                                sgml sgm

Modified: archiva/trunk/pom.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/pom.xml?rev=649352&r1=649351&r2=649352&view=diff
==============================================================================
--- archiva/trunk/pom.xml (original)
+++ archiva/trunk/pom.xml Thu Apr 17 20:05:18 2008
@@ -193,6 +193,11 @@
   <dependencyManagement>
     <dependencies>
       <dependency>
+        <groupId>org.apache.jackrabbit</groupId>
+        <artifactId>jackrabbit-webdav</artifactId>
+        <version>1.4</version>
+      </dependency>
+      <dependency>
         <groupId>javax.activation</groupId>
         <artifactId>activation</artifactId>
         <version>1.1</version>