1 package org.opendaylight.controller.web;
3 import org.opendaylight.controller.containermanager.IContainerAuthorization;
4 import org.opendaylight.controller.sal.authorization.Privilege;
5 import org.opendaylight.controller.sal.utils.GlobalConstants;
6 import org.opendaylight.controller.sal.utils.ServiceHelper;
7 import org.opendaylight.controller.usermanager.IUserManager;
9 public class DaylightWebUtil {
12 * Returns the access privilege the user has on the specified container
17 * The container name. If null, the default container will be assumed
19 * The bundle originating the request
20 * @return The access privilege the user is granted on the container
22 public static Privilege getContainerPrivilege(String userName,
23 String container, Object bundle) {
24 // Derive the target resource
25 String resource = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
27 // Retrieve the Container Authorization service
28 IContainerAuthorization auth = (IContainerAuthorization) ServiceHelper
29 .getGlobalInstance(IContainerAuthorization.class, bundle);
31 return auth.getResourcePrivilege(userName, resource);
35 * Container Authorization service not available. We can only derive the
36 * access privilege to the default container based on user level
38 if (resource.equals(GlobalConstants.DEFAULT.toString())) {
39 IUserManager userManager = (IUserManager) ServiceHelper
40 .getGlobalInstance(IUserManager.class, bundle);
41 if (userManager != null) {
42 switch (userManager.getUserLevel(userName)) {
44 return Privilege.WRITE;
46 return Privilege.READ;
48 return Privilege.NONE;
53 return Privilege.NONE;