Author: iocanel
Date: Fri Oct 29 14:03:59 2010
New Revision: 1028753

URL: http://svn.apache.org/viewvc?rev=1028753&view=rev
Log:
[KARAF-188] Added Jaas shell commands for adding/ removing users and roles.

Added:
    karaf/trunk/jaas/command/
    karaf/trunk/jaas/command/pom.xml
    karaf/trunk/jaas/command/src/
    karaf/trunk/jaas/command/src/main/
    karaf/trunk/jaas/command/src/main/java/
    karaf/trunk/jaas/command/src/main/java/org/
    karaf/trunk/jaas/command/src/main/java/org/apache/
    karaf/trunk/jaas/command/src/main/java/org/apache/karaf/
    karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/
    karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/CancelCommand.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListCommand.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleAddCommand.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleDeleteCommand.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UpdateCommand.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserAddCommand.java
    
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserDeleteCommand.java
    karaf/trunk/jaas/command/src/main/resources/
    karaf/trunk/jaas/command/src/main/resources/OSGI-INF/
    karaf/trunk/jaas/command/src/main/resources/OSGI-INF/blueprint/
    
karaf/trunk/jaas/command/src/main/resources/OSGI-INF/blueprint/jass-command.xml
    karaf/trunk/jaas/command/src/test/
    karaf/trunk/jaas/command/src/test/java/
Modified:
    karaf/trunk/jaas/pom.xml

Added: karaf/trunk/jaas/command/pom.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/pom.xml?rev=1028753&view=auto
==============================================================================
--- karaf/trunk/jaas/command/pom.xml (added)
+++ karaf/trunk/jaas/command/pom.xml Fri Oct 29 14:03:59 2010
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd";>
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>jaas</artifactId>
+        <groupId>org.apache.karaf.jaas</groupId>
+        <version>2.1.99-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>org.apache.karaf.jaas.command</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Jaas :: Command</name>
+
+    <properties>
+        
<appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.jaas</groupId>
+            <artifactId>org.apache.karaf.jaas.config</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.jaas</groupId>
+            <artifactId>org.apache.karaf.jaas.modules</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.obr</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.osgi</groupId>
+            <artifactId>spring-osgi-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        
<Export-Package>${project.artifactId}*;version=${project.version}</Export-Package>
+                        <Import-Package>
+                            !${project.artifactId}*,
+                            javax.management,
+                            javax.management.loading,
+                            org.apache.felix.service.command,
+                            org.apache.felix.gogo.commands,
+                            org.apache.karaf.shell.console,
+                            *
+                        </Import-Package>
+                        <Private-Package>!*</Private-Package>
+                        <_versionpolicy>${bnd.version.policy}</_versionpolicy>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/CancelCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/CancelCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/CancelCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/CancelCommand.java
 Fri Oct 29 14:03:59 2010
@@ -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.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+import java.util.LinkedList;
+
+/**
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "cancel", description = "Cancel the 
modification of a JAAS realm.")
+public class CancelCommand extends JaasCommandSupport {
+
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        //Cleanup the session
+        session.put(JAAS_REALM, null);
+        session.put(JAAS_ENTRY, null);
+        session.put(JAAS_CMDS, new LinkedList<JaasCommandSupport>());
+        return null;
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
 Fri Oct 29 14:03:59 2010
@@ -0,0 +1,125 @@
+/*
+ * 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.karaf.jaas.command;
+
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.modules.BackingEngine;
+import org.apache.karaf.jaas.modules.BackingEngineService;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import java.util.List;
+import java.util.Queue;
+
+/**
+ * @author iocanel
+ */
+public abstract class JaasCommandSupport extends OsgiCommandSupport {
+
+    public static final String JAAS_REALM = "JaasCommand.REALM";
+    public static final String JAAS_ENTRY = "JaasCommand.ENTRY";
+    public static final String JAAS_CMDS = "JaasCommand.COMMANDS";
+
+    private List<JaasRealm> realms;
+
+    protected BackingEngineService backingEngineService;
+
+    protected abstract Object doExecute(BackingEngine engine) throws Exception;
+
+    /**
+     * Add the command to the command queue.
+     *
+     * @return
+     * @throws Exception
+     */
+    protected Object doExecute() throws Exception {
+        JaasRealm realm = (JaasRealm) session.get(JAAS_REALM);
+        AppConfigurationEntry entry = (AppConfigurationEntry) 
session.get(JAAS_ENTRY);
+        Queue commandQueue = (Queue) session.get(JAAS_CMDS);
+
+        if (realm != null && entry != null) {
+            if (commandQueue != null) {
+                commandQueue.add(this);
+            }
+        } else {
+            System.err.println("No JAAS Realm / Module has been selected.");
+        }
+        return null;
+    }
+
+
+    /**
+     * Returns the Jaas Realm named as realmName.
+     *
+     * @param realmName
+     * @return
+     */
+    public JaasRealm findRealmByName(String realmName) {
+        JaasRealm realm = null;
+        if (realms != null) {
+            for (JaasRealm jaasRealm : realms) {
+                if (jaasRealm.getName().equals(realmName))
+                    return jaasRealm;
+            }
+        }
+        return realm;
+    }
+
+    /**
+     * Returns the Jaas Module entry of the specified realm, named as 
moduleName.
+     *
+     * @param moduleName
+     * @return
+     */
+    public AppConfigurationEntry findEntryByRealmAndName(JaasRealm realm, 
String moduleName) {
+        AppConfigurationEntry appConfigurationEntry = null;
+        if (realm != null) {
+
+            AppConfigurationEntry[] entries = realm.getEntries();
+
+            //If no moduleName provided and a there is a single module in the 
realm.
+            if (entries != null && entries.length == 1 && moduleName == null) {
+                return entries[0];
+            }
+
+            for (AppConfigurationEntry entry : entries) {
+                if (moduleName.equals(entry.getLoginModuleName())) {
+                    return entry;
+                }
+            }
+
+        }
+        return appConfigurationEntry;
+    }
+
+
+    public List<JaasRealm> getRealms() {
+        return realms;
+    }
+
+    public void setRealms(List<JaasRealm> realms) {
+        this.realms = realms;
+    }
+
+    public BackingEngineService getBackingEngineService() {
+        return backingEngineService;
+    }
+
+    public void setBackingEngineService(BackingEngineService 
backingEngineService) {
+        this.backingEngineService = backingEngineService;
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListCommand.java
 Fri Oct 29 14:03:59 2010
@@ -0,0 +1,50 @@
+package org.apache.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.jaas.boot.ProxyLoginModule;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import java.util.Queue;
+
+/**
+ * @author iocanel
+ */
+
+/**
+ * Lists the commands the are in the command queue, for the active 
realm/module.
+ *
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "list", description = "Lists the 
modification on the active realm/module.")
+public class ListCommand extends JaasCommandSupport {
+
+    @Override
+    protected Object doExecute() throws Exception {
+        JaasRealm realm = (JaasRealm) session.get(JAAS_REALM);
+        AppConfigurationEntry entry = (AppConfigurationEntry) 
session.get(JAAS_ENTRY);
+        Queue<JaasCommandSupport> commandQueue = (Queue<JaasCommandSupport>) 
session.get(JAAS_CMDS);
+
+        if (realm != null && entry != null) {
+            String moduleClass = (String) 
entry.getOptions().get(ProxyLoginModule.PROPERTY_MODULE);
+            System.out.println(String.format("Jaas Realm:%s Jaas Module:%s", 
realm.getName(), moduleClass));
+
+            if (commandQueue != null && !commandQueue.isEmpty()) {
+                for (JaasCommandSupport command : commandQueue) {
+                    System.out.println(command);
+                }
+            } else {
+                System.err.println("No JAAS command in queue.");
+            }
+        } else {
+            System.err.println("No JAAS Realm / Module has been selected.");
+        }
+        return null;
+    }
+
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        return null;
+    }
+}
\ No newline at end of file

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
 Fri Oct 29 14:03:59 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "manage", description = "Manage user and 
roles of a Jaas Realm.")
+public class ManageRealmCommand extends JaasCommandSupport {
+
+    @Argument(index = 0, name = "realm", description = "Jaas Realm", required 
= true, multiValued = false)
+    String realmName;
+
+    @Option(name = "--module", aliases = {}, description = "Realm Module", 
required = false, multiValued = false)
+    String moduleName;
+
+    @Option(name = "--force", aliases = {}, description = "Force the 
management of this realm, even if another one was under management", required = 
false, multiValued = false)
+    boolean force;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        JaasRealm oldRealm = (JaasRealm) this.session.get(JAAS_REALM);
+        AppConfigurationEntry oldEntry = (AppConfigurationEntry) 
this.session.get(JAAS_ENTRY);
+
+        if (oldRealm != null && !oldRealm.getName().equals(realmName) && 
!force) {
+            System.err.println("Another realm is being edited.  Cancel / 
update first, or use the --force option");
+        } else if (oldEntry != null && 
!oldEntry.getLoginModuleName().equals(moduleName) && !force) {
+            System.err.println("Another module is being edited.  Cancel / 
update first, or use the --force option");
+        } else {
+
+            JaasRealm realm = findRealmByName(realmName);
+
+            if (realm != null) {
+                AppConfigurationEntry entry = findEntryByRealmAndName(realm, 
moduleName);
+
+                if (entry != null) {
+                    Queue<JaasCommandSupport> commands = null;
+
+                    commands = (Queue<JaasCommandSupport>) 
this.session.get(JAAS_CMDS);
+                    if (commands == null) {
+                        commands = new LinkedList<JaasCommandSupport>();
+                    }
+
+
+                    this.session.put(JAAS_REALM, realm);
+                    this.session.put(JAAS_ENTRY, entry);
+                    this.session.put(JAAS_CMDS, commands);
+                } else {
+                    System.err.println(String.format("Could not find module: 
%s in realm:%s", moduleName, realmName));
+                }
+            } else {
+                System.err.println(String.format("Could not find realm:%s", 
realmName));
+            }
+        }
+        return null;
+    }
+
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        return null;
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleAddCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleAddCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleAddCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleAddCommand.java
 Fri Oct 29 14:03:59 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+/**
+ * Adds a role to a user of the active realm/module.
+ *
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "roleadd", description = "Add a role to a 
user.")
+public class RoleAddCommand extends JaasCommandSupport {
+
+    @Argument(index = 0, name = "username", description = "User Name", 
required = true, multiValued = false)
+    private String username;
+
+    @Argument(index = 1, name = "role", description = "Role", required = true, 
multiValued = false)
+    private String role;
+
+    /**
+     * Execute the RoleAddCommand in the given Excecution Context.
+     *
+     * @param engine
+     * @return
+     * @throws Exception
+     */
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        engine.addRole(username, role);
+        return null;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getRole() {
+        return role;
+    }
+
+    public void setRole(String role) {
+        this.role = role;
+    }
+
+    @Override
+    public String toString() {
+        return "RoleAddCommand{" +
+                "username='" + username + '\'' +
+                ", role='" + role + '\'' +
+                '}';
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleDeleteCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleDeleteCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleDeleteCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/RoleDeleteCommand.java
 Fri Oct 29 14:03:59 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+/**
+ * Deletes a role from a user of the active realm/module.
+ *
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "roledel", description = "Delete a role 
from a user.")
+public class RoleDeleteCommand extends JaasCommandSupport {
+
+    @Argument(index = 0, name = "username", description = "User Name", 
required = true, multiValued = false)
+    private String username;
+
+    @Argument(index = 1, name = "role", description = "Role", required = true, 
multiValued = false)
+    private String role;
+
+    /**
+     * Execute the RoleDeleteCommand in the given Excecution Context.
+     *
+     * @param engine
+     * @return
+     * @throws Exception
+     */
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        engine.deleteRole(username, role);
+        return null;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getRole() {
+        return role;
+    }
+
+    public void setRole(String role) {
+        this.role = role;
+    }
+
+    @Override
+    public String toString() {
+        return "RoleDeleteCommand{" +
+                "username='" + username + '\'' +
+                ", role='" + role + '\'' +
+                '}';
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UpdateCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UpdateCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UpdateCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UpdateCommand.java
 Fri Oct 29 14:03:59 2010
@@ -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.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.jaas.config.JaasRealm;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * Executes all the pending commands of the active realm/module.
+ *
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "update", description = "Update JAAS 
realm.")
+public class UpdateCommand extends JaasCommandSupport {
+
+    @Override
+    protected Object doExecute() throws Exception {
+        JaasRealm realm = (JaasRealm) session.get(JAAS_REALM);
+        AppConfigurationEntry entry = (AppConfigurationEntry) 
session.get(JAAS_ENTRY);
+
+        if (realm == null || entry == null) {
+            System.err.println("No JAAS Realm / Module has been selected.");
+            return null;
+        }
+
+        BackingEngine engine = backingEngineService.get(entry);
+
+        if (engine == null) {
+            System.err.println(String.format("Failed to resolve backing engine 
for realm:%s and moudle:%s", realm.getName(), entry.getLoginModuleName()));
+            return null;
+        }
+
+        return doExecute(engine);
+    }
+
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        Queue<? extends JaasCommandSupport> commands = (Queue<? extends 
JaasCommandSupport>) session.get(JAAS_CMDS);
+
+        if (commands == null || commands.isEmpty()) {
+            System.err.println("No JAAS command in queue.");
+            return null;
+        }
+
+        //Loop throught the commands and execute them.
+        while (!commands.isEmpty()) {
+            Object obj = commands.remove();
+            if (obj instanceof JaasCommandSupport) {
+                ((JaasCommandSupport) obj).doExecute(engine);
+            }
+        }
+        //Cleanup the session
+        session.put(JAAS_REALM, null);
+        session.put(JAAS_ENTRY, null);
+        session.put(JAAS_CMDS, new LinkedList<JaasCommandSupport>());
+        return null;
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserAddCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserAddCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserAddCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserAddCommand.java
 Fri Oct 29 14:03:59 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+/**
+ * Creates a new user in the active realm/module.
+ *
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "useradd", description = "Add a user.")
+public class UserAddCommand extends JaasCommandSupport {
+
+    @Argument(index = 0, name = "username", description = "User Name", 
required = true, multiValued = false)
+    private String username;
+
+    @Argument(index = 1, name = "password", description = "Password", required 
= true, multiValued = false)
+    private String password;
+
+
+    /**
+     * Execute the RoleAddCommand in the given Excecution Context.
+     *
+     * @param engine
+     * @return
+     * @throws Exception
+     */
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        engine.addUser(username, password);
+        return null;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    @Override
+    public String toString() {
+        return "UserAddCommand{" +
+                "username='" + username + '\'' +
+                ", password='" + password + '\'' +
+                '}';
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserDeleteCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserDeleteCommand.java?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserDeleteCommand.java
 (added)
+++ 
karaf/trunk/jaas/command/src/main/java/org/apache/karaf/jaas/command/UserDeleteCommand.java
 Fri Oct 29 14:03:59 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.karaf.jaas.command;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.jaas.modules.BackingEngine;
+
+/**
+ * Deletes a user of the active realm/module.
+ *
+ * @author iocanel
+ */
+...@command(scope = "jaas", name = "userdel", description = "Delete a user.")
+public class UserDeleteCommand extends JaasCommandSupport {
+
+    @Argument(index = 0, name = "username", description = "User Name", 
required = true, multiValued = false)
+    private String username;
+
+    /**
+     * Execute the RoleAddCommand in the given Excecution Context.
+     *
+     * @param engine
+     * @return
+     * @throws Exception
+     */
+    @Override
+    protected Object doExecute(BackingEngine engine) throws Exception {
+        engine.deleteUser(username);
+        return null;
+    }
+
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    @Override
+    public String toString() {
+        return "UserDeleteCommand{" +
+                "username='" + username + '\'' +
+                '}';
+    }
+}

Added: 
karaf/trunk/jaas/command/src/main/resources/OSGI-INF/blueprint/jass-command.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/command/src/main/resources/OSGI-INF/blueprint/jass-command.xml?rev=1028753&view=auto
==============================================================================
--- 
karaf/trunk/jaas/command/src/main/resources/OSGI-INF/blueprint/jass-command.xml 
(added)
+++ 
karaf/trunk/jaas/command/src/main/resources/OSGI-INF/blueprint/jass-command.xml 
Fri Oct 29 14:03:59 2010
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0";>
+        <command name="jaas/manage">
+            <action class="org.apache.karaf.jaas.command.ManageRealmCommand">
+                <property name="realms" ref="realms"/>
+            </action>
+        </command>
+        <command name="jaas/update">
+            <action class="org.apache.karaf.jaas.command.UpdateCommand">
+                <property name="backingEngineService" ref="engineService"/>
+            </action>
+        </command>
+        <command name="jaas/cancel">
+            <action class="org.apache.karaf.jaas.command.CancelCommand"/>
+        </command>
+        <command name="jaas/list">
+            <action class="org.apache.karaf.jaas.command.ListCommand"/>
+        </command>
+        <command name="jaas/useradd">
+            <action class="org.apache.karaf.jaas.command.UserAddCommand"/>
+        </command>
+        <command name="jaas/userdel">
+            <action class="org.apache.karaf.jaas.command.UserDeleteCommand"/>
+        </command>
+        <command name="jaas/roleadd">
+            <action class="org.apache.karaf.jaas.command.RoleAddCommand"/>
+        </command>
+        <command name="jaas/roledel">
+            <action class="org.apache.karaf.jaas.command.RoleDeleteCommand"/>
+        </command>
+    </command-bundle>
+
+    <!-- JAAS Realms -->
+    <reference-list id="realms" 
interface="org.apache.karaf.jaas.config.JaasRealm" availability="optional"/>
+
+    <!-- Backing Engine Service -->
+    <bean id="engineService" 
class="org.apache.karaf.jaas.modules.BackingEngineService">
+        <property name="engineFactories" ref="engineFactories"/>
+    </bean>
+
+    <!-- Backing Engine Factories -->
+    <reference-list id="engineFactories" 
interface="org.apache.karaf.jaas.modules.BackingEngineFactory"
+                    availability="optional"/>
+</blueprint>

Modified: karaf/trunk/jaas/pom.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/pom.xml?rev=1028753&r1=1028752&r2=1028753&view=diff
==============================================================================
--- karaf/trunk/jaas/pom.xml (original)
+++ karaf/trunk/jaas/pom.xml Fri Oct 29 14:03:59 2010
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<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/xsd/maven-4.0.0.xsd";>
+<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/xsd/maven-4.0.0.xsd";>
 
     <!--
 
@@ -37,6 +38,7 @@
         <module>config</module>
         <module>modules</module>
         <module>jasypt</module>
+        <module>command</module>
     </modules>
 
 </project>


Reply via email to