karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject git commit: [KARAF-3061] Problems with jaas:realms / jaas:manage commands when using multiple realms of the same name
Date Fri, 20 Jun 2014 14:16:20 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-3.0.x fab0ca62d -> a9b9e5497


[KARAF-3061] Problems with jaas:realms / jaas:manage commands when using multiple realms of
the same name


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/a9b9e549
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a9b9e549
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a9b9e549

Branch: refs/heads/karaf-3.0.x
Commit: a9b9e54975fa936f31d5d64923f3e0809ced2245
Parents: fab0ca6
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Fri Jun 20 15:55:15 2014 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Fri Jun 20 16:16:01 2014 +0200

----------------------------------------------------------------------
 .../karaf/jaas/command/JaasCommandSupport.java  | 22 +++++++++++-
 .../karaf/jaas/command/ListRealmsCommand.java   |  8 ++++-
 .../karaf/jaas/command/ManageRealmCommand.java  | 38 +++++++++++---------
 3 files changed, 49 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/a9b9e549/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
----------------------------------------------------------------------
diff --git a/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
b/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
index bd6e9f7..d631780 100644
--- a/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
+++ b/jaas/command/src/main/java/org/apache/karaf/jaas/command/JaasCommandSupport.java
@@ -22,8 +22,13 @@ import org.apache.karaf.jaas.modules.BackingEngineService;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 
 import javax.security.auth.login.AppConfigurationEntry;
+
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Queue;
+import java.util.TreeMap;
 
 public abstract class JaasCommandSupport extends OsgiCommandSupport {
 
@@ -60,7 +65,22 @@ public abstract class JaasCommandSupport extends OsgiCommandSupport {
     }
 
     public List<JaasRealm> getRealms() {
-        return realms;
+        return getRealms(false);
+    }
+
+    public List<JaasRealm> getRealms(boolean hidden) {
+        if (hidden) {
+            return realms;
+        } else {
+            Map<String, JaasRealm> map = new TreeMap<String, JaasRealm>();
+            for (JaasRealm realm : realms) {
+                if (!map.containsKey(realm.getName())
+                        || realm.getRank() > map.get(realm.getName()).getRank()) {
+                    map.put(realm.getName(), realm);
+                }
+            }
+            return new ArrayList<JaasRealm>(map.values());
+        }
     }
 
     public void setRealms(List<JaasRealm> realms) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/a9b9e549/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListRealmsCommand.java
----------------------------------------------------------------------
diff --git a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListRealmsCommand.java
b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListRealmsCommand.java
index 76354dc..c608db2 100644
--- a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListRealmsCommand.java
+++ b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListRealmsCommand.java
@@ -15,6 +15,9 @@
  */
 package org.apache.karaf.jaas.command;
 
+import java.util.List;
+import javax.security.auth.login.AppConfigurationEntry;
+
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.jaas.boot.ProxyLoginModule;
 import org.apache.karaf.jaas.config.JaasRealm;
@@ -31,13 +34,16 @@ public class ListRealmsCommand extends JaasCommandSupport {
     @Option(name = "--no-format", description = "Disable table rendered output", required
= false, multiValued = false)
     boolean noFormat;
 
+    @Option(name = "-h", aliases = {"--hidden"}, description = "Show hidden realms", required
= false, multiValued = false)
+    boolean hidden;
+
     @Override
     protected Object doExecute(BackingEngine engine) throws Exception {
         return null;
     }
 
     protected Object doExecute() throws Exception {
-        List<JaasRealm> realms = getRealms();
+        List<JaasRealm> realms = getRealms(hidden);
 
         ShellTable table = new ShellTable();
         table.column("Index");

http://git-wip-us.apache.org/repos/asf/karaf/blob/a9b9e549/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
----------------------------------------------------------------------
diff --git a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
index 89b5195..86f2b4e 100644
--- a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
+++ b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ManageRealmCommand.java
@@ -41,6 +41,9 @@ public class ManageRealmCommand extends JaasCommandSupport {
     @Option(name = "-f", aliases = { "--force" }, description = "Force the management of
this realm, even if another one was under management", required = false, multiValued = false)
     boolean force;
 
+    @Option(name = "-h", aliases = {"--hidden"}, description = "Manage hidden realms", required
= false, multiValued = false)
+    boolean hidden;
+
     @SuppressWarnings("unchecked")
     @Override
     protected Object doExecute() throws Exception {
@@ -62,7 +65,7 @@ public class ManageRealmCommand extends JaasCommandSupport {
 
             if (index > 0) {
                 // user provided the index, get the realm AND entry from the index
-                List<JaasRealm> realms = getRealms();
+                List<JaasRealm> realms = getRealms(hidden);
                 if (realms != null && realms.size() > 0) {
                     int i = 1;
                     realms_loop: for (JaasRealm r : realms) {
@@ -86,22 +89,23 @@ public class ManageRealmCommand extends JaasCommandSupport {
                     for (JaasRealm r : realms) {
                         if (r.getName().equals(realmName)) {
                             realm = r;
-                            break;
-                        }
-                    }
-
-                }
-                AppConfigurationEntry[] entries = realm.getEntries();
-                if (entries != null) {
-                    for (AppConfigurationEntry e : entries) {
-                        String moduleClass = (String) e.getOptions().get(ProxyLoginModule.PROPERTY_MODULE);
-                        if (moduleName == null) {
-                            entry = e;
-                            break;
-                        } else {
-                            if (moduleName.equals(e.getLoginModuleName()) || moduleName.equals(moduleClass))
{
-                                entry = e;
-                                break;
+                            AppConfigurationEntry[] entries = realm.getEntries();
+                            if (entries != null) {
+                                for (AppConfigurationEntry e : entries) {
+                                    String moduleClass = (String) e.getOptions().get(ProxyLoginModule.PROPERTY_MODULE);
+                                    if (moduleName == null) {
+                                        entry = e;
+                                        break;
+                                    } else {
+                                        if (moduleName.equals(e.getLoginModuleName()) ||
moduleName.equals(moduleClass)) {
+                                            entry = e;
+                                            break;
+                                        }
+                                    }
+                                }
+                                if (entry != null) {
+                                    break;
+                                }
                             }
                         }
                     }


Mime
View raw message