felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1459227 - in /felix/trunk/jaas: ./ src/test/java/org/apache/felix/jaas/integration/
Date Thu, 21 Mar 2013 11:20:27 GMT
Author: chetanm
Date: Thu Mar 21 11:20:27 2013
New Revision: 1459227

URL: http://svn.apache.org/r1459227
Log:
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

Added:
    felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java
    felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java
      - copied, changed from r1459226, felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
Modified:
    felix/trunk/jaas/pom.xml
    felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java

Modified: felix/trunk/jaas/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/pom.xml?rev=1459227&r1=1459226&r2=1459227&view=diff
==============================================================================
--- felix/trunk/jaas/pom.xml (original)
+++ felix/trunk/jaas/pom.xml Thu Mar 21 11:20:27 2013
@@ -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>

Added: felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java?rev=1459227&view=auto
==============================================================================
--- felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java
(added)
+++ felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWebConsolePlugin.java
Thu Mar 21 11:20:27 2013
@@ -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);
+    }
+
+}

Modified: felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java?rev=1459227&r1=1459226&r2=1459227&view=diff
==============================================================================
--- felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
(original)
+++ felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
Thu Mar 21 11:20:27 2013
@@ -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.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.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.CoreOpt
 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 @@ public class ITJaasWithBootClasspath ext
         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());
+    }
+
 }

Copied: felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java
(from r1459226, felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java)
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java?p2=felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java&p1=felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java&r1=1459226&r2=1459227&rev=1459227&view=diff
==============================================================================
--- felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithBootClasspath.java
(original)
+++ felix/trunk/jaas/src/test/java/org/apache/felix/jaas/integration/ITJaasWithGlobalConfig.java
Thu Mar 21 11:20:27 2013
@@ -19,11 +19,10 @@
 
 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;
-import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginContext;
 
 import org.apache.felix.jaas.integration.common.SimpleCallbackHandler;
@@ -37,22 +36,14 @@ import org.ops4j.pax.exam.spi.reactors.E
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
 import static org.junit.Assert.assertFalse;
-import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackage;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 import static org.ops4j.pax.exam.CoreOptions.streamBundle;
-import static org.ops4j.pax.exam.CoreOptions.vmOption;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
-public class ITJaasWithBootClasspath extends JaasTestBase
+public class ITJaasWithGlobalConfig extends JaasTestBase
 {
 
-    // the default boot jar file name
-    protected static final String BOOT_JAR_DEFAULT = "target/jaas-boot.jar";
-
-    // the name of the system property providing the bundle file to be installed and tested
-    protected static final String BOOT_JAR_SYS_PROP = "project.boot.file";
-
     @Rule
     public TestName name= new TestName();
 
@@ -66,18 +57,7 @@ public class ITJaasWithBootClasspath ext
     @Override
     protected Option addExtraOptions()
     {
-        final String bundleFileName = System.getProperty(BOOT_JAR_SYS_PROP,
-                BOOT_JAR_DEFAULT);
-        final File bundleFile = new File(bundleFileName);
-        if (!bundleFile.canRead())
-        {
-            throw new IllegalArgumentException("Cannot read from boot file "
-                    + bundleFileName + " specified in the " + BUNDLE_JAR_SYS_PROP
-                    + " system property");
-        }
         return composite(
-                vmOption("-Xbootclasspath/a:"+bundleFile.getAbsolutePath()),
-                bootDelegationPackage("org.apache.felix.jaas.boot"),
                 streamBundle(createConfigBasedBundle())
         );
     }
@@ -88,18 +68,33 @@ public class ITJaasWithBootClasspath ext
      * code need not switch the TCCL
      */
     @Test
-    public void testJaasWithBoot() throws Exception
+    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();
 
-        CallbackHandler handler = new SimpleCallbackHandler("foo", "foo");
-        Configuration config = Configuration.getInstance("JavaLoginConfig", null,"FelixJaasProvider");
-        Subject s = new Subject();
+        //2. Validate the login passes with this config. Would not pass explicit config
+        CallbackHandler handler = new SimpleCallbackHandler("foo","foo");
 
-        LoginContext lc = new LoginContext(realmName, s, handler, config);
-        lc.login();
+        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());
     }



Mime
View raw message