Author: bdelacretaz
Date: Mon Apr 2 13:28:31 2012
New Revision: 1308347
URL: http://svn.apache.org/viewvc?rev=1308347&view=rev
Log:
SLING-2443 - WWW-Authenticate header was missing on OPTIONS request on /
Added:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavOptionsTest.java
Modified:
sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
Modified:
sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java?rev=1308347&r1=1308346&r2=1308347&view=diff
==============================================================================
---
sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
(original)
+++
sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
Mon Apr 2 13:28:31 2012
@@ -18,10 +18,13 @@
*/
package org.apache.sling.jcr.webdav.impl.servlets;
+import java.io.IOException;
+
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
@@ -35,7 +38,10 @@ import org.apache.jackrabbit.server.Sess
import org.apache.jackrabbit.server.io.CopyMoveHandler;
import org.apache.jackrabbit.server.io.IOHandler;
import org.apache.jackrabbit.server.io.PropertyHandler;
+import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.webdav.WebdavRequest;
+import org.apache.jackrabbit.webdav.WebdavResponse;
import org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet;
import org.apache.sling.commons.mime.MimeTypeService;
import org.apache.sling.jcr.api.SlingRepository;
@@ -267,4 +273,16 @@ public class SlingWebDavServlet extends
public void unbindCopyMoveHandler(final ServiceReference
copyMoveHandlerReference) {
this.copyMoveManager.unbindCopyMoveHandler(copyMoveHandlerReference);
}
+
+ /** Overridden as the base class uses sendError that we don't want
(SLING-2443) */
+ @Override
+ protected void sendUnauthorized(WebdavRequest request, WebdavResponse
response, DavException error) throws IOException {
+ response.setHeader("WWW-Authenticate", getAuthenticateHeaderValue());
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ if (error != null) {
+ response.getWriter().write(error.getStatusPhrase());
+ response.getWriter().write("\n");
+ }
+ response.getWriter().flush();
+ }
}
Added:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavOptionsTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavOptionsTest.java?rev=1308347&view=auto
==============================================================================
---
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavOptionsTest.java
(added)
+++
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavOptionsTest.java
Mon Apr 2 13:28:31 2012
@@ -0,0 +1,46 @@
+/*
+ * 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.sling.launchpad.webapp.integrationtest;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.sling.commons.testing.integration.HttpAnyMethod;
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+/** Test WebDAV upload of various file types */
+public class WebdavOptionsTest extends HttpTestBase {
+
+ public static final String WWW_Authenticate = "WWW-Authenticate";
+
+ /** OPTIONS request at given path must return a WWW-Authenticate header */
+ private void doTestOnPath(String path) throws Exception {
+ final HttpClient noCredentialsClient = new HttpClient();
+ final HttpAnyMethod opt = new HttpAnyMethod("OPTIONS", HTTP_BASE_URL +
path);
+ final int status = noCredentialsClient.executeMethod(opt);
+ assertEquals("Expecting matching status on OPTIONS request at " +
path, 401, status);
+ final Header h = opt.getResponseHeader(WWW_Authenticate);
+ assertNotNull("Expecting " + WWW_Authenticate + " header in response
at " + path, h);
+ }
+
+ public void testAuthenticateHeaderOnRoot() throws Exception {
+ doTestOnPath("/");
+ }
+
+ public void testAuthenticateHeaderOnDavPath() throws Exception {
+ doTestOnPath("/dav/default");
+ }
+}