Auth Principal to work with Remote authorization
[controller.git] / opendaylight / security / src / main / java / org / opendaylight / controller / security / ControllerCustomRealm.java
index 43a41da82451fea753879b57b3516131aadddfac..f2e339f0c71dbc927ad1fe93964e61bdb3813bca 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");