X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fweb%2Fdevices%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fdevices%2Fweb%2FDevices.java;h=37798ac137f36a7a4014dc84c45f523fe2b8d860;hp=7898f78c6214466edba0383e7908f33336e23781;hb=bf2bf3ea3e0b45f2ae7df27bf4634214add7c0ce;hpb=44331939251d6c9f800f63076e9d51bd8263b526 diff --git a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java index 7898f78c62..37798ac137 100644 --- a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java +++ b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java @@ -10,30 +10,30 @@ package org.opendaylight.controller.devices.web; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ConcurrentMap; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.codehaus.jackson.map.ObjectMapper; -import org.opendaylight.controller.usermanager.IUserManager; -import org.opendaylight.controller.web.IDaylightWeb; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; import org.opendaylight.controller.forwarding.staticrouting.IForwardingStaticRouting; import org.opendaylight.controller.forwarding.staticrouting.StaticRouteConfig; +import org.opendaylight.controller.sal.authorization.Privilege; import org.opendaylight.controller.sal.authorization.UserLevel; import org.opendaylight.controller.sal.core.Config; +import org.opendaylight.controller.sal.core.Description; +import org.opendaylight.controller.sal.core.ForwardingMode; import org.opendaylight.controller.sal.core.Name; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.core.Property; +import org.opendaylight.controller.sal.core.State; import org.opendaylight.controller.sal.core.Tier; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.HexEncode; @@ -45,6 +45,13 @@ import org.opendaylight.controller.switchmanager.SpanConfig; import org.opendaylight.controller.switchmanager.SubnetConfig; import org.opendaylight.controller.switchmanager.Switch; import org.opendaylight.controller.switchmanager.SwitchConfig; +import org.opendaylight.controller.web.DaylightWebUtil; +import org.opendaylight.controller.web.IDaylightWeb; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import com.google.gson.Gson; @@ -55,7 +62,6 @@ public class Devices implements IDaylightWeb { private final String WEB_NAME = "Devices"; private final String WEB_ID = "devices"; private final short WEB_ORDER = 1; - private final String containerName = GlobalConstants.DEFAULT.toString(); public Devices() { ServiceHelper.registerGlobalService(IDaylightWeb.class, this, null); @@ -83,71 +89,108 @@ public class Devices implements IDaylightWeb { @RequestMapping(value = "/nodesLearnt", method = RequestMethod.GET) @ResponseBody - public DevicesJsonBean getNodesLearnt() { + public DevicesJsonBean getNodesLearnt(HttpServletRequest request, + @RequestParam(required = false) String container) { Gson gson = new Gson(); - ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, containerName, this); + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Derive the privilege this user has on the current container + String userName = request.getUserPrincipal().getName(); + Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this); + + ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, + this); List> nodeData = new ArrayList>(); - Map portListStatus = new HashMap(); - for (Switch device : switchManager.getNetworkDevices()) { - HashMap nodeDatum = new HashMap(); - Node node = device.getNode(); - Tier tier = (Tier) switchManager.getNodeProp(node, - Tier.TierPropName); - - nodeDatum.put("containerName", containerName); - nodeDatum.put("nodeName", switchManager.getNodeDescription(node)); - nodeDatum.put("nodeId", node.toString()); - int tierNumber = (tier == null) ? TierHelper.unknownTierNumber - : tier.getValue(); - nodeDatum.put("tierName", TierHelper.getTierName(tierNumber) - + " (Tier-" + tierNumber + ")"); - nodeDatum.put("tier", tierNumber + ""); - SwitchConfig sc = switchManager.getSwitchConfig(device.getNode() - .toString()); - String modeStr = (sc != null) ? sc.getMode() : "0"; - nodeDatum.put("mode", modeStr); - - nodeDatum.put("json", gson.toJson(nodeDatum)); - nodeDatum.put("mac", - HexEncode.bytesToHexString(device.getDataLayerAddress())); - StringBuffer sb1 = new StringBuffer(); - StringBuffer sb2 = new StringBuffer(); - Set nodeConnectorSet = device.getNodeConnectors(); - String nodeConnectorName; - String nodeConnectorNumberToStr; - if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) { - Map portList = new HashMap(); - for (NodeConnector nodeConnector : nodeConnectorSet) { - nodeConnectorNumberToStr = nodeConnector.getID().toString(); - Name ncName = ((Name) switchManager.getNodeConnectorProp( - nodeConnector, Name.NamePropName)); - Config portStatus = ((Config) switchManager - .getNodeConnectorProp(nodeConnector, - Config.ConfigPropName)); - nodeConnectorName = (ncName != null) ? ncName.getValue() - : ""; - portList.put(Short.parseShort(nodeConnectorNumberToStr), - nodeConnectorName); - portListStatus - .put(nodeConnectorName, portStatus.toString()); + if (switchManager != null && privilege != Privilege.NONE) { + for (Switch device : switchManager.getNetworkDevices()) { + HashMap nodeDatum = new HashMap(); + Node node = device.getNode(); + Tier tier = (Tier) switchManager.getNodeProp(node, Tier.TierPropName); + nodeDatum.put("containerName", containerName); + Description description = (Description) switchManager.getNodeProp(node, Description.propertyName); + String desc = (description == null) ? "" : description.getValue(); + nodeDatum.put("nodeName", desc); + nodeDatum.put("nodeId", node.toString()); + int tierNumber = (tier == null) ? TierHelper.unknownTierNumber : tier.getValue(); + nodeDatum.put("tierName", TierHelper.getTierName(tierNumber) + " (Tier-" + tierNumber + ")"); + nodeDatum.put("tier", tierNumber + ""); + String modeStr = "0"; + ForwardingMode mode = (ForwardingMode) switchManager.getNodeProp(node, ForwardingMode.name); + if (mode != null) { + modeStr = String.valueOf(mode.getValue()); } + nodeDatum.put("mode", modeStr); + + nodeDatum.put("json", gson.toJson(nodeDatum)); + nodeDatum.put("mac", HexEncode.bytesToHexString(device.getDataLayerAddress())); + StringBuffer sb1 = new StringBuffer(); + Set nodeConnectorSet = device.getNodeConnectors(); + if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) { + Map portList = new HashMap(); + List intfList = new ArrayList(); + for (NodeConnector nodeConnector : nodeConnectorSet) { + String nodeConnectorNumberToStr = nodeConnector.getID().toString(); + Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector, Name.NamePropName)); + Config portStatus = ((Config) switchManager + .getNodeConnectorProp(nodeConnector, + Config.ConfigPropName)); + State portState = ((State) switchManager + .getNodeConnectorProp(nodeConnector, + State.StatePropName)); + + String nodeConnectorName = (ncName != null) ? ncName + .getValue() : ""; + nodeConnectorName += " (" + nodeConnector.getID() + ")"; + + if (portStatus != null) { + if (portStatus.getValue() == Config.ADMIN_UP) { + if (portState.getValue() == State.EDGE_UP) { + nodeConnectorName = "" + + nodeConnectorName + ""; + } else if (portState.getValue() == State.EDGE_DOWN) { + nodeConnectorName = "" + + nodeConnectorName + ""; + } + } else if (portStatus.getValue() == Config.ADMIN_DOWN) { + nodeConnectorName = "" + + nodeConnectorName + ""; + } + } + + Class idClass = nodeConnector.getID().getClass(); + if (idClass.equals(Short.class)) { + portList.put( + Short.parseShort(nodeConnectorNumberToStr), + nodeConnectorName); + } else { + intfList.add(nodeConnectorName); + } + } - Map sortedPortList = new TreeMap( - portList); - - for (Entry e : sortedPortList.entrySet()) { - sb1.append(e.getValue() + "(" + e.getKey() + ")"); - sb1.append("
"); - sb2.append(portListStatus.get(e.getValue()) + "
"); + if (portList.size() > 0) { + Map sortedPortList = new TreeMap( + portList); + + for (Entry e : sortedPortList.entrySet()) { + sb1.append(e.getValue()); + sb1.append("
"); + } + } else if (intfList.size() > 0) { + for (String intf : intfList) { + sb1.append(intf); + sb1.append("
"); + } + } } + nodeDatum.put("ports", sb1.toString()); + nodeData.add(nodeDatum); } - nodeDatum.put("ports", sb1.toString()); - nodeDatum.put("portStatus", sb2.toString()); - nodeData.add(nodeDatum); } + DevicesJsonBean result = new DevicesJsonBean(); result.setNodeData(nodeData); + result.setPrivilege(privilege); List columnNames = new ArrayList(); columnNames.add("Node ID"); columnNames.add("Node Name"); @@ -173,8 +216,15 @@ public class Devices implements IDaylightWeb { @RequestParam("nodeId") String nodeId, @RequestParam("tier") String tier, @RequestParam("operationMode") String operationMode, - HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil + .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -182,11 +232,24 @@ public class Devices implements IDaylightWeb { try { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - SwitchConfig cfg = new SwitchConfig(nodeId, nodeName, tier, - operationMode); - switchManager.updateSwitchConfig(cfg); - resultBean.setStatus(true); - resultBean.setMessage("Updated node information successfully"); + Map nodeProperties = new HashMap(); + Property desc = new Description(nodeName); + nodeProperties.put(desc.getName(), desc); + Property nodeTier = new Tier(Integer.parseInt(tier)); + nodeProperties.put(nodeTier.getName(), nodeTier); + if (containerName.equals(GlobalConstants.DEFAULT.toString())) { + Property mode = new ForwardingMode(Integer.parseInt(operationMode)); + nodeProperties.put(mode.getName(), mode); + } + SwitchConfig cfg = new SwitchConfig(nodeId, nodeProperties); + Status result = switchManager.updateNodeConfig(cfg); + if (!result.isSuccess()) { + resultBean.setStatus(false); + resultBean.setMessage(result.getDescription()); + } else { + resultBean.setStatus(true); + resultBean.setMessage("Updated node information successfully"); + } } catch (Exception e) { resultBean.setStatus(false); resultBean.setMessage("Error updating node information. " @@ -197,27 +260,41 @@ public class Devices implements IDaylightWeb { @RequestMapping(value = "/staticRoutes", method = RequestMethod.GET) @ResponseBody - public DevicesJsonBean getStaticRoutes() { + public DevicesJsonBean getStaticRoutes(HttpServletRequest request, + @RequestParam(required = false) String container) { Gson gson = new Gson(); + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Derive the privilege this user has on the current container + String userName = request.getUserPrincipal().getName(); + Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this); + IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper .getInstance(IForwardingStaticRouting.class, containerName, this); + if (staticRouting == null) { + return null; + } List> staticRoutes = new ArrayList>(); ConcurrentMap routeConfigs = staticRouting .getStaticRouteConfigs(); if (routeConfigs == null) { return null; } - for (StaticRouteConfig conf : routeConfigs.values()) { - Map staticRoute = new HashMap(); - staticRoute.put("name", conf.getName()); - staticRoute.put("staticRoute", conf.getStaticRoute()); - staticRoute.put("nextHopType", conf.getNextHopType()); - staticRoute.put("nextHop", conf.getNextHop()); - staticRoute.put("json", gson.toJson(conf)); - staticRoutes.add(staticRoute); + if (privilege != Privilege.NONE) { + for (StaticRouteConfig conf : routeConfigs.values()) { + Map staticRoute = new HashMap(); + staticRoute.put("name", conf.getName()); + staticRoute.put("staticRoute", conf.getStaticRoute()); + staticRoute.put("nextHopType", conf.getNextHopType()); + staticRoute.put("nextHop", conf.getNextHop()); + staticRoute.put("json", gson.toJson(conf)); + staticRoutes.add(staticRoute); + } } DevicesJsonBean result = new DevicesJsonBean(); + result.setPrivilege(privilege); result.setColumnNames(StaticRouteConfig.getGuiFieldsNames()); result.setNodeData(staticRoutes); return result; @@ -228,8 +305,16 @@ public class Devices implements IDaylightWeb { public StatusJsonBean addStaticRoute( @RequestParam("routeName") String routeName, @RequestParam("staticRoute") String staticRoute, - @RequestParam("nextHop") String nextHop, HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + @RequestParam("nextHop") String nextHop, + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil + .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -261,8 +346,14 @@ public class Devices implements IDaylightWeb { @ResponseBody public StatusJsonBean deleteStaticRoute( @RequestParam("routesToDelete") String routesToDelete, - HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -295,19 +386,33 @@ public class Devices implements IDaylightWeb { @RequestMapping(value = "/subnets", method = RequestMethod.GET) @ResponseBody - public DevicesJsonBean getSubnetGateways() { + public DevicesJsonBean getSubnetGateways(HttpServletRequest request, + @RequestParam(required = false) String container) { Gson gson = new Gson(); List> subnets = new ArrayList>(); - ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, containerName, this); - for (SubnetConfig conf : switchManager.getSubnetsConfigList()) { - Map subnet = new HashMap(); - subnet.put("name", conf.getName()); - subnet.put("subnet", conf.getSubnet()); - subnet.put("json", gson.toJson(conf)); - subnets.add(subnet); + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Derive the privilege this user has on the current container + String userName = request.getUserPrincipal().getName(); + Privilege privilege = DaylightWebUtil.getContainerPrivilege( + userName, containerName, this); + + if (privilege != Privilege.NONE) { + ISwitchManager switchManager = (ISwitchManager) ServiceHelper + .getInstance(ISwitchManager.class, containerName, this); + if (switchManager != null) { + for (SubnetConfig conf : switchManager.getSubnetsConfigList()) { + Map subnet = new HashMap(); + subnet.put("name", conf.getName()); + subnet.put("subnet", conf.getSubnet()); + subnet.put("json", gson.toJson(conf)); + subnets.add(subnet); + } + } } DevicesJsonBean result = new DevicesJsonBean(); + result.setPrivilege(privilege); result.setColumnNames(SubnetConfig.getGuiFieldsNames()); result.setNodeData(subnets); return result; @@ -318,8 +423,14 @@ public class Devices implements IDaylightWeb { public StatusJsonBean addSubnetGateways( @RequestParam("gatewayName") String gatewayName, @RequestParam("gatewayIPAddress") String gatewayIPAddress, - HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -328,7 +439,7 @@ public class Devices implements IDaylightWeb { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); SubnetConfig cfgObject = new SubnetConfig(gatewayName, - gatewayIPAddress, new ArrayList()); + gatewayIPAddress, new HashSet()); Status result = switchManager.addSubnet(cfgObject); if (result.isSuccess()) { resultBean.setStatus(true); @@ -348,8 +459,14 @@ public class Devices implements IDaylightWeb { @ResponseBody public StatusJsonBean deleteSubnetGateways( @RequestParam("gatewaysToDelete") String gatewaysToDelete, - HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, container, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -380,8 +497,14 @@ public class Devices implements IDaylightWeb { public StatusJsonBean addSubnetGatewayPort( @RequestParam("portsName") String portsName, @RequestParam("ports") String ports, - @RequestParam("nodeId") String nodeId, HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + @RequestParam("nodeId") String nodeId, HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -412,8 +535,14 @@ public class Devices implements IDaylightWeb { public StatusJsonBean deleteSubnetGatewayPort( @RequestParam("gatewayName") String gatewayName, @RequestParam("nodePort") String nodePort, - HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -441,35 +570,51 @@ public class Devices implements IDaylightWeb { @RequestMapping(value = "/spanPorts", method = RequestMethod.GET) @ResponseBody - public DevicesJsonBean getSpanPorts() { + public DevicesJsonBean getSpanPorts(HttpServletRequest request, + @RequestParam(required = false) String container) { Gson gson = new Gson(); - List spanConfigs_json = new ArrayList(); - ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, containerName, this); - for (SpanConfig conf : switchManager.getSpanConfigList()) { - spanConfigs_json.add(gson.toJson(conf)); - } - ObjectMapper mapper = new ObjectMapper(); List> spanConfigs = new ArrayList>(); - for (String config_json : spanConfigs_json) { - try { - @SuppressWarnings("unchecked") - Map config_data = mapper.readValue(config_json, - HashMap.class); - Map config = new HashMap(); - for (String name : config_data.keySet()) { - config.put(name, config_data.get(name)); - // Add switch name value (non-configuration field) - config.put("nodeName", - getNodeDesc(config_data.get("nodeId"))); + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Derive the privilege this user has on the current container + String userName = request.getUserPrincipal().getName(); + Privilege privilege = DaylightWebUtil.getContainerPrivilege( + userName, containerName, this); + + if (privilege != Privilege.NONE) { + List spanConfigs_json = new ArrayList(); + ISwitchManager switchManager = (ISwitchManager) ServiceHelper + .getInstance(ISwitchManager.class, containerName, this); + if (switchManager != null) { + for (SpanConfig conf : switchManager.getSpanConfigList()) { + spanConfigs_json.add(gson.toJson(conf)); + } + } + ObjectMapper mapper = new ObjectMapper(); + + for (String config_json : spanConfigs_json) { + try { + @SuppressWarnings("unchecked") + Map config_data = mapper.readValue(config_json, + HashMap.class); + Map config = new HashMap(); + for (String name : config_data.keySet()) { + config.put(name, config_data.get(name)); + // Add switch name value (non-configuration field) + config.put("nodeName", + getNodeDesc(config_data.get("nodeId"), containerName)); + } + config.put("json", config_json); + spanConfigs.add(config); + } catch (Exception e) { + // TODO: Handle the exception. } - config.put("json", config_json); - spanConfigs.add(config); - } catch (Exception e) { - // TODO: Handle the exception. } } + DevicesJsonBean result = new DevicesJsonBean(); + result.setPrivilege(privilege); result.setColumnNames(SpanConfig.getGuiFieldsNames()); result.setNodeData(spanConfigs); return result; @@ -477,11 +622,23 @@ public class Devices implements IDaylightWeb { @RequestMapping(value = "/nodeports") @ResponseBody - public Map getNodePorts() { + public Map getNodePorts(HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Derive the privilege this user has on the current container + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) { + return null; + } + + ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - if (switchManager == null) + if (switchManager == null) { return null; + } Map nodes = new HashMap(); Map port; @@ -490,7 +647,7 @@ public class Devices implements IDaylightWeb { port = new HashMap(); // new port Set nodeConnectorSet = node.getNodeConnectors(); - if (nodeConnectorSet != null) + if (nodeConnectorSet != null) { for (NodeConnector nodeConnector : nodeConnectorSet) { String nodeConnectorName = ((Name) switchManager .getNodeConnectorProp(nodeConnector, @@ -498,6 +655,7 @@ public class Devices implements IDaylightWeb { port.put((Short) nodeConnector.getID(), nodeConnectorName + "(" + nodeConnector.getID() + ")"); } + } nodes.put(node.getNode().toString(), port); } @@ -509,8 +667,14 @@ public class Devices implements IDaylightWeb { @ResponseBody public StatusJsonBean addSpanPort( @RequestParam("jsonData") String jsonData, - HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -540,8 +704,14 @@ public class Devices implements IDaylightWeb { @ResponseBody public StatusJsonBean deleteSpanPorts( @RequestParam("spanPortsToDelete") String spanPortsToDelete, - HttpServletRequest request) { - if (!authorize(UserLevel.NETWORKADMIN, request)) { + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return unauthorizedMessage(); } @@ -573,38 +743,20 @@ public class Devices implements IDaylightWeb { return resultBean; } - private String getNodeDesc(String nodeId) { + private String getNodeDesc(String nodeId, String containerName) { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); String description = ""; if (switchManager != null) { - description = switchManager.getNodeDescription(Node - .fromString(nodeId)); + Description desc = (Description) switchManager.getNodeProp(Node.fromString(nodeId), Description.propertyName); + if(desc != null) { + description = desc.getValue(); + } } return (description.isEmpty() || description.equalsIgnoreCase("none")) ? nodeId : description; } - /** - * Is the operation permitted for the given level - * - * @param level - */ - private boolean authorize(UserLevel level, HttpServletRequest request) { - IUserManager userManager = (IUserManager) ServiceHelper - .getGlobalInstance(IUserManager.class, this); - if (userManager == null) { - return false; - } - - String username = request.getUserPrincipal().getName(); - UserLevel userLevel = userManager.getUserLevel(username); - if (userLevel.toNumber() <= level.toNumber()) { - return true; - } - return false; - } - private StatusJsonBean unauthorizedMessage() { StatusJsonBean message = new StatusJsonBean(); message.setStatus(false); @@ -620,10 +772,10 @@ public class Devices implements IDaylightWeb { * IUserManager userManager = (IUserManager) ServiceHelper * .getGlobalInstance(IUserManager.class, this); if (userManager == * null) { return "User Manager is not available"; } - * + * * String username = request.getUserPrincipal().getName(); - * - * + * + * * model.addAttribute("username", username); model.addAttribute("role", * userManager.getUserLevel(username).toNumber()); */