import org.apache.maven.archiva.configuration.ConfigurationEvent;
import org.apache.maven.archiva.configuration.ConfigurationListener;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.webdav.ArchivaDavLocatorFactory;
-import org.apache.maven.archiva.webdav.ArchivaDavResourceFactory;
-import org.apache.maven.archiva.webdav.ArchivaDavSessionProvider;
-import org.apache.maven.archiva.webdav.UnauthorizedDavException;
+import org.apache.maven.archiva.webdav.*;
import org.apache.jackrabbit.webdav.server.AbstractWebdavServlet;
import org.apache.jackrabbit.webdav.*;
import org.codehaus.plexus.redback.system.SecuritySystem;
webdavResponse.setHeader("WWW-Authenticate", getAuthenticateHeaderValue(e.getRepositoryName()));
webdavResponse.sendError(e.getErrorCode(), e.getStatusPhrase());
}
- catch (DavException e) {
+ catch (BrowserRedirectException e)
+ {
+ response.sendRedirect(e.getLocation());
+ }
+ catch (DavException e)
+ {
if (e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
final String msg = "Should throw " + UnauthorizedDavException.class.getName();
log.error(msg);
final String repository = RepositoryPathUtil.getRepositoryName(path);
return new ArchivaDavResourceLocator(prefix, path, repository, this);
}
-
-
}
{
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get resource for method " + request.getMethod());
}
+
setHeaders(locator, response);
+
+ //compatibility with MRM-440 to ensure browsing the repository works ok
+ if (resource.isCollection() && !resource.getLocator().getResourcePath().endsWith("/"))
+ {
+ throw new BrowserRedirectException(resource.getHref());
+ }
}
return resource;
}
this.prefix = prefix;
this.repositoryId = repositoryId;
this.davLocatorFactory = davLocatorFactory;
+ this.resourcePath = resourcePath;
+
+ String escapedPath = Text.escapePath(resourcePath);
+ String hrefPrefix = prefix;
- // 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);
+ //Ensure no extra slashes when href is joined
+ if (hrefPrefix.endsWith("/") && escapedPath.startsWith("/"))
+ {
+ hrefPrefix = hrefPrefix.substring(0, hrefPrefix.length()-1);
}
- this.resourcePath = resourcePath;
- href = prefix + Text.escapePath(resourcePath);
+ href = hrefPrefix + escapedPath;
}
public String getRepositoryId()
--- /dev/null
+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 BrowserRedirectException extends DavException
+{
+ final String location;
+
+ public BrowserRedirectException(String location)
+ {
+ super(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ this.location = location;
+ }
+
+ public String getLocation()
+ {
+ return location;
+ }
+}
throws Exception
{
String prefix = "http://myproxy/";
- String href = "repository/internal";
+ String href = "/repository/internal";
ArchivaDavResourceLocator locator = (ArchivaDavResourceLocator)factory.createResourceLocator(prefix, href);
assertEquals("internal", locator.getRepositoryId());
assertEquals("http://myproxy/", locator.getPrefix());
assertEquals("http://myproxy/repository/internal", locator.getHref(false));
assertEquals("http://myproxy/repository/internal/", locator.getHref(true));
- assertEquals("repository/internal", locator.getResourcePath());
- assertEquals("repository/internal", locator.getRepositoryPath());
+ assertEquals("/repository/internal", locator.getResourcePath());
+ assertEquals("/repository/internal", locator.getRepositoryPath());
}
public void testLocatorWithHrefThatContainsPrefix()
assertEquals("", locator.getWorkspaceName());
assertEquals("", locator.getWorkspacePath());
assertEquals("http://myproxy/", locator.getPrefix());
- assertEquals("http://myproxy//", locator.getHref(false));
- assertEquals("http://myproxy//", locator.getHref(true));
+ assertEquals("http://myproxy/", locator.getHref(false));
+ assertEquals("http://myproxy/", locator.getHref(true));
assertEquals("/", locator.getResourcePath());
assertEquals("/", locator.getRepositoryPath());
}
<jdkLevel>1.5</jdkLevel>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-alpha-3</version>
+ </plugin>
</plugins>
</pluginManagement>
</build>