1 package org.opendaylight.controller.northbound.commons.utils;
3 import org.opendaylight.controller.containermanager.IContainerAuthorization;
4 import org.opendaylight.controller.sal.authorization.Privilege;
5 import org.opendaylight.controller.sal.authorization.UserLevel;
6 import org.opendaylight.controller.sal.utils.GlobalConstants;
7 import org.opendaylight.controller.sal.utils.ServiceHelper;
8 import org.opendaylight.controller.usermanager.IUserManager;
10 public class NorthboundUtils {
14 * Returns whether the current user has the required privilege on the
19 * @param containerName
22 * Operation to be performed - READ/WRITE
24 * Class from where the function is invoked
25 * @return The Status of the request, either Success or Unauthorized
27 public static boolean isAuthorized(String userName, String containerName,
28 Privilege required,Object bundle) {
30 if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
31 IUserManager auth = (IUserManager) ServiceHelper.getGlobalInstance(
32 IUserManager.class, bundle);
36 return (auth.getUserLevel(userName).ordinal() <= UserLevel.NETWORKADMIN.ordinal());
38 return (auth.getUserLevel(userName).ordinal() <= UserLevel.NETWORKOPERATOR.ordinal());
44 IContainerAuthorization auth = (IContainerAuthorization) ServiceHelper
45 .getGlobalInstance(IContainerAuthorization.class, bundle);
51 Privilege current = auth.getResourcePrivilege(userName,
53 if (required.ordinal() > current.ordinal()) {