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;
.getGlobalInstance(IUserManager.class, this);
if (userManager != null) {
return userManager.getPassword(username);
- } else
+ } else {
throw new RuntimeException("User Manager reference is null");
+ }
}
@Override
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);
- } else
+ List<String> controllerRoles = new ArrayList<String>();
+ for (UserLevel level : userManager.getUserLevels(username)) {
+ controllerRoles.add(level.toString());
+ }
+ return new GenericPrincipal(username, "", controllerRoles);
+ } else {
throw new RuntimeException("User Manager reference is null");
-
+ }
}
@Override
logger.error("Authentication failed for user " + username);
return null;
}
- } else
+ } else {
throw new RuntimeException("User Manager reference is null");
+ }
}
}