Auth Principal to work with Remote authorization 37/137/1
authorMadhu Venugopal <vmadhu@cisco.com>
Thu, 11 Apr 2013 19:06:05 +0000 (12:06 -0700)
committerMadhu Venugopal <vmadhu@cisco.com>
Thu, 11 Apr 2013 19:06:05 +0000 (12:06 -0700)
Also added some helpful OSGi console commands for remote auth.

Change-Id: I2c092cb73c7603acc2a2171e1d1fcc5669a9373d
Signed-off-by: Madhu Venugopal <vmadhu@cisco.com>
opendaylight/security/src/main/java/org/opendaylight/controller/security/ControllerCustomRealm.java
opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/ServerConfig.java
opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java

index 43a41da..f2e339f 100644 (file)
@@ -1,11 +1,13 @@
 package org.opendaylight.controller.security;
 
 import java.security.Principal;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.catalina.realm.GenericPrincipal;
 import org.apache.catalina.realm.RealmBase;
 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
+import org.opendaylight.controller.sal.authorization.UserLevel;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.usermanager.IUserManager;
 import org.slf4j.Logger;
@@ -38,8 +40,11 @@ public class ControllerCustomRealm  extends RealmBase {
         IUserManager userManager = (IUserManager) ServiceHelper
                 .getGlobalInstance(IUserManager.class, this);
         if (userManager != null) {
-            final List<String> roles = userManager.getUserRoles(username);
-            return new GenericPrincipal(username, getPassword(username), roles);
+            final List<String> levels = new ArrayList<String>(); 
+            UserLevel level = userManager.getUserLevel(username);
+            if (level == null) level = UserLevel.NOUSER;
+            levels.add(level.toString());
+            return new GenericPrincipal(username, "", levels);
         } else
             throw new RuntimeException("User Manager reference is null");
 
index 4ab0ae2..649fee8 100644 (file)
@@ -29,6 +29,12 @@ public class ServerConfig implements Serializable {
     public ServerConfig() {
     }
 
+    public ServerConfig(String ip, String secret, String protocol) {
+       this.ip = ip;
+       this.secret = secret;
+       this.protocol = protocol;
+    }
+    
     public String getAddress() {
         return ip;
     }
index 1bd323d..3e57ed8 100644 (file)
@@ -726,6 +726,39 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
             ci.println(conf.getUser() + " " + conf.getRole());
         }
     }
+    
+    public void _addAAAServer (CommandInterpreter ci) {
+        String server = ci.nextArgument();
+        String secret = ci.nextArgument();
+        String protocol = ci.nextArgument();
+        
+        if (server == null || secret == null || protocol == null) {
+               ci.println("Usage : addAAAServer <server> <secret> <protocol>");
+               return;
+        }
+        ServerConfig s = new ServerConfig(server, secret, protocol);
+        addAAAServer(s);
+    }
+    
+    public void _removeAAAServer (CommandInterpreter ci) {
+        String server = ci.nextArgument();
+        String secret = ci.nextArgument();
+        String protocol = ci.nextArgument();
+        
+        if (server == null || secret == null || protocol == null) {
+               ci.println("Usage : addAAAServer <server> <secret> <protocol>");
+               return;
+        }
+        ServerConfig s = new ServerConfig(server, secret, protocol);
+        removeAAAServer(s);
+    }
+
+    public void _printAAAServers (CommandInterpreter ci) {
+        for (ServerConfig aaaServer : remoteServerConfigList.values()) {
+            String protocol = aaaServer.getProtocol();
+            ci.println(aaaServer.getAddress() + "-" + aaaServer.getProtocol());
+        }
+    }
 
     @Override
     public String getHelp() {