* @return the {@code Status} object indicating the result of this action
*/
public Status toggleStaticFlowStatus(FlowConfig configObject);
+
+ /**
+ * Toggle the installation status of the specified configured flow
+ * If the flow configuration status is active, this call will
+ * change the flow status to inactive and vice-versa
+ *
+ * @param name for the static flow
+ * @param node on which the flow is attached
+ * @return the {@code Status} object indicating the result of this action
+ */
+ public Status toggleStaticFlowStatus(String name, Node node);
public Map<String, PortGroupConfig> getPortGroupConfigs();
return status;
}
+
+
+ @Override
+ public Status toggleStaticFlowStatus(String name, Node node) {
+ return toggleStaticFlowStatus(getStaticFlow(name, node));
+ }
+
@Override
public Status toggleStaticFlowStatus(FlowConfig config) {
+ if (config == null) {
+ String msg = "Invalid request: null flow config";
+ log.warn(msg);
+ return new Status(StatusCode.BADREQUEST, msg);
+ }
// Validity check for api3 entry point
if (config.isInternalFlow()) {
String msg = "Invalid operation: Controller generated flow " +
+ RestMessages.NOFLOW.toString());
}
- Status status = frm.toggleStaticFlowStatus(new FlowConfig("", name,
- node, "", "", "", "", "", "", "", "", "", "", "", "", "", "",
- "", "", "", null));
+ Status status = frm.toggleStaticFlowStatus(staticFlow);
if (status.isSuccess()) {
return Response.ok().build();
}
*
*/
public void stop() {
-
for (Iterator<Entry<Long, ISwitch>> it = switches.entrySet().iterator(); it
.hasNext();) {
Entry<Long, ISwitch> entry = it.next();
it.remove();
}
switchEventThread.interrupt();
- controllerIO.shutDown();
+ try {
+ controllerIO.shutDown();
+ } catch (IOException ex) {
+ logger.error("Caught exception: " + ex + " during stop");
+ }
}
/**
switchHandler.start();
logger.info(instanceName + " connected: " + sc.toString());
} catch (IOException e) {
- logger
- .error("Caught I/O Exception when trying to accept a new connection");
return;
}
}
serverSelectionKey);
}
}
- } catch (IOException e) {
- logger.error("Caught I/O Exception: " + e.toString());
- return;
+ } catch (Exception e) {
+ continue;
}
}
}
logger.info("Controller is now listening on port " + openFlowPort);
}
- public void shutDown() {
+ public void shutDown() throws IOException {
this.running = false;
this.selector.wakeup();
- try {
- this.serverSocket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ this.serverSocket.close();
}
}
package org.opendaylight.controller.protocol_plugin.openflow.core.internal;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
handleMessages();
}
}
- } catch (IOException e) {
- logger.error("Caught I/O Exception: " + e.toString());
- e.printStackTrace();
+ } catch (Exception e) {
+ reportError(e);
}
}
}
this.clientSelectionKey.cancel();
this.socket.close();
executor.shutdown();
- } catch (IOException e) {
- logger.error("Caught IOException in stop()");
+ } catch (Exception e) {
+ // do nothing since we are shutting down.
+ return;
}
}
this.selector, SelectionKey.OP_WRITE, this);
}
logger.trace("Message sent: " + msg.toString());
- } catch (IOException e) {
+ } catch (Exception e) {
reportError(e);
}
}
this.clientSelectionKey = this.socket.register(
this.selector, SelectionKey.OP_READ, this);
}
- } catch (IOException e) {
+ } catch (Exception e) {
reportError(e);
}
}
int bytesRead;
try {
bytesRead = socket.read(inBuffer);
- } catch (IOException e) {
+ } catch (Exception e) {
reportError(e);
return null;
}
org.slf4j,
org.opendaylight.controller.sal.routing,
org.opendaylight.controller.sal.core,
- org.opendaylight.controller.sal.topology,
org.opendaylight.controller.sal.utils,
org.opendaylight.controller.sal.reader,
org.apache.commons.collections15,
org.opendaylight.controller.switchmanager,
+ org.opendaylight.controller.topologymanager,
edu.uci.ics.jung.graph,
edu.uci.ics.jung.algorithms.shortestpath,
edu.uci.ics.jung.graph.util,
<artifactId>switchmanager</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>topologymanager</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
import org.opendaylight.controller.sal.routing.IListenRoutingUpdates;
import org.opendaylight.controller.sal.routing.IRouting;
-import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.sal.reader.IReadService;
+import org.opendaylight.controller.topologymanager.ITopologyManager;
+import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
public class Activator extends ComponentActivatorAbstractBase {
protected static final Logger logger = LoggerFactory
*
*/
public void init() {
- logger.debug("routing.dijkstra_implementation INIT called!");
}
/**
if (imp.equals(DijkstraImplementation.class)) {
// export the service
Dictionary<String, String> props = new Hashtable<String, String>();
- props.put("salListenerName", "routing.Dijkstra");
- c.setInterface(new String[] { IListenTopoUpdates.class.getName(),
+ props.put("topoListenerName", "routing.Dijkstra");
+ c.setInterface(new String[] { ITopologyManagerAware.class.getName(),
IRouting.class.getName() }, props);
// Now lets add a service dependency to make sure the
ISwitchManager.class).setCallbacks("setSwitchManager",
"unsetSwitchManager").setRequired(true));
+ c.add(createContainerServiceDependency(containerName).setService(
+ ITopologyManager.class).setCallbacks("setTopologyManager",
+ "unsetTopologyManager").setRequired(true));
+
c.add(createContainerServiceDependency(containerName).setService(
IReadService.class).setCallbacks("setReadService",
"unsetReadService").setRequired(true));
import org.opendaylight.controller.sal.core.Path;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
import org.opendaylight.controller.sal.reader.IReadService;
import org.opendaylight.controller.sal.routing.IListenRoutingUpdates;
import org.opendaylight.controller.sal.routing.IRouting;
-import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.controller.topologymanager.ITopologyManager;
+import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
import edu.uci.ics.jung.graph.Graph;
import java.lang.Exception;
import java.lang.IllegalArgumentException;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Map;
import org.slf4j.LoggerFactory;
import org.apache.commons.collections15.Transformer;
-public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
+public class DijkstraImplementation implements IRouting, ITopologyManagerAware {
private static Logger log = LoggerFactory
.getLogger(DijkstraImplementation.class);
private ConcurrentMap<Short, Graph<Node, Edge>> topologyBWAware;
DijkstraShortestPath<Node, Edge> mtp; //Max Throughput Path
private Set<IListenRoutingUpdates> routingAware;
private ISwitchManager switchManager;
+ private ITopologyManager topologyManager;
private IReadService readService;
private static final long DEFAULT_LINK_SPEED = Bandwidth.BW1Gbps;
this.routingAware = new HashSet<IListenRoutingUpdates>();
}
if (this.routingAware != null) {
- log.debug("Adding routingAware listener");
+ log.debug("Adding routingAware listener: " + i);
this.routingAware.add(i);
}
}
}
}
- @SuppressWarnings( { "unchecked", "rawtypes" })
- public DijkstraImplementation() {
- this.topologyBWAware = (ConcurrentMap<Short, Graph<Node, Edge>>) new ConcurrentHashMap();
- this.sptBWAware = (ConcurrentMap<Short, DijkstraShortestPath<Node, Edge>>) new ConcurrentHashMap();
- // Now create the default topology, which doesn't consider the
- // BW, also create the corresponding Dijkstra calculation
- Graph<Node, Edge> g = new SparseMultigraph();
- Short sZero = Short.valueOf((short) 0);
- this.topologyBWAware.put(sZero, g);
- this.sptBWAware.put(sZero, new DijkstraShortestPath(g));
- // Topologies for other BW will be added on a needed base
- }
-
@Override
public synchronized void initMaxThroughput(
final Map<Edge, Number> EdgeWeightMap) {
}
}
- public void startUp() {
- log.debug(this.getClass().getName() + ":startUp Method Called");
+ /**
+ * Function called by the dependency manager when all the required
+ * dependencies are satisfied
+ *
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void init() {
+ log.debug("Routing init() is called");
+ this.topologyBWAware = (ConcurrentMap<Short, Graph<Node, Edge>>) new ConcurrentHashMap();
+ this.sptBWAware = (ConcurrentMap<Short, DijkstraShortestPath<Node, Edge>>) new ConcurrentHashMap();
+ // Now create the default topology, which doesn't consider the
+ // BW, also create the corresponding Dijkstra calculation
+ Graph<Node, Edge> g = new SparseMultigraph();
+ Short sZero = Short.valueOf((short) 0);
+ this.topologyBWAware.put(sZero, g);
+ this.sptBWAware.put(sZero, new DijkstraShortestPath(g));
+ // Topologies for other BW will be added on a needed base
}
-
- public void shutDown() {
- log.debug(this.getClass().getName() + ":shutDown Method Called");
+ /**
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
+ */
+ void destroy() {
+ log.debug("Routing destroy() is called");
}
+ /**
+ * Function called by dependency manager after "init ()" is called
+ * and after the services provided by the class are registered in
+ * the service registry
+ *
+ */
+ void start() {
+ log.debug("Routing start() is called");
+ // build the routing database from the topology if it exists.
+ Map<Edge, Set<Property>> edges = topologyManager.getEdges();
+ if (edges.isEmpty()) {
+ return;
+ }
+ log.debug("Creating routing database from the topology");
+ for (Iterator<Map.Entry<Edge,Set<Property>>> i = edges.entrySet().iterator(); i.hasNext();) {
+ Map.Entry<Edge, Set<Property>> entry = i.next();
+ Edge e = entry.getKey();
+ Set<Property> props = entry.getValue();
+ edgeUpdate(e, UpdateType.ADDED, props);
+ }
+ }
+
+ /**
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
+ */
+ public void stop() {
+ log.debug("Routing stop() is called");
+ }
+
@Override
public void edgeOverUtilized(Edge edge) {
// TODO Auto-generated method stub
this.readService = null;
}
}
+
+ public void setTopologyManager(ITopologyManager tm) {
+ this.topologyManager = tm;
+ }
+
+ public void unsetTopologyManager(ITopologyManager tm) {
+ if (this.topologyManager == tm) {
+ this.topologyManager = null;
+ }
+ }
}
@Test
public void testSinglePathRouteNoBw() {
DijkstraImplementation imp = new DijkstraImplementation();
+ imp.init();
Node node1 = NodeCreator.createOFNode((long) 1);
Node node2 = NodeCreator.createOFNode((long) 2);
Node node3 = NodeCreator.createOFNode((long) 3);
@Test
public void testShortestPathRouteNoBw() {
DijkstraImplementation imp = new DijkstraImplementation();
+ imp.init();
Node node1 = NodeCreator.createOFNode((long) 1);
Node node2 = NodeCreator.createOFNode((long) 2);
Node node3 = NodeCreator.createOFNode((long) 3);
@Test
public void testShortestPathRouteNoBwAfterLinkDelete() {
DijkstraImplementation imp = new DijkstraImplementation();
+ imp.init();
Node node1 = NodeCreator.createOFNode((long) 1);
Node node2 = NodeCreator.createOFNode((long) 2);
Node node3 = NodeCreator.createOFNode((long) 3);
@Test
public void testMaxThruPut() {
DijkstraImplementation imp = new DijkstraImplementation();
+ imp.init();
Node node1 = NodeCreator.createOFNode((long) 1);
Node node2 = NodeCreator.createOFNode((long) 2);
Node node3 = NodeCreator.createOFNode((long) 3);
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.sal.binding.impl;
import java.util.HashMap;
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.binding.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class BrokerUtils {
+ private BrokerUtils() {
+
+ }
+
+
+ public static <K,V> void addToMap(Map<Class<? extends K>, List<V>> map, Class<? extends K> key, V value) {
+ List<V> list = map.get(key);
+ if (list == null) {
+ list = new ArrayList<V>();
+ map.put(key, list);
+ }
+ list.add(value);
+ }
+
+ public static <K,V> void removeFromMap(Map<Class<? extends K>, List<V>> map, Class<? extends K> key,
+ V value) {
+ List<V> list = map.get(key);
+ if (list == null) {
+ return;
+ }
+ list.remove(value);
+ if (list.isEmpty()) {
+ map.remove(key);
+ }
+ }
+}
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.sal.binding.impl;
import org.opendaylight.controller.sal.binding.spi.MappingProvider.MappingExtension;
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.sal.binding.impl;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import org.opendaylight.controller.sal.binding.spi.Mapper;
import org.opendaylight.controller.sal.binding.spi.MappingProvider;
import org.opendaylight.controller.sal.binding.spi.MappingProvider.MappingExtensionFactory;
-import org.opendaylight.controller.sal.core.api.Provider;
+
import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
import org.opendaylight.controller.yang.binding.DataObject;
import org.opendaylight.controller.yang.binding.Notification;
private MappingProvider mappingProvider;
private Map<Class<? extends Notification>, List<NotificationListener>> listeners = new HashMap<Class<? extends Notification>, List<NotificationListener>>();
- private static Logger log = LoggerFactory.getLogger(NotificationModule.class);
+ private Set<QName> biNotifications = new HashSet<QName>();
+ private static final Logger log = LoggerFactory
+ .getLogger(NotificationModule.class);
+ private final BindingIndependentListener biListener = new BindingIndependentListener();
@Override
public Set<Class<? extends BindingAwareService>> getProvidedServices() {
biNotifyService.sendNotification(domNotification);
}
+ private void addBAListener(Class<? extends Notification> notificationType,
+ NotificationListener listener) {
+
+ BrokerUtils.addToMap(listeners, notificationType, listener);
+ Mapper<? extends Notification> mapper = mappingProvider
+ .getMapper(notificationType);
+ QName biType = mapper.getQName();
+ if (false == biNotifications.contains(biType)) {
+ // The listener is not registered for binding independent
+ // notification
+ biNotifications.add(biType);
+
+ if (biNotifyService != null) {
+ biNotifyService.addNotificationListener(biType, biListener);
+ }
+ }
+
+ }
+
+ private void removeBAListener(
+ Class<? extends Notification> notificationType,
+ NotificationListener listener) {
+ BrokerUtils.removeFromMap(listeners, notificationType, listener);
+ }
+
private class NotificationSession implements NotificationService {
private final ConsumerSession session;
public void addNotificationListener(
Class<? extends Notification> notificationType,
NotificationListener listener) {
- // TODO Implement this method
- throw new UnsupportedOperationException("Not implemented");
+
+ NotificationModule.this.addBAListener(notificationType, listener);
+ BrokerUtils.addToMap(sessionListeners, notificationType, listener);
+
}
@Override
public void removeNotificationListener(
Class<? extends Notification> notificationType,
NotificationListener listener) {
- // TODO Implement this method
- throw new UnsupportedOperationException("Not implemented");
+ BrokerUtils.removeFromMap(sessionListeners, notificationType,
+ listener);
+ NotificationModule.this
+ .removeBAListener(notificationType, listener);
}
}
}
}
-
- private class BindingIndependentListener implements org.opendaylight.controller.sal.core.api.notify.NotificationListener {
+
+ private class BindingIndependentListener
+ implements
+ org.opendaylight.controller.sal.core.api.notify.NotificationListener {
@Override
public Set<QName> getSupportedNotifications() {
- return Collections.emptySet();
+ return biNotifications;
}
@Override
public void onNotification(CompositeNode notification) {
- NotificationModule.this.onBindingIndependentNotification(notification);
+ NotificationModule.this
+ .onBindingIndependentNotification(notification);
}
-
+
}
private void onBindingIndependentNotification(CompositeNode biNotification) {
QName biType = biNotification.getNodeType();
-
+
Mapper<DataObject> mapper = mappingProvider.getMapper(biType);
- if(mapper == null) {
+ if (mapper == null) {
log.info("Received notification does not have a binding defined.");
return;
}
Class<DataObject> type = mapper.getDataObjectClass();
-
+
// We check if the received QName / type is really Notification
- if(Notification.class.isAssignableFrom(type)) {
- Notification notification = (Notification) mapper.objectFromDom(biNotification);
+ if (Notification.class.isAssignableFrom(type)) {
+ Notification notification = (Notification) mapper
+ .objectFromDom(biNotification);
notifyBindingAware(notification);
} else {
- // The generated type for this QName does not inherits from notification
- // something went wrong - generated APIs and/or provider sending notification
+ // The generated type for this QName does not inherits from
+ // notification something went wrong - generated APIs and/or
+ // provider sending notification
// which was incorectly described in the YANG schema.
- log.error("Received notification "+ biType +" is not binded as notification");
+ log.error("Received notification " + biType
+ + " is not binded as notification");
}
-
+
}
}
package org.opendaylight.controller.sal.core.api.notify;\r
\r
import org.opendaylight.controller.sal.core.api.Broker;\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
import org.opendaylight.controller.sal.core.api.Provider;\r
import org.opendaylight.controller.yang.data.api.CompositeNode;\r
\r
* \r
* \r
*/\r
-public interface NotificationProviderService extends BrokerService {\r
+public interface NotificationProviderService extends NotificationService {\r
\r
/**\r
* Publishes a notification.\r
void setTopologyManagerAware(ITopologyManagerAware s) {
if (this.topologyManagerAware != null) {
+ log.debug("Adding ITopologyManagerAware: " + s);
this.topologyManagerAware.add(s);
}
}
@RequestMapping("/")
public class Flows implements IOneWeb {
private static final UserLevel AUTH_LEVEL = UserLevel.CONTAINERUSER;
- private final String WEB_NAME = "Flows";
- private final String WEB_ID = "flows";
- private final short WEB_ORDER = 2;
+ private static final String WEB_NAME = "Flows";
+ private static final String WEB_ID = "flows";
+ private static final short WEB_ORDER = 2;
public Flows() {
ServiceHelper.registerGlobalService(IOneWeb.class, this, null);
// fetch frm
IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
.getInstance(IForwardingRulesManager.class, "default", this);
- if (frm == null)
- return null;
+ if (frm == null) { return null; }
// fetch sm
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, "default", this);
- if (switchManager == null)
- return null;
+ if (switchManager == null) { return null; }
// get static flow list
List<FlowConfig> staticFlowList = frm.getStaticFlows();
public Map<String, Object> getNodePorts() {
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, "default", this);
- if (switchManager == null)
- return null;
+ if (switchManager == null) { return null; }
Map<String, Object> nodes = new HashMap<String, Object>();
Map<Short, String> port;
port = new HashMap<Short, String>(); // new port
Set<NodeConnector> nodeConnectorSet = node.getNodeConnectors();
- if (nodeConnectorSet != null)
+ if (nodeConnectorSet != null) {
for (NodeConnector nodeConnector : nodeConnectorSet) {
String nodeConnectorName = ((Name) switchManager
.getNodeConnectorProp(nodeConnector,
nodeConnectorName + "("
+ nodeConnector.getNodeConnectorIDString() + ")");
}
+ }
// add ports
Map<String, Object> entry = new HashMap<String, Object>();
@ResponseBody
public String actionFlow(@RequestParam(required = true) String action,
@RequestParam(required = false) String body, @RequestParam(required = true) String nodeId) {
- if (!authorize(UserLevel.NETWORKADMIN)) {
+ if (!isUserAuthorized(UserLevel.NETWORKADMIN)) {
return "Operation not authorized";
}
FlowConfig flow = gson.fromJson(body, FlowConfig.class);
Node node = Node.fromString(nodeId);
flow.setNode(node);
- Status result = null;
+ Status result = new Status(StatusCode.BADREQUEST, "Invalid request");
if (action.equals("add")) {
result = frm.addStaticFlow(flow, false);
}
- return result.getDescription();
+ return (result.isSuccess())? StatusCode.SUCCESS.toString(): result.getDescription();
}
@RequestMapping(value = "/flow/{nodeId}/{name}", method = RequestMethod.POST)
@ResponseBody
public String removeFlow(@PathVariable("nodeId") String nodeId, @PathVariable("name") String name,
@RequestParam(required = true) String action) {
- if (!authorize(UserLevel.NETWORKADMIN)) { return "Operation not authorized"; }
+ if (!isUserAuthorized(UserLevel.NETWORKADMIN)) { return "Operation not authorized"; }
IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
.getInstance(IForwardingRulesManager.class, "default", this);
Status result = null;
Node node = Node.fromString(nodeId);
- if (node == null) {
- return null;
- }
+ if (node == null) { return null; }
if (action.equals("remove")) {
result = frm.removeStaticFlow(name, node);
} else if (action.equals("toggle")) {
- FlowConfig config = frm.getStaticFlow(name, node);
- result = frm.toggleStaticFlowStatus(config);
+ result = frm.toggleStaticFlowStatus(name, node);
} else {
result = new Status(StatusCode.BADREQUEST, "Unknown action");
}
- return result.getDescription();
+ return (result.isSuccess())? StatusCode.SUCCESS.toString(): result.getDescription();
}
/**
- * Is the operation permitted for the given level
+ * Returns whether the current user's level is same or above
+ * the required authorization level.
*
- * @param level
+ * @param requiredLevel the authorization level required
*/
- private boolean authorize(UserLevel level) {
+ private boolean isUserAuthorized(UserLevel requiredLevel) {
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);
- if (userManager == null) {
- return false;
- }
+ if (userManager == null) { return false; }
String username = SecurityContextHolder.getContext().getAuthentication().getName();
UserLevel userLevel = userManager.getUserLevel(username);
- if (userLevel.toNumber() <= level.toNumber()) {
- return true;
- }
- return false;
+ return (userLevel.ordinal() <= requiredLevel.ordinal());
}
}