예제 #1
0
 public static void buildMenuItems(HttpServletRequest request, String s, String s1, String s2) {
   int menuOrder = 50;
   if (CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/resources/ws-api")) {
     HttpSession session = request.getSession();
     String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
     try {
       WSRegistryServiceClient registry = new WSRegistryServiceClient(s2, cookie);
       List<GovernanceArtifactConfiguration> configurations =
           GovernanceUtils.findGovernanceArtifactConfigurations(registry);
       Map<String, String> customAddUIMap = new LinkedHashMap<String, String>();
       Map<String, String> customViewUIMap = new LinkedHashMap<String, String>();
       List<Menu> userCustomMenuItemsList = new LinkedList<Menu>();
       for (GovernanceArtifactConfiguration configuration : configurations) {
         Component component = new Component();
         OMElement uiConfigurations = configuration.getUIConfigurations();
         String key = configuration.getKey();
         String configurationPath =
             RegistryConstants.CONFIG_REGISTRY_BASE_PATH
                 + RegistryConstants.GOVERNANCE_COMPONENT_PATH
                 + "/configuration/";
         String layoutStoragePath = configurationPath + key;
         RealmService realmService = registry.getRegistryContext().getRealmService();
         if (realmService
                 .getTenantUserRealm(realmService.getTenantManager().getTenantId(s1))
                 .getAuthorizationManager()
                 .isUserAuthorized(s, configurationPath, ActionConstants.PUT)
             || registry.resourceExists(layoutStoragePath)) {
           List<Menu> menuList = component.getMenusList();
           if (uiConfigurations != null) {
             ComponentBuilder.processMenus("artifactType", uiConfigurations, component);
             ComponentBuilder.processCustomUIs(uiConfigurations, component);
           }
           if (menuList.size() == 0) {
             // if no menu definitions were present, define the default ones.
             menuOrder = buildMenuList(request, configuration, menuList, key, menuOrder);
           }
           userCustomMenuItemsList.addAll(menuList);
           customAddUIMap.putAll(component.getCustomAddUIMap());
           Map<String, String> viewUIMap = component.getCustomViewUIMap();
           if (viewUIMap.isEmpty()) {
             // if no custom UI definitions were present, define the default.
             buildViewUI(configuration, viewUIMap, key);
           }
           customViewUIMap.putAll(viewUIMap);
           OMElement layout = configuration.getContentDefinition();
           if (layout != null && !registry.resourceExists(layoutStoragePath)) {
             Resource resource = registry.newResource();
             resource.setContent(RegistryUtils.encodeString(layout.toString()));
             resource.setMediaType("application/xml");
             registry.put(layoutStoragePath, resource);
           }
         }
       }
       session.setAttribute(
           MenuAdminClient.USER_CUSTOM_MENU_ITEMS,
           userCustomMenuItemsList.toArray(new Menu[userCustomMenuItemsList.size()]));
       session.setAttribute("customAddUI", customAddUIMap);
       session.setAttribute("customViewUI", customViewUIMap);
     } catch (RegistryException e) {
       log.error("unable to create connection to registry");
     } catch (org.wso2.carbon.user.api.UserStoreException e) {
       log.error("unable to realm service");
     }
   }
 }
예제 #2
0
  private static int buildMenuList(
      HttpServletRequest request,
      GovernanceArtifactConfiguration configuration,
      List<Menu> menuList,
      String key,
      int menuOrder) {
    String singularLabel = configuration.getSingularLabel();
    String pluralLabel = configuration.getPluralLabel();
    boolean hasNamespace = configuration.hasNamespace();
    String lifecycleAttribute = key + "Lifecycle_lifecycleName";

    lifecycleAttribute =
        BuilLifecycleAttribute(
            configuration, DEFAULT_LIFECYCLE_GENERATOR_CLASS, lifecycleAttribute);

    if (singularLabel == null || pluralLabel == null) {
      log.error(
          "The singular label and plural label have not "
              + "been defined for the artifact type: "
              + key);
    } else {
      int iconSet = configuration.getIconSet();
      if (CarbonUIUtil.isUserAuthorized(
              request, "/permission/admin/manage/resources/govern/" + key + "/add")
          && CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/resources/browse")
          && CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/resources/ws-api")) {
        Menu addMenu = new Menu();
        addMenu.setId("governance_add_" + key + "_menu");
        addMenu.setI18nKey(singularLabel);
        addMenu.setParentMenu("add_sub_menu");
        if (configuration.getExtension() == null) {
          addMenu.setLink("../generic/add_edit.jsp");
          addMenu.setUrlParameters(
              "key="
                  + key
                  + "&lifecycleAttribute="
                  + lifecycleAttribute
                  + "&breadcrumb="
                  + singularLabel);
        } else {
          addMenu.setLink("../generic/add_content.jsp");
          addMenu.setUrlParameters(
              "key="
                  + key
                  + "&lifecycleAttribute="
                  + lifecycleAttribute
                  + "&breadcrumb="
                  + singularLabel
                  + "&mediaType="
                  + configuration.getMediaType()
                  + "&extension="
                  + configuration.getExtension()
                  + "&singularLabel="
                  + singularLabel
                  + "&pluralLabel="
                  + pluralLabel
                  + "&hasNamespace"
                  + hasNamespace);
        }
        addMenu.setRegion("region3");
        addMenu.setOrder(String.valueOf(menuOrder));
        addMenu.setStyleClass("manage");
        if (iconSet > 0) {
          addMenu.setIcon("../generic/images/add" + iconSet + ".png");
        } else {
          addMenu.setIcon("../images/add.gif");
        }
        addMenu.setAllPermissionsRequired(true);
        addMenu.setRequirePermission(
            new String[] {
              "/permission/admin/manage/resources/govern/" + key + "/add",
              "/permission/admin/manage/resources/browse",
              "/permission/admin/manage/resources/ws-api"
            });
        menuList.add(addMenu);
      }

      if (CarbonUIUtil.isUserAuthorized(
              request, "/permission/admin/manage/resources/govern/" + key + "/list")
          && CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/resources/ws-api")) {
        Menu listMenu = new Menu();
        listMenu.setId("governance_list_" + key + "_menu");
        listMenu.setI18nKey(pluralLabel);
        listMenu.setParentMenu("list_sub_menu");
        if (configuration.getExtension() == null) {
          listMenu.setLink("../generic/list.jsp");
          listMenu.setUrlParameters(
              "key="
                  + key
                  + "&breadcrumb="
                  + pluralLabel
                  + "&singularLabel="
                  + singularLabel
                  + "&pluralLabel="
                  + pluralLabel);
        } else {
          listMenu.setLink("../generic/list_content.jsp");
          listMenu.setUrlParameters(
              "key="
                  + key
                  + "&lifecycleAttribute="
                  + lifecycleAttribute
                  + "&breadcrumb="
                  + singularLabel
                  + "&mediaType="
                  + configuration.getMediaType()
                  + "&singularLabel="
                  + singularLabel
                  + "&pluralLabel="
                  + pluralLabel
                  + "&hasNamespace="
                  + hasNamespace);
        }
        listMenu.setRegion("region3");
        listMenu.setOrder(String.valueOf(menuOrder));
        listMenu.setStyleClass("manage");
        if (iconSet > 0) {
          listMenu.setIcon("../generic/images/list" + iconSet + ".png");
        } else {
          listMenu.setIcon("../images/list.gif");
        }
        listMenu.setAllPermissionsRequired(true);
        listMenu.setRequirePermission(
            new String[] {
              "/permission/admin/manage/resources/govern/" + key + "/list",
              "/permission/admin/manage/resources/ws-api"
            });
        menuList.add(listMenu);
      }
      /*if (CarbonUIUtil.isUserAuthorized(request,
              "/permission/admin/configure/governance/" + key + "-ui")) {
          Menu configureMenu = new Menu();
          configureMenu.setId("governance_" + key + "_config_menu");
          configureMenu.setI18nKey(pluralLabel);
          configureMenu.setParentMenu("configure_menu");
          configureMenu.setLink("../generic/configure.jsp");
          configureMenu.setUrlParameters("key=" + key + "&breadcrumb=" + pluralLabel +
                  "&add_edit_region=region3&add_edit_item=governance_add_" + key + "_menu" +
                  "&lifecycleAttribute=" + lifecycleAttribute +
                  "&add_edit_breadcrumb=" + singularLabel + "&singularLabel=" + singularLabel +
                  "&pluralLabel=" + pluralLabel);
          configureMenu.setRegion("region1");
          configureMenu.setOrder("40");
          configureMenu.setStyleClass("manage");
          if (iconSet > 0) {
              configureMenu.setIcon("../generic/images/configure" + iconSet + ".png");
          } else {
              configureMenu.setIcon("../generic/images/services1.gif");
          }
          configureMenu.setRequirePermission(
                  new String[]{"/permission/admin/configure/governance/" + key + "-ui"});
          menuList.add(configureMenu);
      }*/
      menuOrder++;
    }
    return menuOrder;
  }