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;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
11 public class DaylightWebUtil {
13 private static final String AUDIT = "audit";
14 private static final Logger logger = LoggerFactory.getLogger(AUDIT);
17 * Returns the access privilege the user has on the specified container
22 * The container name. If null, the default container will be assumed
24 * The bundle originating the request
25 * @return The access privilege the user is granted on the container
27 public static Privilege getContainerPrivilege(String userName,
28 String container, Object bundle) {
29 // Derive the target resource
30 String resource = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
32 // Retrieve the Container Authorization service
33 IContainerAuthorization auth = (IContainerAuthorization) ServiceHelper
34 .getGlobalInstance(IContainerAuthorization.class, bundle);
36 return auth.getResourcePrivilege(userName, resource);
40 * Container Authorization service not available. We can only derive the
41 * access privilege to the default container based on user level
43 if (resource.equals(GlobalConstants.DEFAULT.toString())) {
44 IUserManager userManager = (IUserManager) ServiceHelper
45 .getGlobalInstance(IUserManager.class, bundle);
46 if (userManager != null) {
47 switch (userManager.getUserLevel(userName)) {
49 return Privilege.WRITE;
51 return Privilege.READ;
53 return Privilege.NONE;
58 return Privilege.NONE;
61 public static void auditlog(String moduleName, String user, String action, String resource,
62 String containerName) {
65 if (containerName != null) {
66 auditMsg = "Mode: " + mode + " User " + user + " " + action + " " + moduleName + " " + resource + " in container "
69 auditMsg = "Mode: " + mode + " User " + user + " " + action + " " + moduleName + " " + resource;
71 logger.info(auditMsg);
74 public static void auditlog(String moduleName, String user, String action, String resource) {
75 auditlog(moduleName, user, action, resource, null);