1 package org.opendaylight.controller.web;
5 import javax.servlet.http.HttpServletRequest;
7 import org.opendaylight.controller.containermanager.IContainerAuthorization;
8 import org.opendaylight.controller.sal.authorization.Resource;
9 import org.opendaylight.controller.sal.utils.GlobalConstants;
10 import org.opendaylight.controller.sal.utils.ServiceHelper;
12 public class DaylightWebUtil {
13 private static String defaultName = GlobalConstants.DEFAULT.toString();
16 * Returns the container that this user is authorized to access. If the user is not authorized to the requested
17 * container, then this method will return the default container.
19 * @param request - HttpServletRequest object to retrieve username
20 * @param container - requested container
21 * @param bundle - respective bundle
22 * @return container name if cleared, else it will always be 'default'
24 public static String getAuthorizedContainer(HttpServletRequest request, String container, Object bundle) {
25 if (container == null) {
29 String username = request.getUserPrincipal().getName();
30 IContainerAuthorization containerAuthorization = (IContainerAuthorization)
31 ServiceHelper.getGlobalInstance(IContainerAuthorization.class, bundle);
32 if (containerAuthorization != null) {
33 Set<Resource> resources = containerAuthorization.getAllResourcesforUser(username);
34 for(Resource resource : resources) {
35 String name = (String) resource.getResource();
36 if(container.equals(name)) {