felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1399574 [1/2] - in /felix/trunk: ./ jaas/ jaas/src/ jaas/src/main/ jaas/src/main/java/ jaas/src/main/java/org/ jaas/src/main/java/org/apache/ jaas/src/main/java/org/apache/felix/ jaas/src/main/java/org/apache/felix/jaas/ jaas/src/main/java...
Date Thu, 18 Oct 2012 10:10:09 GMT
Author: fmeschbe
Date: Thu Oct 18 10:10:08 2012
New Revision: 1399574

URL: http://svn.apache.org/viewvc?rev=1399574&view=rev
Log:
FELIX-3705 import new JAAS OSGi support (contributed by Chetan Mehrotra, thank you very much)

Added:
    felix/trunk/jaas/   (with props)
    felix/trunk/jaas/pom.xml
    felix/trunk/jaas/src/
    felix/trunk/jaas/src/main/
    felix/trunk/jaas/src/main/java/
    felix/trunk/jaas/src/main/java/org/
    felix/trunk/jaas/src/main/java/org/apache/
    felix/trunk/jaas/src/main/java/org/apache/felix/
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginContextFactory.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginModuleFactory.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/ProxyLoginModule.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/package-info.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/BundleLoginModuleCreator.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigLoginModuleProvider.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ControlFlag.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasConfigFactory.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Logger.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleCreator.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleProvider.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/OsgiLoginModuleProvider.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Util.java
    felix/trunk/jaas/src/main/java/org/apache/felix/jaas/package-info.java
    felix/trunk/jaas/src/main/resources/
    felix/trunk/jaas/src/main/resources/OSGI-INF/
    felix/trunk/jaas/src/main/resources/OSGI-INF/l10n/
    felix/trunk/jaas/src/main/resources/OSGI-INF/l10n/bundle.properties
    felix/trunk/jaas/src/main/resources/OSGI-INF/metatype/
    felix/trunk/jaas/src/main/resources/OSGI-INF/metatype/metatype.properties
Modified:
    felix/trunk/pom.xml

Propchange: felix/trunk/jaas/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Oct 18 10:10:08 2012
@@ -0,0 +1,4 @@
+.project
+.classpath
+.settings
+target

Added: felix/trunk/jaas/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/pom.xml?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/pom.xml (added)
+++ felix/trunk/jaas/pom.xml Thu Oct 18 10:10:08 2012
@@ -0,0 +1,230 @@
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+     <parent>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>felix-parent</artifactId>
+        <version>2.1</version>
+        <relativePath>../pom/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.felix.jaas</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Felix JAAS Support</name>
+    <description />
+
+     <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/jaas</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/trunk/jaas</developerConnection>
+        <url>http://svn.apache.org/repos/asf/felix/jaas</url>
+    </scm>
+
+    <properties>
+    </properties>
+    
+    <build>
+        <plugins>
+            <!--
+                We do not use DS but the SCR plugin is used to generate the
+                metatype.xml from the SCR annotations
+            -->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.7.4</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-scrdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <!-- We use the new JDK 1.6 ConfigurationSpi API so can set the version to 1.6-->
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.3.7</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>
+                            ${project.artifactId}
+                        </Bundle-SymbolicName>
+                        <Bundle-Vendor>
+                            The Apache Software Foundation
+                        </Bundle-Vendor>
+                        <Bundle-Activator>
+                            org.apache.felix.jaas.internal.Activator
+                        </Bundle-Activator>
+                        <_removeheaders>
+                            Embed-Dependency,Private-Package,Include-Resource
+                        </_removeheaders>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <!-- Create jar which can be put in boot classpath to enable use of
+            ProxyLoginModule in normal JAAS mode of authentication -->
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                <execution>
+                    <id>boot-library</id>
+                    <goals><goal>jar</goal></goals>
+                    <phase>package</phase>
+                    <configuration>
+                        <classifier>boot</classifier>
+                        <includes>
+                            <include>org/apache/felix/jaas/boot/*.class</include>
+                            <include>META-INF/NOTICE</include>
+                            <include>META-INF/DEPENDENCIES</include>
+                            <include>META-INF/LICENSE</include>
+                        </includes>
+                    </configuration>
+                </execution>
+            </executions>
+            </plugin>
+
+            <!-- Required for pax exam-->
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>depends-maven-plugin</artifactId>
+                <version>1.2</version>
+                <executions>
+                    <execution>
+                        <id>generate-depends-file</id>
+                        <goals>
+                            <goal>generate-depends-file</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>biz.aQute</groupId>
+            <artifactId>bndlib</artifactId>
+            <version>1.50.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.6.0</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.3</version>
+        </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+            <version>4.10</version>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <!--
+            copy the package such that IDEs may easily use it without
+            setting the system property
+        -->
+        <profile>
+            <id>ide</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-antrun-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>scr-file-create</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>run</goal>
+                                </goals>
+                                <configuration>
+                                    <target>
+                                        <copy file="${project.build.directory}/${project.build.finalName}.jar"
+                                              tofile="${project.build.directory}/jaas.jar" />
+                                        <copy file="${project.build.directory}/${project.build.finalName}-boot.jar"
+                                              tofile="${project.build.directory}/jaas-boot.jar" />
+                                    </target>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <profile>
+            <id>felix</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>org.apache.felix.framework</artifactId>
+                    <version>4.0.2</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>equinox</id>
+            <dependencies>
+                <dependency>
+                    <groupId>org.eclipse</groupId>
+                    <artifactId>osgi</artifactId>
+                    <version>3.7.1.R37x_v20110808-1106</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+</project>

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginContextFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginContextFactory.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginContextFactory.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginContextFactory.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+
+public interface LoginContextFactory
+{
+
+    LoginContext createLoginContext(String realm, Subject subject, CallbackHandler handler) throws LoginException;
+
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginModuleFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginModuleFactory.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginModuleFactory.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/LoginModuleFactory.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import javax.security.auth.spi.LoginModule;
+
+
+/**
+ * User: chetanm
+ * Date: 7/9/12
+ * Time: 5:43 PM
+ */
+public interface LoginModuleFactory
+{
+
+    String JAAS_CONTROL_FLAG = "jaas.controlFlag";
+    String JAAS_REALM_NAME = "jaas.realmName";
+
+    LoginModule createLoginModule();
+
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/ProxyLoginModule.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/ProxyLoginModule.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/ProxyLoginModule.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/ProxyLoginModule.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,78 @@
+/*
+ * 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.boot;
+
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+
+public class ProxyLoginModule implements LoginModule
+{
+    public static final String PROP_LOGIN_MODULE_FACTORY = "org.apache.felix.jaas.LoginModuleFactory";
+
+    private LoginModule delegate;
+
+    public void initialize(Subject subject, CallbackHandler callbackHandler,
+        Map<String, ?> sharedState, Map<String, ?> options)
+    {
+        BootLoginModuleFactory factory = (BootLoginModuleFactory) options.get(PROP_LOGIN_MODULE_FACTORY);
+        if (factory == null)
+        {
+            throw new IllegalStateException("Specify LoginModuleFactory through ["
+                + PROP_LOGIN_MODULE_FACTORY
+                + "] property as part of configuration options");
+        }
+        delegate = factory.createLoginModule();
+        delegate.initialize(subject, callbackHandler, sharedState, options);
+    }
+
+    public boolean login() throws LoginException
+    {
+        return delegate.login();
+    }
+
+    public boolean commit() throws LoginException
+    {
+        return delegate.commit();
+    }
+
+    public boolean abort() throws LoginException
+    {
+        return delegate.abort();
+    }
+
+    public boolean logout() throws LoginException
+    {
+        return delegate.logout();
+    }
+
+    /**
+     * Factory interface to create LoginModule instance. This is exactly same as
+     * LoginModuleFactory. This is done to keep the boot package self sufficient
+     */
+    public static interface BootLoginModuleFactory
+    {
+        LoginModule createLoginModule();
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/package-info.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/package-info.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/package-info.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/boot/package-info.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides support for performing JAAS based authentication in OSGi
+ *
+ * @version 1.0
+ */
+@Version("1.0")
+@Export(optional = "provide:=true")
+package org.apache.felix.jaas.boot;
+
+import aQute.bnd.annotation.Version;
+import aQute.bnd.annotation.Export;

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.internal;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator
+{
+
+    private BundleLoginModuleCreator loginModuleCreator;
+    private JaasConfigFactory jaasConfigFactory;
+    private ConfigSpiOsgi configSpi;
+    private JaasWebConsolePlugin webConsolePlugin;
+    private Logger logger;
+
+    @Override
+    public void start(BundleContext context) throws Exception
+    {
+        logger = new Logger(context);
+        loginModuleCreator = new BundleLoginModuleCreator(context, logger);
+        jaasConfigFactory = new JaasConfigFactory(context, loginModuleCreator, logger);
+        configSpi = new ConfigSpiOsgi(context, logger);
+        webConsolePlugin = new JaasWebConsolePlugin(context, configSpi,
+            loginModuleCreator);
+
+        logger.open();
+        loginModuleCreator.open();
+        configSpi.open();
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception
+    {
+        if (loginModuleCreator != null)
+        {
+            loginModuleCreator.close();
+        }
+
+        if (configSpi != null)
+        {
+            configSpi.close();
+        }
+
+        if (logger != null)
+        {
+            logger.close();
+        }
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/BundleLoginModuleCreator.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/BundleLoginModuleCreator.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/BundleLoginModuleCreator.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/BundleLoginModuleCreator.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,212 @@
+/*
+ * 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.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.security.auth.spi.LoginModule;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTracker;
+
+class BundleLoginModuleCreator extends BundleTracker implements LoginModuleCreator
+{
+
+    private static final String JAAS_MODULE_CLASS = "Jaas-ModuleClass";
+
+    private final Map<String, LoginModuleInfo> loginModuleInfo = new ConcurrentHashMap<String, LoginModuleInfo>();
+
+    private final Logger log;
+
+    public BundleLoginModuleCreator(BundleContext context, Logger log)
+    {
+        super(context, Bundle.ACTIVE, null /* customizer */);
+        this.log = log;
+    }
+
+    public LoginModule newInstance(String className)
+    {
+        LoginModuleInfo lmInfo = loginModuleInfo.get(className);
+
+        //TODO Rethink about exception handling. Probably introduce custom exception classes
+        if (lmInfo == null)
+        {
+            throw new AssertionError("No bundle exists to create LoginModule from "
+                + className);
+        }
+
+        try
+        {
+            return lmInfo.newInstance();
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new RuntimeException("Error occurred while creating LoginModule for "
+                + className, e);
+        }
+        catch (InstantiationException e)
+        {
+            throw new RuntimeException("Error occurred while creating LoginModule for "
+                + className, e);
+        }
+    }
+
+    public Map<Bundle, Set<String>> getBundleToLoginModuleMapping()
+    {
+        //With R5 we could have used Map<Bundle, T> BundleTracker.getTracked()
+        //Determine the bundle -> login module classes map
+        Map<Bundle, Set<String>> bundleMap = new HashMap<Bundle, Set<String>>();
+        for (LoginModuleInfo e : loginModuleInfo.values())
+        {
+            Bundle b = e.getBundle();
+            @SuppressWarnings("unchecked")
+            Set<String> classNames = (Set<String>) getObject(b);
+
+            if (classNames == null)
+            {
+                continue;
+            }
+            bundleMap.put(b, classNames);
+        }
+        return bundleMap;
+    }
+
+    // ---------- BundleTracker integration ----------------------------------------------
+
+    @Override
+    public Object addingBundle(Bundle bundle, BundleEvent event)
+    {
+        if (providesLoginModule(bundle))
+        {
+            return registerBundle(bundle);
+        }
+        return null;
+    }
+
+    @Override
+    public void removedBundle(Bundle bundle, BundleEvent event, Object object)
+    {
+        @SuppressWarnings("unchecked")
+        Set<String> classNames = (Set<String>) object;
+
+        for (String className : classNames)
+        {
+            loginModuleInfo.remove(className);
+        }
+    }
+
+    private boolean providesLoginModule(Bundle bundle)
+    {
+        return bundle.getHeaders().get(JAAS_MODULE_CLASS) != null;
+    }
+
+    private Set<String> registerBundle(Bundle bundle)
+    {
+        Set<String> classNames = Util.parseHeader((String) bundle.getHeaders().get(
+            JAAS_MODULE_CLASS));
+        for (String className : classNames)
+        {
+            LoginModuleInfo bi = new LoginModuleInfo(className, bundle, log);
+            if (bi.isValid())
+            {
+
+                //Duplicate registration check
+                if (loginModuleInfo.containsKey(className))
+                {
+                    LoginModuleInfo existingInfo = loginModuleInfo.get(className);
+                    String msg = String.format(
+                        "LoginModule class %s is already registered with Bundle %s. Entry "
+                            + "from bundle %s would be ignored", className,
+                        existingInfo.getBundle(), bundle);
+                    log.log(LogService.LOG_WARNING, msg);
+                    continue;
+                }
+
+                loginModuleInfo.put(className, bi);
+                log.log(LogService.LOG_INFO, "Registering LoginModule class ["
+                    + className + "] from Bundle" + bundle);
+            }
+            else
+            {
+                log.log(LogService.LOG_WARNING,
+                    "Could not load LoginModule class " + bi.getClassName()
+                        + " from bundle " + bundle);
+            }
+        }
+        return classNames;
+    }
+
+    static final class LoginModuleInfo
+    {
+        private final String className;
+        private final Bundle bundle;
+        private final Class<LoginModule> clazz;
+
+        @SuppressWarnings("unchecked")
+        public LoginModuleInfo(String className, Bundle bundle, Logger log)
+        {
+            this.className = className;
+            this.bundle = bundle;
+
+            Class<LoginModule> clazz = null;
+            try
+            {
+                clazz = bundle.loadClass(className);
+            }
+            catch (ClassNotFoundException e)
+            {
+                log.log(LogService.LOG_WARNING, "Error loading class [" + className
+                    + "] from bundle " + bundle, e);
+            }
+            this.clazz = clazz;
+        }
+
+        public LoginModule newInstance() throws IllegalAccessException,
+            InstantiationException
+        {
+            if (clazz == null)
+            {
+                throw new IllegalStateException("LoginModule class not initialized");
+            }
+            return clazz.newInstance();
+        }
+
+        public boolean isValid()
+        {
+            return clazz != null;
+        }
+
+        public String getClassName()
+        {
+            return className;
+        }
+
+        public Bundle getBundle()
+        {
+            return bundle;
+        }
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigLoginModuleProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigLoginModuleProvider.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigLoginModuleProvider.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigLoginModuleProvider.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,88 @@
+/*
+ * 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.internal;
+
+import static javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+
+import java.util.Collections;
+import java.util.Map;
+
+import javax.security.auth.spi.LoginModule;
+
+
+final class ConfigLoginModuleProvider implements LoginModuleProvider
+{
+    private final Map options;
+    private final LoginModuleControlFlag controlFlag;
+    private final int ranking;
+    private final String realmName;
+    private final String className;
+    private final LoginModuleCreator moduleCreator;
+
+    @SuppressWarnings("unchecked")
+    ConfigLoginModuleProvider(String realmName, String className, Map options, LoginModuleControlFlag controlFlag, int order, LoginModuleCreator moduleCreator)
+    {
+        this.options = Collections.unmodifiableMap(options);
+        this.controlFlag = controlFlag;
+        this.ranking = order;
+        this.realmName = realmName;
+        this.className = className;
+        this.moduleCreator = moduleCreator;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Map<String, ?> options()
+    {
+        return options;
+    }
+
+    public LoginModuleControlFlag getControlFlag()
+    {
+        return controlFlag;
+    }
+
+    public int ranking()
+    {
+        return ranking;
+    }
+
+    public String realmName()
+    {
+        return realmName;
+    }
+
+    public String getClassName()
+    {
+        return className;
+    }
+
+    public LoginModule createLoginModule()
+    {
+        return moduleCreator.newInstance(className);
+    }
+
+    @Override
+    public String toString()
+    {
+        return "ConfigLoginModuleProvider{" + "flag=" + controlFlag + ", ranking="
+            + ranking + ", realmName='" + realmName + '\'' + ", className='" + className
+            + '\'' + '}';
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,591 @@
+/*
+ * 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.internal;
+
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.*;
+
+import org.apache.felix.jaas.LoginContextFactory;
+import org.apache.felix.jaas.LoginModuleFactory;
+import org.apache.felix.jaas.boot.ProxyLoginModule;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyOption;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+@Component(label = "%jaas.spi.name", description = "%jaas.spi.description", metatype = true, ds = false, name = "org.apache.felix.jaas.ConfigurationSpi", policy = ConfigurationPolicy.REQUIRE)
+public class ConfigSpiOsgi extends ConfigurationSpi implements ManagedService, ServiceTrackerCustomizer, LoginContextFactory
+{
+    /**
+     * Name of the algorithm to use to fetch JAAS Config
+     */
+    public static final String JAAS_CONFIG_ALGO_NAME = "JavaLoginConfig";
+
+    public static final String SERVICE_PID = "org.apache.felix.jaas.ConfigurationSpi";
+
+    private static enum GlobalConfigurationPolicy
+    {
+        DEFAULT, REPLACE, PROXY
+    }
+
+    private Map<String, Realm> configs = Collections.emptyMap();
+
+    private final Logger log;
+
+    @Property
+    private static final String JAAS_DEFAULT_REALM_NAME = "jaas.defaultRealmName";
+    private String defaultRealmName;
+
+    private static final String DEFAULT_CONFIG_PROVIDER_NAME = "FelixJaasProvider";
+    @Property(value = DEFAULT_CONFIG_PROVIDER_NAME)
+    private static final String JAAS_CONFIG_PROVIDER_NAME = "jaas.configProviderName";
+
+    @Property(value = "default", options = {
+            @PropertyOption(name = "default", value = "%jaas.configPolicy.default"),
+            @PropertyOption(name = "replace", value = "%jaas.configPolicy.replace"),
+            @PropertyOption(name = "proxy", value = "%jaas.configPolicy.proxy") })
+    static final String JAAS_CONFIG_POLICY = "jaas.globalConfigPolicy";
+
+    private final Configuration osgiConfig = new OsgiConfiguration();
+
+    private final Configuration originalConfig;
+
+    private final Configuration proxyConfig;
+
+    private volatile GlobalConfigurationPolicy globalConfigPolicy = GlobalConfigurationPolicy.DEFAULT;
+
+    private final Map<ServiceReference, LoginModuleProvider> providerMap = new ConcurrentHashMap<ServiceReference, LoginModuleProvider>();
+
+    private volatile String jaasConfigProviderName;
+
+    private final Object lock = new Object();
+
+    private final BundleContext context;
+
+    private final ServiceTracker tracker;
+
+    private ServiceRegistration spiReg;
+
+    public ConfigSpiOsgi(BundleContext context, Logger log)
+    {
+        this.context = context;
+        this.log = log;
+        this.tracker = new ServiceTracker(context, LoginModuleFactory.class.getName(),
+            this);
+
+        Properties props = new Properties();
+        props.setProperty(Constants.SERVICE_VENDOR, "Apache Software Foundation");
+        props.setProperty(Constants.SERVICE_PID, SERVICE_PID);
+
+        this.context.registerService(ManagedService.class.getName(), this, props);
+
+        //TODO Should this registration be made conditional i.e. service is only registered
+        //only if there active LoginModules present
+        this.context.registerService(LoginContextFactory.class.getName(), this, new Properties());
+
+        this.originalConfig = getGlobalConfiguration();
+        this.proxyConfig = new DelegatingConfiguration(osgiConfig, originalConfig);
+    }
+
+    @Override
+    public LoginContext createLoginContext(String realm, Subject subject,
+        CallbackHandler handler) throws LoginException
+    {
+        if (realm == null)
+        {
+            realm = defaultRealmName;
+        }
+
+        final Thread currentThread = Thread.currentThread();
+        final ClassLoader cl = currentThread.getContextClassLoader();
+        try
+        {
+            currentThread.setContextClassLoader(ProxyLoginModule.class.getClassLoader());
+            Configuration config = Configuration.getInstance("JavaLoginConfig", null,
+                jaasConfigProviderName);
+            return new LoginContext(realm, subject, handler, config);
+        }
+        catch (NoSuchProviderException e)
+        {
+            throw new LoginException(e.getMessage());
+        }
+        catch (NoSuchAlgorithmException e)
+        {
+            throw new LoginException(e.getMessage());
+        }
+        finally
+        {
+            currentThread.setContextClassLoader(cl);
+        }
+    }
+
+    @Override
+    protected AppConfigurationEntry[] engineGetAppConfigurationEntry(String name)
+    {
+        Realm realm = configs.get(name);
+        if (realm == null)
+        {
+            log.log(LogService.LOG_WARNING, "No JAAS module configured for realm " + name);
+            return null;
+        }
+
+        return realm.engineGetAppConfigurationEntry();
+    }
+
+    Map<String, Realm> getAllConfiguration()
+    {
+        return configs;
+    }
+
+    private void recreateConfigs()
+    {
+        Map<String, Realm> realmToConfigMap = new HashMap<String, Realm>();
+        for (LoginModuleProvider lmp : providerMap.values())
+        {
+            String realmName = lmp.realmName();
+            if (realmName == null)
+            {
+                realmName = defaultRealmName;
+            }
+
+            Realm realm = realmToConfigMap.get(realmName);
+            if (realm == null)
+            {
+                realm = new Realm(realmName);
+                realmToConfigMap.put(realmName, realm);
+            }
+
+            realm.add(new AppConfigurationHolder(lmp));
+        }
+
+        for (Realm realm : realmToConfigMap.values())
+        {
+            realm.afterPropertiesSet();
+        }
+
+        //We also register the Spi with OSGI SR if any configuration is available
+        //This would allow any client component to determine when it should start
+        //and use the config
+        if (!realmToConfigMap.isEmpty() && spiReg == null)
+        {
+            Properties props = new Properties();
+            props.setProperty("providerName", "felix");
+
+            synchronized (lock)
+            {
+                spiReg = context.registerService(ConfigurationSpi.class.getName(), this,
+                    props);
+            }
+        }
+
+        synchronized (lock)
+        {
+            this.configs = Collections.unmodifiableMap(realmToConfigMap);
+        }
+    }
+
+    //--------------LifeCycle methods -------------------------------------
+
+    void open()
+    {
+        this.tracker.open();
+        this.configs = Collections.emptyMap();
+    }
+
+    void close()
+    {
+        this.tracker.close();
+        deregisterProvider(jaasConfigProviderName);
+
+        synchronized (lock)
+        {
+            providerMap.clear();
+            configs = null; //Cannot call clear as its an unmodifiable map
+        }
+
+        if (globalConfigPolicy != GlobalConfigurationPolicy.DEFAULT)
+        {
+            restoreOriginalConfiguration();
+        }
+    }
+
+    // --------------Config handling ----------------------------------------
+
+    @Override
+    public synchronized void updated(Dictionary properties) throws ConfigurationException
+    {
+        //TODO Do not know but for fresh install it is null
+        if (properties == null)
+        {
+            return;
+        }
+        String newDefaultRealmName = Util.toString(
+            properties.get(JAAS_DEFAULT_REALM_NAME), null);
+        if (newDefaultRealmName == null)
+        {
+            throw new IllegalArgumentException(
+                "Default JAAS realm name must be specified");
+        }
+
+        if (!newDefaultRealmName.equals(defaultRealmName))
+        {
+            defaultRealmName = newDefaultRealmName;
+            recreateConfigs();
+        }
+
+        String newProviderName = Util.toString(properties.get(JAAS_CONFIG_PROVIDER_NAME),
+            DEFAULT_CONFIG_PROVIDER_NAME);
+
+        deregisterProvider(jaasConfigProviderName);
+        registerProvider(newProviderName);
+        jaasConfigProviderName = newProviderName;
+
+        manageGlobalConfiguration(properties);
+    }
+
+    private void manageGlobalConfiguration(Dictionary props)
+    {
+        String configPolicy = Util.toString(props.get(JAAS_CONFIG_POLICY),
+                GlobalConfigurationPolicy.DEFAULT.name());
+        configPolicy = Util.trimToNull(configPolicy);
+
+        GlobalConfigurationPolicy policy = GlobalConfigurationPolicy.DEFAULT;
+        if (configPolicy != null)
+        {
+            policy = GlobalConfigurationPolicy.valueOf(configPolicy.toUpperCase());
+        }
+
+        this.globalConfigPolicy = policy;
+
+        if (policy == GlobalConfigurationPolicy.REPLACE)
+        {
+            Configuration.setConfiguration(osgiConfig);
+            log.log(LogService.LOG_INFO,
+                "Replacing the global JAAS configuration with OSGi based configuration");
+        }
+        else if (policy == GlobalConfigurationPolicy.PROXY)
+        {
+            Configuration.setConfiguration(proxyConfig);
+            log.log(
+                LogService.LOG_INFO,
+                "Replacing the global JAAS configuration with OSGi based proxy configuration. "
+                    + "It would look first in the OSGi based configuration and if not found would use the default global "
+                    + "configuration");
+        }
+        else if (policy == GlobalConfigurationPolicy.DEFAULT)
+        {
+            restoreOriginalConfiguration();
+        }
+    }
+
+    private void restoreOriginalConfiguration()
+    {
+        if (originalConfig == null)
+        {
+            return;
+        }
+
+        Configuration current = Configuration.getConfiguration();
+        if (current != originalConfig)
+        {
+            Configuration.setConfiguration(originalConfig);
+        }
+    }
+
+    // --------------JAAS/JCA/Security ----------------------------------------
+
+    private void registerProvider(String providerName)
+    {
+        Security.addProvider(new OSGiProvider(providerName));
+        log.log(LogService.LOG_INFO, "Registered provider " + providerName
+            + " for managing JAAS config with type " + JAAS_CONFIG_ALGO_NAME);
+    }
+
+    private void deregisterProvider(String providerName)
+    {
+        Security.removeProvider(providerName);
+        log.log(LogService.LOG_INFO, "Removed provider " + providerName + " type "
+            + JAAS_CONFIG_ALGO_NAME + " from Security providers list");
+    }
+
+    // ---------- ServiceTracker ----------------------------------------------
+
+    @Override
+    public Object addingService(ServiceReference reference)
+    {
+        LoginModuleFactory lmf = (LoginModuleFactory) context.getService(reference);
+        registerFactory(reference, lmf);
+        recreateConfigs();
+        return lmf;
+    }
+
+    @Override
+    public void modifiedService(ServiceReference reference, Object service)
+    {
+        recreateConfigs();
+    }
+
+    @Override
+    public void removedService(ServiceReference reference, Object service)
+    {
+        deregisterFactory(reference);
+        recreateConfigs();
+        context.ungetService(reference);
+    }
+
+    private void deregisterFactory(ServiceReference ref)
+    {
+        LoginModuleProvider lmp = providerMap.remove(ref);
+        if (lmp != null)
+        {
+            log.log(LogService.LOG_INFO, "Deregistering LoginModuleFactory " + lmp);
+        }
+    }
+
+    private void registerFactory(ServiceReference ref, LoginModuleFactory lmf)
+    {
+        LoginModuleProvider lmfExt;
+        if (lmf instanceof LoginModuleProvider)
+        {
+            lmfExt = (LoginModuleProvider) lmf;
+        }
+        else
+        {
+            lmfExt = new OsgiLoginModuleProvider(ref, lmf);
+        }
+        log.log(LogService.LOG_INFO, "Registering LoginModuleFactory " + lmf);
+        providerMap.put(ref, lmfExt);
+    }
+
+    private static Configuration getGlobalConfiguration()
+    {
+        try
+        {
+            return Configuration.getConfiguration();
+        }
+        catch (Exception e)
+        {
+            // means no JAAS configuration file OR no permission to read it
+        }
+        return null;
+    }
+
+    private class OSGiProvider extends Provider
+    {
+        public static final String TYPE_CONFIGURATION = "Configuration";
+
+        OSGiProvider(String providerName)
+        {
+            super(providerName, 1.0, "OSGi based provider for Jaas configuration");
+        }
+
+        @Override
+        public synchronized Service getService(String type, String algorithm)
+        {
+            if (TYPE_CONFIGURATION.equals(type)
+                && JAAS_CONFIG_ALGO_NAME.equals(algorithm))
+            {
+                return new ConfigurationService(this);
+            }
+            return super.getService(type, algorithm);
+        }
+    }
+
+    private class ConfigurationService extends Provider.Service
+    {
+
+        public ConfigurationService(Provider provider)
+        {
+            super(provider, OSGiProvider.TYPE_CONFIGURATION, //the type of this service
+                JAAS_CONFIG_ALGO_NAME, //the algorithm name
+                ConfigSpiOsgi.class.getName(), //the name of the class implementing this service
+                Collections.<String> emptyList(), //List of aliases or null if algorithm has no aliases
+                Collections.<String, String> emptyMap()); //Map of attributes or null if this implementation
+        }
+
+        @Override
+        public Object newInstance(Object constructorParameter)
+            throws NoSuchAlgorithmException
+        {
+            //constructorParameter is the one which is passed as Configuration.Parameters params
+            //for now we do not make use of that
+            return ConfigSpiOsgi.this;
+        }
+    }
+
+    //---------------------------- Global Configuration Handling
+
+    private class OsgiConfiguration extends Configuration
+    {
+
+        @Override
+        public AppConfigurationEntry[] getAppConfigurationEntry(String name)
+        {
+            return ConfigSpiOsgi.this.engineGetAppConfigurationEntry(name);
+        }
+    }
+
+    private class DelegatingConfiguration extends Configuration
+    {
+        private final Configuration primary;
+        private final Configuration secondary;
+
+        private DelegatingConfiguration(Configuration primary, Configuration secondary)
+        {
+            this.primary = primary;
+            this.secondary = secondary;
+        }
+
+        @Override
+        public AppConfigurationEntry[] getAppConfigurationEntry(String name)
+        {
+            // check if jaas-loginModule or fallback is configured
+            AppConfigurationEntry[] result = null;
+            try
+            {
+                result = primary.getAppConfigurationEntry(name);
+            }
+            catch (Exception e)
+            {
+                // means no JAAS configuration file OR no permission to read it
+            }
+
+            if (result == null)
+            {
+                try
+                {
+                    result = secondary.getAppConfigurationEntry(name);
+                }
+                catch (Exception e)
+                {
+                    // WLP 9.2.0 throws IllegalArgumentException for unknown appName
+                }
+            }
+
+            return result;
+        }
+    }
+
+    //-------------------------------------OSGi Config Management
+
+    static final class Realm
+    {
+        private final String realmName;
+        private AppConfigurationEntry[] configArray;
+        private List<AppConfigurationHolder> configs = new ArrayList<AppConfigurationHolder>();
+
+        Realm(String realmName)
+        {
+            this.realmName = realmName;
+        }
+
+        public void add(AppConfigurationHolder config)
+        {
+            configs.add(config);
+        }
+
+        public void afterPropertiesSet()
+        {
+            Collections.sort(configs);
+            configArray = new AppConfigurationEntry[configs.size()];
+            for (int i = 0; i < configs.size(); i++)
+            {
+                configArray[i] = configs.get(i).getEntry();
+            }
+            configs = Collections.unmodifiableList(configs);
+        }
+
+        public String getRealmName()
+        {
+            return realmName;
+        }
+
+        public List<AppConfigurationHolder> getConfigs()
+        {
+            return configs;
+        }
+
+        public AppConfigurationEntry[] engineGetAppConfigurationEntry()
+        {
+            return Arrays.copyOf(configArray, configArray.length);
+        }
+
+        @Override
+        public String toString()
+        {
+            return "Realm{" + "realmName='" + realmName + '\'' + '}';
+        }
+    }
+
+    static final class AppConfigurationHolder implements Comparable<AppConfigurationHolder>
+    {
+        private static final String LOGIN_MODULE_CLASS = ProxyLoginModule.class.getName();
+        private final LoginModuleProvider provider;
+        private final int ranking;
+        private final AppConfigurationEntry entry;
+
+        public AppConfigurationHolder(LoginModuleProvider provider)
+        {
+            this.provider = provider;
+            this.ranking = provider.ranking();
+
+            Map<String, Object> options = new HashMap<String, Object>(provider.options());
+            options.put(ProxyLoginModule.PROP_LOGIN_MODULE_FACTORY, provider);
+            this.entry = new AppConfigurationEntry(LOGIN_MODULE_CLASS,
+                provider.getControlFlag(), Collections.unmodifiableMap(options));
+        }
+
+        public int compareTo(AppConfigurationHolder that)
+        {
+            if (this.ranking == that.ranking)
+            {
+                return 0;
+            }
+            return this.ranking > that.ranking ? -1 : 1;
+        }
+
+        public AppConfigurationEntry getEntry()
+        {
+            return entry;
+        }
+
+        public LoginModuleProvider getProvider()
+        {
+            return provider;
+        }
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ControlFlag.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ControlFlag.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ControlFlag.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ControlFlag.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,80 @@
+/*
+ * 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.internal;
+
+import static javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+
+/**
+ * User: chetanm
+ * Date: 7/9/12
+ * Time: 9:55 PM
+ */
+@SuppressWarnings("UnusedDeclaration")
+enum ControlFlag
+{
+
+    REQUIRED(LoginModuleControlFlag.REQUIRED), REQUISITE(LoginModuleControlFlag.REQUISITE), SUFFICIENT(
+        LoginModuleControlFlag.SUFFICIENT), OPTIONAL(LoginModuleControlFlag.OPTIONAL), ;
+
+    private final LoginModuleControlFlag flag;
+
+    private ControlFlag(LoginModuleControlFlag flag)
+    {
+        this.flag = flag;
+    }
+
+    public LoginModuleControlFlag flag()
+    {
+        return flag;
+    }
+
+    public static ControlFlag from(String val)
+    {
+        val = Util.trimToNull(val);
+        if (val == null)
+        {
+            return REQUIRED;
+        }
+
+        val = val.toUpperCase();
+        return ControlFlag.valueOf(val);
+    }
+
+    public static String toString(LoginModuleControlFlag flag)
+    {
+        if (flag == LoginModuleControlFlag.REQUIRED)
+        {
+            return "REQUIRED";
+        }
+        else if (flag == LoginModuleControlFlag.REQUISITE)
+        {
+            return "REQUISITE";
+        }
+        else if (flag == LoginModuleControlFlag.SUFFICIENT)
+        {
+            return "SUFFICIENT";
+        }
+        else if (flag == LoginModuleControlFlag.OPTIONAL)
+        {
+            return "OPTIONAL";
+        }
+        throw new IllegalArgumentException("Unknown flag " + flag);
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasConfigFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasConfigFactory.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasConfigFactory.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasConfigFactory.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,171 @@
+/*
+ * 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.internal;
+
+import static org.apache.felix.jaas.internal.Util.trimToNull;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.felix.jaas.LoginModuleFactory;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyOption;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.log.LogService;
+
+@Component(label = "%jaas.name", description = "%jaas.description", metatype = true, ds = false, name = JaasConfigFactory.SERVICE_PID, configurationFactory = true)
+public class JaasConfigFactory implements ManagedServiceFactory
+{
+
+    public static final String SERVICE_PID = "org.apache.felix.jaas.Configuration.factory";
+
+    @Property
+    static final String JAAS_CLASS_NAME = "jaas.classname";
+
+    @Property(value = "required", options = {
+            @PropertyOption(name = "required", value = "%jaas.flag.required"),
+            @PropertyOption(name = "requisite", value = "%jaas.flag.requisite"),
+            @PropertyOption(name = "sufficient", value = "%jaas.flag.sufficient"),
+            @PropertyOption(name = "optional", value = "%jaas.flag.optional") })
+    static final String JAAS_CONTROL_FLAG = "jaas.controlFlag";
+
+    @Property(intValue = 0)
+    static final String JAAS_RANKING = "jaas.ranking";
+
+    @Property(unbounded = PropertyUnbounded.ARRAY)
+    static final String JAAS_OPTIONS = "jaas.options";
+
+    @Property
+    static final String JAAS_REALM_NAME = "jaas.realmName";
+
+    private final Logger log;
+
+    private final LoginModuleCreator factory;
+
+    private final BundleContext context;
+
+    private final Map<String, ServiceRegistration> registrations = new ConcurrentHashMap<String, ServiceRegistration>();
+
+    public JaasConfigFactory(BundleContext context, LoginModuleCreator factory, Logger log)
+    {
+        this.context = context;
+        this.factory = factory;
+        this.log = log;
+
+        Properties props = new Properties();
+        props.setProperty(Constants.SERVICE_VENDOR, "Apache Software Foundation");
+        props.setProperty(Constants.SERVICE_PID, SERVICE_PID);
+        context.registerService(ManagedServiceFactory.class.getName(), this, props);
+    }
+
+    @Override
+    public String getName()
+    {
+        return "JaasConfigFactory";
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void updated(String pid, Dictionary config) throws ConfigurationException
+    {
+        String className = trimToNull(Util.toString(config.get(JAAS_CLASS_NAME), null));
+        String flag = trimToNull(Util.toString(config.get(JAAS_CONTROL_FLAG), "required"));
+        int ranking = Util.toInteger(config.get(JAAS_RANKING), 0);
+
+        String[] props = Util.toStringArray(config.get(JAAS_OPTIONS), new String[0]);
+        Map options = toMap(props);
+        String realmName = trimToNull(Util.toString(config.get(JAAS_REALM_NAME), null));
+
+        if (className == null)
+        {
+            log.log(LogService.LOG_WARNING,
+                "Class name for the LoginModule is required. Configuration would be ignored"
+                    + config);
+            return;
+        }
+
+        //Combine the config. As the jaas.options is required for capturing config
+        //via felix webconsole. However in normal usage people would like to provide
+        //key=value pair directly in config. So merge both to provide a combined
+        //view
+        Map combinedOptions = convertToMap(config);
+        combinedOptions.putAll(options);
+
+        LoginModuleProvider lmf = new ConfigLoginModuleProvider(realmName, className,
+            combinedOptions, ControlFlag.from(flag).flag(), ranking, factory);
+
+        ServiceRegistration reg = context.registerService(
+            LoginModuleFactory.class.getName(), lmf, new Properties());
+        registrations.put(pid, reg);
+    }
+
+    @Override
+    public void deleted(String pid)
+    {
+        ServiceRegistration reg = registrations.remove(pid);
+        if (reg != null)
+        {
+            reg.unregister();
+        }
+    }
+
+    //~----------------------------------- Utility Methods
+
+    private static Map<String, Object> toMap(String[] props)
+    {
+        //TODO support system property substitution e.g. ${user.home}
+        //in property values
+        Map<String, Object> result = new HashMap<String, Object>();
+        for (String kv : props)
+        {
+            int indexOfEqual = kv.indexOf('=');
+            if (indexOfEqual > 0)
+            {
+                String key = trimToNull(kv.substring(0, indexOfEqual));
+                String value = trimToNull(kv.substring(indexOfEqual + 1));
+                if (key != null && value != null)
+                {
+                    result.put(key, value);
+                }
+            }
+        }
+        return result;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static Map convertToMap(Dictionary config)
+    {
+        Map copy = new HashMap();
+        Enumeration e = config.keys();
+        while (e.hasMoreElements())
+        {
+            Object key = e.nextElement();
+            Object value = config.get(key);
+            copy.put(key, value);
+        }
+        return copy;
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,292 @@
+/*
+ * 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.internal;
+
+import static org.apache.felix.jaas.internal.ConfigSpiOsgi.AppConfigurationHolder;
+import static org.apache.felix.jaas.internal.ConfigSpiOsgi.Realm;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+public class JaasWebConsolePlugin extends HttpServlet
+{
+
+    private final ConfigSpiOsgi configSpi;
+
+    private final BundleLoginModuleCreator loginModuleCreator;
+
+    public JaasWebConsolePlugin(BundleContext context, ConfigSpiOsgi configSpi, BundleLoginModuleCreator loginModuleCreator)
+    {
+        this.configSpi = configSpi;
+        this.loginModuleCreator = loginModuleCreator;
+
+        Properties props = new Properties();
+        props.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
+        props.put(Constants.SERVICE_DESCRIPTION, "JAAS Web Console Plugin");
+        props.put("felix.webconsole.label", "jaas");
+        props.put("felix.webconsole.title", "JAAS");
+        props.put("felix.webconsole.configprinter.modes", "always");
+        context.registerService(Servlet.class.getName(), this, props);
+    }
+
+    @Override
+    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
+        throws ServletException, IOException
+    {
+        if (req.getPathInfo().endsWith("/data.json"))
+        {
+            getJson(resp);
+        }
+        else
+        {
+            getHtml(resp);
+        }
+
+    }
+
+    private void getHtml(HttpServletResponse resp) throws IOException
+    {
+        final PrintWriter pw = resp.getWriter();
+
+        printAppConfigurationDetails(pw);
+        printAvailableModuleDetails(pw);
+
+    }
+
+    private void printAvailableModuleDetails(PrintWriter pw)
+    {
+        Map<Bundle, Set<String>> bundleMap = getAvailableLoginModuleInfo();
+
+        pw.println("<p class=\"statline ui-state-highlight\">${Available LoginModules}</p>");
+        if (bundleMap.isEmpty())
+        {
+            return;
+        }
+
+        pw.println("<table class=\"nicetable\">");
+        pw.println("<thead><tr>");
+        pw.println("<th class=\"header\">${Bundle}</th>");
+        pw.println("<th class=\"header\">${Classes}</th>");
+        pw.println("</tr></thead>");
+
+        String rowClass = "odd";
+        for (Map.Entry<Bundle, Set<String>> e : bundleMap.entrySet())
+        {
+            Bundle b = e.getKey();
+            pw.print("<tr class=\"%s ui-state-default\">");
+            pw.printf("<td><a href=\"${pluginRoot}/../bundles/%s\">%s (%s)</a></td>",
+                b.getBundleId(), b.getSymbolicName(), b.getBundleId());
+            pw.printf("<td>");
+            for (String className : e.getValue())
+            {
+                pw.print(className);
+                pw.print("<br/>");
+            }
+            pw.print("</td>");
+            pw.println("</tr>");
+
+            if (rowClass.equals("odd"))
+            {
+                rowClass = "even";
+            }
+            else
+            {
+                rowClass = "odd";
+            }
+        }
+        pw.println("</table>");
+    }
+
+    private void printAppConfigurationDetails(PrintWriter pw)
+    {
+        Map<String, Realm> configs = getConfigurationDetails();
+        if (configs.isEmpty())
+        {
+            pw.println("No JAAS LoginModule registered");
+            return;
+        }
+
+        pw.println("<p class=\"statline ui-state-highlight\">${Registered LoginModules}</p>");
+
+        pw.println("<table class=\"nicetable\">");
+        pw.println("<thead><tr>");
+        pw.println("<th class=\"header\">${Realm}</th>");
+        pw.println("<th class=\"header\">${Rank}</th>");
+        pw.println("<th class=\"header\">${Control Flag}</th>");
+        pw.println("<th class=\"header\">${Type}</th>");
+        pw.println("<th class=\"header\">${Classname}</th>");
+        pw.println("</tr></thead>");
+
+        for (Realm r : configs.values())
+        {
+            String realmName = r.getRealmName();
+            pw.printf(
+                "<tr class=\"ui-state-default\"><td>%s</td><td colspan=\"4\"></td></tr>",
+                realmName);
+
+            String rowClass = "odd";
+            for (AppConfigurationHolder ah : r.getConfigs())
+            {
+                LoginModuleProvider lp = ah.getProvider();
+                String type = getType(lp);
+                pw.printf("<tr class=\"%s ui-state-default\"><td></td><td>%d</td>",
+                    rowClass, lp.ranking());
+                pw.printf("<td>%s</td>", ControlFlag.toString(lp.getControlFlag()));
+                pw.printf("<td>%s</td>", type);
+
+                pw.printf("<td>");
+                pw.print(lp.getClassName());
+
+                if (lp instanceof OsgiLoginModuleProvider)
+                {
+                    ServiceReference sr = ((OsgiLoginModuleProvider) lp).getServiceReference();
+                    Object id = sr.getProperty(Constants.SERVICE_ID);
+                    pw.printf("<a href=\"${pluginRoot}/../services/%s\">(%s)</a>", id, id);
+                }
+                else if (lp instanceof ConfigLoginModuleProvider)
+                {
+                    Map config = lp.options();
+                    Object id = config.get(Constants.SERVICE_PID);
+                    pw.printf("<a href=\"${pluginRoot}/../configMgr/%s\">(Details)</a>",
+                        id);
+                }
+                pw.printf("</td>");
+
+                pw.println("</tr>");
+                if (rowClass.equals("odd"))
+                {
+                    rowClass = "even";
+                }
+                else
+                {
+                    rowClass = "odd";
+                }
+            }
+        }
+        pw.println("</table>");
+    }
+
+    private String getType(LoginModuleProvider lp)
+    {
+        String type = "Service";
+        if (lp instanceof ConfigLoginModuleProvider)
+        {
+            type = "Configuration";
+        }
+        return type;
+    }
+
+    private void getJson(HttpServletResponse resp)
+    {
+
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    public void printConfiguration(final PrintWriter pw)
+    {
+        pw.println("JAAS Configuration Details:");
+        pw.println();
+        pw.println("Registered LoginModules");
+        Map<String, Realm> configs = getConfigurationDetails();
+        if (configs.isEmpty())
+        {
+            pw.println("No JAAS LoginModule registered");
+        }
+        else
+        {
+            for (Realm r : configs.values())
+            {
+                String realmName = r.getRealmName();
+                pw.printf("Realm : %s \n", realmName);
+                for (AppConfigurationHolder ah : r.getConfigs())
+                {
+                    addSpace(pw, 1);
+                    pw.printf("%s \n", ah.getProvider().getClassName());
+
+                    addSpace(pw, 2);
+                    pw.printf("Flag    : %s \n",
+                        ControlFlag.toString(ah.getProvider().getControlFlag()));
+                    addSpace(pw, 2);
+                    pw.printf("Type    : %s \n", getType(ah.getProvider()));
+                    addSpace(pw, 2);
+                    pw.printf("Ranking : %d \n", ah.getProvider().ranking());
+                }
+            }
+        }
+
+        pw.println();
+
+        Map<Bundle, Set<String>> bundleMap = getAvailableLoginModuleInfo();
+        pw.println("Available LoginModules");
+        if (bundleMap.isEmpty())
+        {
+            //Nothing to do
+        }
+        else
+        {
+            for (Map.Entry<Bundle, Set<String>> e : bundleMap.entrySet())
+            {
+                Bundle b = e.getKey();
+                pw.printf("%s (%s) \n", b.getSymbolicName(), b.getBundleId());
+                for (String className : e.getValue())
+                {
+                    addSpace(pw, 1);
+                    pw.println(className);
+                }
+            }
+        }
+    }
+
+    private static void addSpace(PrintWriter pw, int count)
+    {
+        for (int i = 0; i < count; i++)
+        {
+            pw.print("  ");
+        }
+    }
+
+    private Map<String, Realm> getConfigurationDetails()
+    {
+        return configSpi.getAllConfiguration();
+    }
+
+    private Map<Bundle, Set<String>> getAvailableLoginModuleInfo()
+    {
+        return loginModuleCreator.getBundleToLoginModuleMapping();
+    }
+
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Logger.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Logger.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Logger.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/Logger.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.internal;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+class Logger extends ServiceTracker
+{
+
+    public Logger(BundleContext context)
+    {
+        super(context, LogService.class.getName(), null);
+    }
+
+    public void log(int level, String message)
+    {
+        LogService log = getLog();
+        if (log != null)
+        {
+            log.log(level, message);
+        }
+
+    }
+
+    public void log(int level, String message, Throwable exception)
+    {
+        LogService log = getLog();
+        if (log != null)
+        {
+            log.log(level, message, exception);
+        }
+    }
+
+    private LogService getLog()
+    {
+        return (LogService) getService();
+    }
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleCreator.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleCreator.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleCreator.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleCreator.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.internal;
+
+import javax.security.auth.spi.LoginModule;
+
+
+/**
+ * User: chetanm
+ * Date: 7/9/12
+ * Time: 10:17 PM
+ */
+public interface LoginModuleCreator
+{
+
+    LoginModule newInstance(String className);
+
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleProvider.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleProvider.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/LoginModuleProvider.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,41 @@
+/*
+ * 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.internal;
+
+import static javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+
+import java.util.Map;
+
+import org.apache.felix.jaas.LoginModuleFactory;
+import org.apache.felix.jaas.boot.ProxyLoginModule;
+
+public interface LoginModuleProvider extends LoginModuleFactory, ProxyLoginModule.BootLoginModuleFactory
+{
+
+    Map<String, ?> options();
+
+    LoginModuleControlFlag getControlFlag();
+
+    int ranking();
+
+    String realmName();
+
+    String getClassName();
+}

Added: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/OsgiLoginModuleProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/OsgiLoginModuleProvider.java?rev=1399574&view=auto
==============================================================================
--- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/OsgiLoginModuleProvider.java (added)
+++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/OsgiLoginModuleProvider.java Thu Oct 18 10:10:08 2012
@@ -0,0 +1,93 @@
+/*
+ * 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.internal;
+
+import static javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+
+import java.util.Collections;
+import java.util.Map;
+
+import javax.security.auth.spi.LoginModule;
+
+import org.apache.felix.jaas.LoginModuleFactory;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+final class OsgiLoginModuleProvider implements LoginModuleProvider
+{
+    private final LoginModuleFactory delegate;
+    private final int ranking;
+    private final LoginModuleControlFlag flag;
+    private final String realmName;
+    private final ServiceReference serviceReference;
+
+    public OsgiLoginModuleProvider(ServiceReference sr, LoginModuleFactory delegate)
+    {
+        this.delegate = delegate;
+        this.ranking = Util.toInteger(sr.getProperty(Constants.SERVICE_RANKING), 0);
+        this.flag = ControlFlag.from(
+            (String) sr.getProperty(LoginModuleFactory.JAAS_CONTROL_FLAG)).flag();
+        this.realmName = (String) sr.getProperty(LoginModuleFactory.JAAS_REALM_NAME);
+        this.serviceReference = sr;
+    }
+
+    public Map<String, ?> options()
+    {
+        return Collections.emptyMap();
+    }
+
+    public LoginModuleControlFlag getControlFlag()
+    {
+        return flag;
+    }
+
+    public int ranking()
+    {
+        return ranking;
+    }
+
+    public String realmName()
+    {
+        return realmName;
+    }
+
+    public LoginModule createLoginModule()
+    {
+        return delegate.createLoginModule();
+    }
+
+    public String getClassName()
+    {
+        return delegate.getClass().getName();
+    }
+
+    public ServiceReference getServiceReference()
+    {
+        return serviceReference;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "OsgiLoginModuleProvider{" + "className=" + delegate.getClass().getName()
+            + ", ranking=" + ranking + ", flag=" + flag + ", realmName='" + realmName
+            + '\'' + '}';
+    }
+}



Mime
View raw message