FELIX-3935 - Testcases for JAAS integration
Adding testcases for following scenarios
-- registration of WebConsole plugin if HTTP service is present
-- replacing the global config via explicit setting
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1459227 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/jaas/pom.xml b/jaas/pom.xml
index befb351..c49e867 100644
--- a/jaas/pom.xml
+++ b/jaas/pom.xml
@@ -171,6 +171,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
+ <!--suppress MavenModelInspection -->
<encoding>${project.build.sourceEncoding}</encoding>
<excludePackageNames>*.internal</excludePackageNames>
</configuration>
@@ -260,6 +261,12 @@
<version>1.6.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http.bundle</artifactId>
+ <version>2.2.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
@@ -314,8 +321,8 @@
<dependencies>
<dependency>
<groupId>org.eclipse</groupId>
- <artifactId>osgi</artifactId>
- <version>3.7.1.R37x_v20110808-1106</version>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>3.8.0.v20120529-1548</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java b/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java
new file mode 100644
index 0000000..7b23837
--- /dev/null
+++ b/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java
@@ -0,0 +1,77 @@
+/*
+ * 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.felix.jaas.integration;
+
+import javax.inject.Inject;
+import javax.servlet.Servlet;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
+
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class ITJaasWebConsolePlugin extends JaasTestBase
+{
+ @Rule
+ public TestName name= new TestName();
+
+ @Inject
+ @Filter("(&(felix.webconsole.label=*)(felix.webconsole.title=*)(felix.webconsole.configprinter.modes=*))")
+ private Servlet servlet;
+
+ static
+ {
+ // uncomment to enable debugging of this test class
+// paxRunnerVmOption = DEBUG_VM_OPTION;
+
+ }
+
+ @Override
+ protected Option addExtraOptions()
+ {
+ return composite(
+ mavenBundle("org.apache.felix","org.apache.felix.http.bundle").versionAsInProject(),
+ streamBundle(createConfigBasedBundle())
+ );
+ }
+
+
+ /**
+ * Checks the presence of plugin servlet if Servlet API is present
+ */
+ @Test
+ public void testJaasPlugin() throws Exception
+ {
+ assertNotNull(servlet);
+ }
+
+}
diff --git a/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java b/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
index d5aba18..fa01d4d 100644
--- a/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
+++ b/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
@@ -20,6 +20,7 @@
package org.apache.felix.jaas.integration;
import java.io.File;
+import java.util.Properties;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
@@ -34,7 +35,7 @@
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
import static org.junit.Assert.assertFalse;
import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackage;
@@ -43,7 +44,7 @@
import static org.ops4j.pax.exam.CoreOptions.vmOption;
@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
+@ExamReactorStrategy(PerMethod.class)
public class ITJaasWithBootClasspath extends JaasTestBase
{
@@ -104,4 +105,29 @@
assertFalse(s.getPrincipals().isEmpty());
}
+ @Test
+ public void testJaasWithBootAndGlobalConfig() throws Exception
+ {
+ String realmName = name.getMethodName();
+ createLoginModuleConfig(realmName);
+
+ //1. Configure the ConfigSpi to replace global config
+ org.osgi.service.cm.Configuration config2 = ca.getConfiguration("org.apache.felix.jaas.ConfigurationSpi",null);
+ Properties p2 = new Properties();
+ p2.setProperty("jaas.globalConfigPolicy","replace");
+ config2.update(p2);
+
+ delay();
+
+ CallbackHandler handler = new SimpleCallbackHandler("foo", "foo");
+ Subject s = new Subject();
+
+ //2. Now just do normal JAAS Login. No change of TCCL and no fetching of explicit config
+
+ LoginContext lc = new LoginContext(realmName, s, handler);
+ lc.login();
+
+ assertFalse(s.getPrincipals().isEmpty());
+ }
+
}
diff --git a/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java b/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java
new file mode 100644
index 0000000..4ee0c34
--- /dev/null
+++ b/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java
@@ -0,0 +1,102 @@
+/*
+ * 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.felix.jaas.integration;
+
+import java.util.Properties;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+
+import org.apache.felix.jaas.integration.common.SimpleCallbackHandler;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.junit.Assert.assertFalse;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class ITJaasWithGlobalConfig extends JaasTestBase
+{
+
+ @Rule
+ public TestName name= new TestName();
+
+ static
+ {
+ // uncomment to enable debugging of this test class
+// paxRunnerVmOption = DEBUG_VM_OPTION;
+
+ }
+
+ @Override
+ protected Option addExtraOptions()
+ {
+ return composite(
+ streamBundle(createConfigBasedBundle())
+ );
+ }
+
+
+ /**
+ * Creates the scenario where jaas-boot jar is placed in bootclasspath. With this the client
+ * code need not switch the TCCL
+ */
+ @Test
+ public void testJaasWithGlobalConfig() throws Exception
+ {
+ String realmName = name.getMethodName();
+ createLoginModuleConfig(realmName);
+
+ //1. Configure the ConfigSpi to replace global config
+ org.osgi.service.cm.Configuration config2 = ca.getConfiguration("org.apache.felix.jaas.ConfigurationSpi",null);
+ Properties p2 = new Properties();
+ p2.setProperty("jaas.globalConfigPolicy","replace");
+ config2.update(p2);
+ delay();
+
+ //2. Validate the login passes with this config. Would not pass explicit config
+ CallbackHandler handler = new SimpleCallbackHandler("foo","foo");
+
+ Subject s = new Subject();
+ final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ LoginContext lc = new LoginContext(realmName,s,handler);
+ lc.login();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+
+ assertFalse(s.getPrincipals().isEmpty());
+ }
+
+}