You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2011/11/11 00:57:14 UTC
svn commit: r1200643 - in /sling/trunk/launchpad:
integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/
test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/
Author: justin
Date: Thu Nov 10 23:57:14 2011
New Revision: 1200643
URL: http://svn.apache.org/viewvc?rev=1200643&view=rev
Log:
SLING-2274 - adding integration test to ensure that davex access works if anonymous access is disabled in the authenticator.
Added:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExDisabledAnonAccessTest.java
sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/AnonymousAccessConfigServlet.java
Modified:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExIntegrationTest.java
Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExDisabledAnonAccessTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExDisabledAnonAccessTest.java?rev=1200643&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExDisabledAnonAccessTest.java (added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExDisabledAnonAccessTest.java Thu Nov 10 23:57:14 2011
@@ -0,0 +1,43 @@
+/*
+ * 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 java.util.Collections;
+
+import org.apache.commons.httpclient.NameValuePair;
+
+/**
+ * Test that the repository is accessible via DavEx when anonymous access is
+ * disabled.
+ */
+public class DavExDisabledAnonAccessTest extends DavExIntegrationTest {
+
+ private static String ANON_SERVLET_URL = HTTP_BASE_URL + "/testing/AnonymousAccessConfigServlet.txt";
+
+ @Override
+ protected void configureServerAfterTest() throws Exception {
+ assertPostStatus(ANON_SERVLET_URL, 200, Collections.singletonList(new NameValuePair("action", "enable")),
+ "Unable to enable anonymous access");
+
+ }
+
+ @Override
+ protected void configureServerBeforeTest() throws Exception {
+ assertPostStatus(ANON_SERVLET_URL, 200, Collections.singletonList(new NameValuePair("action", "disable")),
+ "Unable to disable anonymous access");
+ }
+}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExIntegrationTest.java?rev=1200643&r1=1200642&r2=1200643&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExIntegrationTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/DavExIntegrationTest.java Thu Nov 10 23:57:14 2011
@@ -36,9 +36,13 @@ public class DavExIntegrationTest extend
@Override
protected void setUp() throws Exception {
super.setUp();
+ configureServerBeforeTest();
repository = JcrUtils.getRepository(HTTP_BASE_URL + "/server/");
}
+ protected void configureServerBeforeTest() throws Exception {
+ }
+
public void testDescriptor() throws Exception {
assertEquals("2.0", repository.getDescriptor(Repository.SPEC_VERSION_DESC));
assertEquals("Jackrabbit", repository.getDescriptor(Repository.REP_NAME_DESC));
@@ -68,7 +72,11 @@ public class DavExIntegrationTest extend
@Override
protected void tearDown() throws Exception {
- super.tearDown();
repository = null;
+ configureServerAfterTest();
+ super.tearDown();
+ }
+
+ protected void configureServerAfterTest() throws Exception {
}
}
Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/AnonymousAccessConfigServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/AnonymousAccessConfigServlet.java?rev=1200643&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/AnonymousAccessConfigServlet.java (added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/AnonymousAccessConfigServlet.java Thu Nov 10 23:57:14 2011
@@ -0,0 +1,109 @@
+/*
+ * 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.testservices.servlets;
+
+import java.io.IOException;
+import java.util.Dictionary;
+
+import javax.servlet.ServletException;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+/**
+ * Servlet which disables and enables anonymous access and ensures
+ * that the authenticator service has accepted the configuration change.
+ */
+@SuppressWarnings("serial")
+@Component(immediate = true)
+@Service
+@Properties({ @Property(name = "service.description", value = "Anonymous Access Config Servlet"),
+ @Property(name = "service.vendor", value = "The Apache Software Foundation"),
+ @Property(name = "sling.servlet.paths", value = "/testing/AnonymousAccessConfigServlet"),
+ @Property(name = "sling.servlet.extensions", value = "txt"),
+ @Property(name = "event.topics", value = "org/osgi/framework/ServiceEvent/MODIFIED") })
+public class AnonymousAccessConfigServlet extends SlingAllMethodsServlet implements EventHandler {
+
+ private static final String PROP_AUTH_ANNONYMOUS = "auth.annonymous";
+
+ private static final String AUTH_PID = "org.apache.sling.engine.impl.auth.SlingAuthenticator";
+
+ private static final long TIMEOUT = 1000;
+
+ @Reference
+ private ConfigurationAdmin configAdmin;
+
+ private int modifiedCounter;
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException,
+ IOException {
+ response.setContentType(request.getContentType());
+ String action = request.getParameter("action");
+ if ("disable".equals(action)) {
+ int existingModifiedCounter = modifiedCounter;
+ Configuration config = configAdmin.getConfiguration(AUTH_PID);
+ Dictionary props = config.getProperties();
+ props.put(PROP_AUTH_ANNONYMOUS, Boolean.FALSE);
+ config.update(props);
+ waitForModified(existingModifiedCounter, TIMEOUT);
+ } else if ("enable".equals(action)) {
+ int existingModifiedCounter = modifiedCounter;
+ Configuration config = configAdmin.getConfiguration(AUTH_PID);
+ Dictionary props = config.getProperties();
+ props.put(PROP_AUTH_ANNONYMOUS, Boolean.TRUE);
+ config.update(props);
+ waitForModified(existingModifiedCounter, TIMEOUT);
+ }
+
+ response.getWriter().println("ok");
+ }
+
+ private void waitForModified(final int existingModifiedCounter, final long timeoutMsec) {
+ final int targetCounter = existingModifiedCounter + 1;
+ final long end = System.currentTimeMillis() + timeoutMsec;
+ while (modifiedCounter < targetCounter && System.currentTimeMillis() < end) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ignored) {
+ }
+ }
+
+ if (modifiedCounter < targetCounter) {
+ throw new IllegalStateException("Event counter did not reach " + targetCounter + ", waited " + timeoutMsec
+ + " msec");
+ }
+ }
+
+ public void handleEvent(Event event) {
+ if (AUTH_PID.equals(event.getProperty("service.pid"))) {
+ modifiedCounter++;
+ }
+ }
+
+}