Exemplo n.º 1
0
  /**
   * Finds the integration point of the specified type. Returns the contents of this IP type as a
   * list. The content can be a comma separated String. This is useful for the case such as dropdown
   * or list box to allow additional options in the component.
   */
  @Handler(
      id = "getContentOfIntegrationPoints",
      input = {@HandlerInput(name = "type", type = String.class, required = true)},
      output = {
        @HandlerOutput(name = "labels", type = List.class),
        @HandlerOutput(name = "values", type = List.class)
      })
  public static void getContentOfIntegrationPoints(HandlerContext handlerCtx)
      throws java.io.IOException {
    // Get the input
    String type = (String) handlerCtx.getInputValue("type");

    // Get the IntegrationPoints
    FacesContext ctx = handlerCtx.getFacesContext();
    Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type));
    List labels = new ArrayList();
    List values = new ArrayList();
    if (points != null) {
      for (IntegrationPoint it : points) {
        String content = it.getContent();
        if (GuiUtil.isEmpty(content)) {
          GuiUtil.getLogger()
              .warning(
                  "No Content specified for Integration Point: " + type + " id : " + it.getId());
          continue;
        }
        List<String> labelsAndValues = GuiUtil.parseStringList(content, "|");
        values.add(labelsAndValues.get(0));
        labels.add(GuiUtil.getMessage(labelsAndValues.get(1), labelsAndValues.get(2)));
      }
    }
    handlerCtx.setOutputValue("labels", labels);
    handlerCtx.setOutputValue("values", values);
  }
Exemplo n.º 2
0
  /**
   * This handler is used for the navigation nodes that request content from an external URL. This
   * handler pulls the "real url" from from the component specified by the <code>compId</code>
   * parameter (this necessarily depends on the presence of the navigation container in the view for
   * the component look up to work). Once the component has been found, the url is retrieved from
   * the attribute map, and its contents retrieved. If <code>processPage</code> is true, the URL
   * contents are interpretted and the resulting component(s) are added to the component tree (This
   * feature is not currently supported).. Otherwise, the contents are returned in the output
   * parameter <code>pluginPage</code> to be output as-is on the page.
   *
   * @param handlerCtx The <code>HandlerContext</code>.
   */
  @Handler(
      id = "retrievePluginPageContents",
      input = {@HandlerInput(name = "compId", type = String.class, required = true)},
      output = {@HandlerOutput(name = "pluginPage", type = String.class)})
  public static void retrievePluginPageContents(HandlerContext handlerCtx) {
    String id = (String) handlerCtx.getInputValue("compId");
    UIComponent comp = handlerCtx.getFacesContext().getViewRoot().findComponent(id);
    String urlContents = "";
    if (comp != null) {
      String url = (String) comp.getAttributes().get(NavigationNodeFactory.REAL_URL);
      try {
        // Read from the URL...
        URL contentUrl = FileUtil.searchForFile(url, null);
        if (contentUrl == null) {
          throw new IOException("Unable to locate file: " + url);
        }
        urlContents = new String(FileUtil.readFromURL(contentUrl));

        // FIXME: Implement processPage support
        /*
        if (processPage) {
            // probably do something like what includeIntegrations does
            ...
        }
        */
      } catch (IOException ex) {
        Logger.getLogger(PluginHandlers.class.getName())
            .log(Level.SEVERE, "Unable to read url: " + url, ex);
      }
    }

    // Set the content to output...
    handlerCtx.setOutputValue("pluginPage", urlContents);
  }
Exemplo n.º 3
0
  @Handler(
      id = "addDefaultProviderInfo",
      input = {
        @HandlerInput(name = "providerList", type = List.class, required = true),
        @HandlerInput(name = "configName", type = String.class, required = true),
        @HandlerInput(name = "msgSecurityName", type = String.class, required = true)
      })
  public static void addDefaultProviderInfo(HandlerContext handlerCtx) {
    List<HashMap> providerList = (ArrayList<HashMap>) handlerCtx.getInputValue("providerList");
    String configName = (String) handlerCtx.getInputValue("configName");
    String msgSecurityName = (String) handlerCtx.getInputValue("msgSecurityName");

    String endpoint =
        GuiUtil.getSessionValue("REST_URL")
            + "/configs/config/"
            + configName
            + "/security-service/message-security-config/"
            + msgSecurityName;
    Map<String, Object> valueMap =
        (Map<String, Object>) RestUtil.getEntityAttrs(endpoint, "entity");
    String defaultProvider = (String) valueMap.get("defaultProvider");
    String defaultClientProvider = (String) valueMap.get("defaultClientProvider");
    String trueStr = GuiUtil.getMessage("common.true");
    String falseStr = GuiUtil.getMessage("common.false");
    for (Map oneRow : providerList) {
      if (oneRow.get("name").equals(defaultProvider)
          || oneRow.get("name").equals(defaultClientProvider)) {
        oneRow.put("default", trueStr);
      } else {
        oneRow.put("default", falseStr);
      }
    }
  }
Exemplo n.º 4
0
 @Handler(
     id = "getProvidersByType",
     input = {
       @HandlerInput(name = "msgSecurityName", type = String.class, required = true),
       @HandlerInput(name = "configName", type = String.class, required = true),
       @HandlerInput(name = "type", type = List.class, required = true)
     },
     output = {@HandlerOutput(name = "result", type = List.class)})
 public static void getProvidersByType(HandlerContext handlerCtx) throws Exception {
   List type = (List) handlerCtx.getInputValue("type");
   List result = new ArrayList();
   String configName = (String) handlerCtx.getInputValue("configName");
   String msgSecurityName = (String) handlerCtx.getInputValue("msgSecurityName");
   String endpoint =
       GuiUtil.getSessionValue("REST_URL")
           + "/configs/config/"
           + configName
           + "/security-service/message-security-config/"
           + msgSecurityName
           + "/provider-config";
   List<String> providers = (List<String>) RestUtil.getChildList(endpoint);
   for (String providerEndpoint : providers) {
     Map providerAttrs = (HashMap) RestUtil.getAttributesMap(providerEndpoint);
     String providerType = (String) providerAttrs.get("providerType");
     if (type.contains(providerType)) {
       result.add(
           com.sun.jsftemplating.util.Util.htmlEscape((String) providerAttrs.get("providerId")));
     }
   }
   result.add(0, "");
   handlerCtx.setOutputValue("result", result);
 }
Exemplo n.º 5
0
 @Handler(
     id = "getMessageSecurityAuthLayersForCreate",
     input = {
       @HandlerInput(name = "attrMap", type = Map.class, required = true),
       @HandlerInput(name = "configName", type = String.class, required = true),
       @HandlerInput(name = "propList", type = List.class, required = true)
     },
     output = {@HandlerOutput(name = "layers", type = List.class)})
 public static void getMessageSecurityAuthLayersForCreate(HandlerContext handlerCtx)
     throws Exception {
   List layers = new ArrayList();
   String configName = (String) handlerCtx.getInputValue("configName");
   layers.add("SOAP");
   layers.add("HttpServlet");
   String endpoint =
       GuiUtil.getSessionValue("REST_URL")
           + "/configs/config/"
           + configName
           + "/security-service/message-security-config";
   Set<String> msgSecurityCfgs = (Set<String>) (RestUtil.getChildMap(endpoint)).keySet();
   for (String name : msgSecurityCfgs) {
     if (layers.contains(name)) {
       layers.remove(name);
     }
   }
   handlerCtx.setOutputValue("layers", layers);
 }
Exemplo n.º 6
0
  @Handler(
      id = "getPluginIdFromViewId",
      input = {@HandlerInput(name = "viewId", type = String.class, required = true)},
      output = {@HandlerOutput(name = "pluginId", type = String.class)})
  public static void getPluginIdFromViewId(HandlerContext handlerCtx) {
    String viewId = (String) handlerCtx.getInputValue("viewId");
    if (viewId == null) {
      return;
    }
    ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext());
    String pluginId = "common";
    int next = viewId.indexOf("/", 1);
    if (next > -1) {
      pluginId = viewId.substring(0, next);
      String resource = viewId.substring(next);

      if (pluginId.startsWith("/")) {
        pluginId = pluginId.substring(1);
      }

      ClassLoader cl = cps.getModuleClassLoader(pluginId);
      URL url = null;
      if (cl != null) {
        url = cl.getResource(resource);
      }
      if (url == null) {
        pluginId = "common";
      }
    }
    handlerCtx.setOutputValue("pluginId", pluginId);
  }
Exemplo n.º 7
0
  @Handler(
      id = "calculateHelpUrl",
      input = {
        @HandlerInput(name = "pluginId", type = String.class, required = true),
        @HandlerInput(name = "helpKey", type = String.class, required = true)
      },
      output = {@HandlerOutput(name = "url", type = String.class)})
  public static void calculateHelpUrl(HandlerContext handlerCtx) {
    String pluginId = (String) handlerCtx.getInputValue("pluginId");
    String helpKey = (String) handlerCtx.getInputValue("helpKey");
    ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext());

    ClassLoader cl = cps.getModuleClassLoader(pluginId);

    // Try the viewRoot locale first
    String path =
        getHelpPathForResource(helpKey, handlerCtx.getFacesContext().getViewRoot().getLocale(), cl);
    if (path == null) {
      // Try the default locale
      path = getHelpPathForResource(helpKey, Locale.getDefault(), cl);

      // Default to en
      if (path == null) {
        path = "/en/help/" + helpKey;
      }
    }

    handlerCtx.setOutputValue("url", path);
  }
Exemplo n.º 8
0
  /**
   * This handler removes users for specified realm.
   *
   * @param handlerCtx The HandlerContext.
   */
  @Handler(
      id = "removeUser",
      input = {
        @HandlerInput(name = "Realm", type = String.class, required = true),
        @HandlerInput(name = "configName", type = String.class, required = true),
        @HandlerInput(name = "selectedRows", type = List.class, required = true)
      },
      output = {@HandlerOutput(name = "result", type = java.util.List.class)})
  public static void removeUser(HandlerContext handlerCtx) {

    String error = null;
    String realmName = (String) handlerCtx.getInputValue("Realm");
    String configName = (String) handlerCtx.getInputValue("configName");
    try {
      List obj = (List) handlerCtx.getInputValue("selectedRows");
      List<Map> selectedRows = (List) obj;
      for (Map oneRow : selectedRows) {
        String user = (String) oneRow.get("name");
        String endpoint =
            GuiUtil.getSessionValue("REST_URL")
                + "/configs/config/"
                + configName
                + "/admin-service/jmx-connector/system.json";
        Map<String, Object> responseMap =
            RestUtil.restRequest(endpoint, null, "get", handlerCtx, false);
        Map<String, Object> valueMap = (Map<String, Object>) responseMap.get("data");
        valueMap =
            (Map<String, Object>)
                ((Map<String, Object>) valueMap.get("extraProperties")).get("entity");
        String authRealm = (String) valueMap.get("authRealmName");
        if (realmName.equals(authRealm) && user.equals(GuiUtil.getSessionValue("userName"))) {
          error = GuiUtil.getMessage(COMMON_BUNDLE, "msg.error.cannotDeleteCurrent");
          continue;
        } else {
          HashMap attrs = new HashMap<String, Object>();
          endpoint =
              GuiUtil.getSessionValue("REST_URL")
                  + "/configs/config/"
                  + configName
                  + "/security-service/auth-realm/"
                  + realmName
                  + "/delete-user?target="
                  + configName;
          attrs.put("name", user);
          RestResponse response = RestUtil.delete(endpoint, attrs);
          if (!response.isSuccess()) {
            GuiUtil.getLogger()
                .severe("Remove user failed.  parent=" + endpoint + "; attrs =" + attrs);
            error = GuiUtil.getMessage("msg.error.checkLog");
          }
        }
      }
      if (error != null) {
        GuiUtil.prepareAlert("error", error, null);
      }
    } catch (Exception ex) {
      GuiUtil.handleException(handlerCtx, ex);
    }
  }
Exemplo n.º 9
0
 /**
  * This handler provides access to {@link IntegrationPoint}s for the requested key.
  *
  * @param handlerCtx The <code>HandlerContext</code>.
  */
 @Handler(
     id = "getIntegrationPoints",
     input = {@HandlerInput(name = "type", type = String.class, required = true)},
     output = {@HandlerOutput(name = "points", type = List.class)})
 public static void getIntegrationPoints(HandlerContext handlerCtx) {
   String type = (String) handlerCtx.getInputValue("type");
   List<IntegrationPoint> value = getIntegrationPoints(handlerCtx.getFacesContext(), type);
   handlerCtx.setOutputValue("points", value);
 }
Exemplo n.º 10
0
 /**
  * This handler returns a <code>Map&lt;String id, List&lt;URL&gt;&gt;</code> containing all the
  * matches of the requested resource. Each <code>List</code> in the <code>Map</code> is associated
  * with a GUI Plugin, and the key to the <code>Map</code> is the plugin id.
  *
  * @param handlerCtx The <code>HandlerContext</code>.
  */
 @Handler(
     id = "getPluginResources",
     input = {@HandlerInput(name = "name", type = String.class, required = true)},
     output = {@HandlerOutput(name = "resources", type = Map.class)})
 public static void getPluginResources(HandlerContext handlerCtx) {
   String name = (String) handlerCtx.getInputValue("name");
   ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext());
   handlerCtx.setOutputValue("resources", cps.getResources(name));
 }
Exemplo n.º 11
0
  @Handler(
      id = "saveSecurityManagerValue",
      input = {
        @HandlerInput(name = "configName", type = String.class),
        @HandlerInput(name = "value", type = String.class, required = true)
      })
  public static void saveSecurityManagerValue(HandlerContext handlerCtx) {
    try {
      String configName = (String) handlerCtx.getInputValue("configName");
      if (GuiUtil.isEmpty(configName)) configName = "server-config";
      String endpoint =
          GuiUtil.getSessionValue("REST_URL")
              + "/configs/config/"
              + configName
              + "/java-config/jvm-options.json";
      ArrayList<String> list;
      Map result = (HashMap) RestUtil.restRequest(endpoint, null, "GET", null, false).get("data");
      list =
          (ArrayList<String>) ((Map<String, Object>) result.get("extraProperties")).get("leafList");
      if (list == null) list = new ArrayList<String>();
      Boolean status = isSecurityManagerEnabled(list);
      String value = (String) handlerCtx.getInputValue("value");
      Boolean userValue = Boolean.valueOf(value);
      if (status.equals(userValue)) {
        // no need to change
        return;
      }

      ArrayList<String> newOptions = new ArrayList();
      Object[] origOptions = list.toArray();
      if (userValue) {
        for (int i = 0; i < origOptions.length; i++) {
          newOptions.add((String) origOptions[i]);
        }
        newOptions.add(JVM_OPTION_SECURITY_MANAGER);
      } else {
        for (int i = 0; i < origOptions.length; i++) {
          String str = (String) origOptions[i];
          if (!(str.trim().equals(JVM_OPTION_SECURITY_MANAGER)
              || str.trim().startsWith(JVM_OPTION_SECURITY_MANAGER_WITH_EQUAL))) {
            newOptions.add((String) origOptions[i]);
          }
        }
      }
      Map<String, Object> payload = new HashMap<String, Object>();
      payload.put("target", configName);
      for (String option : newOptions) {
        ArrayList kv = InstanceHandler.getKeyValuePair(option);
        payload.put((String) kv.get(0), kv.get(1));
      }
      RestUtil.restRequest(endpoint, payload, "POST", handlerCtx, false);
    } catch (Exception ex) {
      GuiUtil.handleException(handlerCtx, ex);
    }
  }
Exemplo n.º 12
0
  /**
   * Includes the first IP based on priority for the given type. It adds the content to the given
   * UIComponent root. If the IP content looks like a URL (contains ://), a StaticText component
   * will be added with the value of the content from the URL.
   */
  @Handler(
      id = "includeFirstIntegrationPoint",
      input = {
        @HandlerInput(name = "type", type = String.class, required = true),
        @HandlerInput(name = "root", type = UIComponent.class, required = false)
      })
  public static void includeFirstIntegrationPoint(HandlerContext handlerCtx)
      throws java.io.IOException {
    // Get the input
    String type = (String) handlerCtx.getInputValue("type");
    UIComponent root = (UIComponent) handlerCtx.getInputValue("root");

    // Get the IntegrationPoints
    FacesContext ctx = handlerCtx.getFacesContext();
    Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type));
    if (points != null) {
      Iterator<IntegrationPoint> it = points.iterator();
      if (it.hasNext()) {
        // Get the first one...
        IntegrationPoint point = it.next();
        root = getIntegrationPointParent(ctx, root, point);

        // Check to see if IP points to an external URL...
        if (point.getContent().lastIndexOf("://", 15) != -1) {
          // Treat content as a url...
          URL contentURL = FileUtil.searchForFile(point.getContent(), null);
          if (contentURL == null) {
            throw new IOException("Unable to locate file: " + point.getContent());
          }

          // Read the content...
          String content = new String(FileUtil.readFromURL(contentURL));

          // Create a StaticText component and add it under the
          // "root" component.
          LayoutComponent stDesc =
              new LayoutComponent(
                  null,
                  "externalContent",
                  new ComponentType(
                      "tmpTextCT",
                      "com.sun.jsftemplating.component.factory.basic.StaticTextFactory"));
          stDesc.addOption("value", content);
          ComponentUtil.getInstance(ctx).createChildComponent(ctx, stDesc, root);
        } else {
          // Include the first one...
          includeIntegrationPoint(ctx, root, point);
        }
      }
    }
  }
Exemplo n.º 13
0
  /**
   * This handler returns the attribute values in the Edit Manage User Password Page.
   *
   * <p>Input value: "Realm" -- Type: <code>java.lang.String</code>
   *
   * <p>Output value: "UserId" -- Type: <code>java.lang.String</code>
   *
   * <p>Output value: "GroupList" -- Type: <code>java.lang.String</code>
   *
   * @param handlerCtx The HandlerContext.
   */
  @Handler(
      id = "getUserInfo",
      input = {
        @HandlerInput(name = "Realm", type = String.class, required = true),
        @HandlerInput(name = "configName", type = String.class, required = true),
        @HandlerInput(name = "User", type = String.class, required = true)
      },
      output = {@HandlerOutput(name = "GroupList", type = String.class)})
  public static void getUserInfo(HandlerContext handlerCtx) {

    String realmName = (String) handlerCtx.getInputValue("Realm");
    String userName = (String) handlerCtx.getInputValue("User");
    String configName = (String) handlerCtx.getInputValue("configName");
    handlerCtx.setOutputValue(
        "GroupList", getGroupNames(realmName, userName, configName, handlerCtx));
  }
Exemplo n.º 14
0
  /**
   * This handler returns the a Map for storing the attributes for realm creation.
   *
   * @param handlerCtx The HandlerContext.
   */
  @Handler(
      id = "getRealmAttrForCreate",
      output = {
        @HandlerOutput(name = "attrMap", type = Map.class),
        @HandlerOutput(name = "classnameOption", type = String.class),
        @HandlerOutput(name = "realmClasses", type = List.class),
        @HandlerOutput(name = "properties", type = List.class)
      })
  public static void getRealmAttrForCreate(HandlerContext handlerCtx) {

    handlerCtx.setOutputValue("realmClasses", realmClassList);
    handlerCtx.setOutputValue("classnameOption", "predefine");
    Map attrMap = new HashMap();
    attrMap.put("predefinedClassname", Boolean.TRUE);
    handlerCtx.setOutputValue("attrMap", attrMap);
    handlerCtx.setOutputValue("properties", new ArrayList());
  }
Exemplo n.º 15
0
  /**
   * This handler adds {@link IntegrationPoint}s of a given type to a <code>UIComponent</code> tree.
   * It looks for {@link IntegrationPoint}s using the given <code>type</code>. It then sorts the
   * results (if any) by <code>parentId</code>, and then by priority. It next interates over each
   * one looking for a <code>UIComponent</code> with an <code>id</code> which matches the its own
   * <code>parentId</code> value. It then uses the content of the {@link IntegrationPoint} to
   * attempt to include the .jsf page it refers to under the identified parent component.
   */
  @Handler(
      id = "includeIntegrations",
      input = {
        @HandlerInput(name = "type", type = String.class, required = true),
        @HandlerInput(name = "root", type = UIComponent.class, required = false)
      })
  public static void includeIntegrations(HandlerContext handlerCtx) {
    // Get the input
    String type = (String) handlerCtx.getInputValue("type");
    UIComponent root = (UIComponent) handlerCtx.getInputValue("root");

    // Get the IntegrationPoints
    FacesContext ctx = handlerCtx.getFacesContext();
    List<IntegrationPoint> points = getIntegrationPoints(ctx, type);

    // Include them
    includeIntegrationPoints(ctx, root, getSortedIntegrationPoints(points));
  }
Exemplo n.º 16
0
 @Handler(
     id = "getSecurityManagerValue",
     input = {
       @HandlerInput(name = "endpoint", type = String.class),
       @HandlerInput(name = "attrs", type = Map.class, required = false)
     },
     output = {@HandlerOutput(name = "value", type = String.class)})
 public static void getSecurityManagerValue(HandlerContext handlerCtx) {
   ArrayList<String> list = InstanceHandler.getJvmOptions(handlerCtx);
   handlerCtx.setOutputValue("value", isSecurityManagerEnabled(list).toString());
 }
Exemplo n.º 17
0
 /**
  * This handler returns a {@link GadgetModule} for the named gadget. The <code>name</code> should
  * either be a complete URL, or a context-root relative path to the gadget XML file (this also
  * includes .xml files stored in .jar's / plugins).
  */
 @Handler(
     id = "gf.getGadgetModule",
     input = {@HandlerInput(name = "name", type = String.class, required = true)},
     output = {@HandlerOutput(name = "module", type = GadgetModule.class)})
 public static void getGadgetModule(HandlerContext handlerCtx) {
   String gadgetName = (String) handlerCtx.getInputValue("name");
   URL url = null;
   try {
     if (!gadgetName.contains("://")) {
       // Treat as a path...
       url = FileUtil.searchForFile(gadgetName, null);
     }
     if (url == null) {
       url = new URL(gadgetName);
     }
   } catch (Exception ex) {
     throw new IllegalArgumentException("Cannot creaqte URL from '" + gadgetName + "'!", ex);
   }
   GadgetModule module = getGadgetModule(url);
   handlerCtx.setOutputValue("module", module);
 }
Exemplo n.º 18
0
 /**
  * This handler returns the list of file users for specified realm.
  *
  * @param handlerCtx The HandlerContext.
  */
 @Handler(
     id = "getFileUsers",
     input = {
       @HandlerInput(name = "Realm", type = String.class, required = true),
       @HandlerInput(name = "configName", type = String.class, required = true)
     },
     output = {@HandlerOutput(name = "result", type = java.util.List.class)})
 public static void getFileUsers(HandlerContext handlerCtx) {
   String realmName = (String) handlerCtx.getInputValue("Realm");
   String configName = (String) handlerCtx.getInputValue("configName");
   List result = new ArrayList();
   try {
     String endpoint =
         GuiUtil.getSessionValue("REST_URL")
             + "/configs/config/"
             + configName
             + "/security-service/auth-realm/"
             + realmName
             + "/list-users.json?target="
             + configName;
     Map<String, Object> responseMap =
         RestUtil.restRequest(endpoint, null, "get", handlerCtx, false);
     responseMap = (Map<String, Object>) responseMap.get("data");
     List<HashMap> children = (List<HashMap>) responseMap.get("children");
     if (children != null) {
       Map<String, Object> map = null;
       for (HashMap child : children) {
         map = new HashMap<String, Object>();
         String name = (String) child.get("message");
         map.put("users", name);
         map.put("groups", getGroupNames(realmName, name, configName, handlerCtx));
         map.put("selected", false);
         result.add(map);
       }
     }
   } catch (Exception ex) {
     GuiUtil.handleException(handlerCtx, ex);
   }
   handlerCtx.setOutputValue("result", result);
 }
Exemplo n.º 19
0
  @Handler(
      id = "getAppEditIntegrationPoint",
      input = {@HandlerInput(name = "type", type = String.class, required = true)},
      output = {@HandlerOutput(name = "appEditPageMap", type = Map.class)})
  public static void getAppEditIntegrationPoint(HandlerContext handlerCtx)
      throws java.io.IOException {
    // Get the input
    String type = (String) handlerCtx.getInputValue("type");

    // Get the IntegrationPoints
    FacesContext ctx = handlerCtx.getFacesContext();
    Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type));
    Map result = new HashMap();
    if (points != null) {
      for (IntegrationPoint it : points) {
        String content = it.getContent();
        if (GuiUtil.isEmpty(content)) {
          GuiUtil.getLogger()
              .warning(
                  "No Content specified for Integration Point: " + type + " id : " + it.getId());
          continue;
        }
        List<String> vv = GuiUtil.parseStringList(content, ":");
        if (vv.size() != 2) {
          GuiUtil.getLogger()
              .warning(
                  "Invalid content specified for Integration Point: "
                      + type
                      + " id : "
                      + it.getId());
          continue;
        }
        result.put(vv.get(0), vv.get(1));
      }
    }
    handlerCtx.setOutputValue("appEditPageMap", result);
  }
Exemplo n.º 20
0
  /**
   * This handler update's user info.
   *
   * <p>Input value: "Realm" -- Type: <code>java.lang.String</code>
   *
   * <p>Output value: "UserId" -- Type: <code>java.lang.String</code>
   *
   * <p>Output value: "GroupList" -- Type: <code>java.lang.String</code>
   *
   * <p>Output value: "Password" -- Type: <code>java.lang.String</code>
   *
   * @param handlerCtx The HandlerContext.
   */
  @Handler(
      id = "saveUser",
      input = {
        @HandlerInput(name = "Realm", type = String.class, required = true),
        @HandlerInput(name = "configName", type = String.class, required = true),
        @HandlerInput(name = "UserId", type = String.class, required = true),
        @HandlerInput(name = "GroupList", type = String.class, required = true),
        @HandlerInput(name = "Password", type = String.class, required = true),
        @HandlerInput(name = "CreateNew", type = String.class, required = true)
      })
  public static void saveUser(HandlerContext handlerCtx) {
    try {
      String realmName = (String) handlerCtx.getInputValue("Realm");
      String configName = (String) handlerCtx.getInputValue("configName");
      String grouplist = (String) handlerCtx.getInputValue("GroupList");
      String password = (String) handlerCtx.getInputValue("Password");
      String userid = (String) handlerCtx.getInputValue("UserId");
      String createNew = (String) handlerCtx.getInputValue("CreateNew");

      if (password == null) {
        password = "";
      }
      // before save user synchronize realm, for the case if keyfile is changed
      String tmpEP =
          GuiUtil.getSessionValue("REST_URL")
              + "/configs/config/"
              + configName
              + "/synchronize-realm-from-config";
      HashMap attrs = new HashMap<String, Object>();
      attrs.put("id", configName);
      attrs.put("realmName", realmName);
      RestUtil.restRequest(tmpEP, attrs, "POST", handlerCtx, false);
      String endpoint =
          GuiUtil.getSessionValue("REST_URL")
              + "/configs/config/"
              + configName
              + "/security-service/auth-realm/"
              + realmName;
      if (Boolean.valueOf(createNew)) {
        endpoint = endpoint + "/create-user?target=" + configName;
      } else {
        endpoint = endpoint + "/update-user?target=" + configName;
      }

      attrs = new HashMap<String, Object>();
      attrs.put("id", userid);
      attrs.put("userpassword", password);
      attrs.put("target", configName);
      if (grouplist != null && grouplist.contains(",")) grouplist = grouplist.replace(',', ':');
      List<String> grpList = new ArrayList();
      if (grouplist != null && !grouplist.equals("")) grpList.add(grouplist);
      attrs.put("groups", grpList);
      RestUtil.restRequest(endpoint, attrs, "POST", null, true, true);
    } catch (Exception ex) {
      GuiUtil.handleException(handlerCtx, ex);
    }
  }
Exemplo n.º 21
0
  @Handler(
      id = "saveMsgProviderInfo",
      input = {
        @HandlerInput(name = "attrMap", type = Map.class, required = true),
        @HandlerInput(name = "configName", type = String.class, required = true),
        @HandlerInput(name = "edit", type = String.class, required = true)
      })
  public static void saveMsgProviderInfo(HandlerContext handlerCtx) {
    Map<String, String> attrMap = (Map<String, String>) handlerCtx.getInputValue("attrMap");
    String edit = (String) handlerCtx.getInputValue("edit");
    String msgSecurityName = attrMap.get("msgSecurityName");
    String configName = (String) handlerCtx.getInputValue("configName");

    try {
      String providerName = URLEncoder.encode((String) attrMap.get("Name"), "UTF-8");
      String providerEndpoint =
          GuiUtil.getSessionValue("REST_URL")
              + "/configs/config/"
              + configName
              + "/security-service/message-security-config/"
              + msgSecurityName
              + "/provider-config/"
              + providerName;

      if (edit.equals("true")) {
        boolean providerExist = RestUtil.get(providerEndpoint).isSuccess();
        if (!providerExist) {
          GuiUtil.handleError(
              handlerCtx,
              GuiUtil.getMessage(
                  COMMON_BUNDLE, "msg.error.noSuchProvider")); // normally won't happen.
          return;
        } else {
          Map<String, Object> providerMap =
              (Map<String, Object>) RestUtil.getEntityAttrs(providerEndpoint, "entity");
          providerMap.put("className", attrMap.get("ClassName"));
          providerMap.put("providerType", attrMap.get("ProviderType"));
          RestUtil.restRequest(providerEndpoint, providerMap, "POST", null, false);
          Map attrs = new HashMap();
          String endpoint =
              GuiUtil.getSessionValue("REST_URL")
                  + "/configs/config/"
                  + configName
                  + "/security-service/message-security-config/"
                  + attrMap.get("msgSecurityName");
          attrs.put("authLayer", attrMap.get("msgSecurityName"));
          if (attrMap.get("defaultProvider") != null
              && attrMap.get("defaultProvider").equals("true")) {
            if (providerMap.get("providerType").equals("client")) {
              attrs.put("defaultClientProvider", providerName);
            } else if (providerMap.get("providerType").equals("server")) {
              attrs.put("defaultProvider", providerName);
            } else if (providerMap.get("providerType").equals("client-server")) {
              attrs.put("defaultProvider", providerName);
              attrs.put("defaultClientProvider", providerName);
            }
          }
          if (attrMap.get("defaultProvider") == null) {
            if (providerMap.get("providerType").equals("client")
                && providerName.equals(attrMap.get("defaultClientProvider"))) {
              attrs.put("defaultClientProvider", "");
            } else if (providerMap.get("providerType").equals("server")
                && providerName.equals(attrMap.get("defaultProvider"))) {
              attrs.put("defaultProvider", "");
            } else if (providerMap.get("providerType").equals("client-server")) {
              if (providerName.equals(attrMap.get("defaultServerProvider"))
                  && providerName.equals(attrMap.get("defaultClientProvider"))) {
                attrs.put("defaultProvider", "");
                attrs.put("defaultClientProvider", "");
              }
            }
          }
          RestUtil.sendUpdateRequest(endpoint, attrs, null, null, null);
        }
      } else {
        String endpoint =
            GuiUtil.getSessionValue("REST_URL")
                + "/configs/config/"
                + configName
                + "/security-service/message-security-config";
        Map attrs = new HashMap();
        if (attrMap.get("defaultProvider") == null) {
          attrMap.put("defaultProvider", "false");
        }
        attrs.put("isdefaultprovider", attrMap.get("defaultProvider"));
        attrs.put("id", attrMap.get("Name"));
        attrs.put("classname", attrMap.get("ClassName"));
        attrs.put("providertype", attrMap.get("ProviderType"));
        attrs.put("layer", attrMap.get("msgSecurityName"));
        attrs.put("target", configName);
        RestUtil.restRequest(endpoint, attrs, "POST", null, false);
      }

      // if we pass in "", backend will throw bean violation, since it only accepts certain values.
      String[] attrList =
          new String[] {
            "Request-AuthSource",
            "Request-AuthRecipient",
            "Response-AuthSource",
            "Response-AuthRecipient"
          };
      for (int i = 0; i < attrList.length; i++) {
        if ("".equals(attrMap.get(attrList[i]))) {
          attrMap.put(attrList[i], null);
        }
      }

      Map reqPolicyMap = new HashMap();
      reqPolicyMap.put("authSource", attrMap.get("Request-AuthSource"));
      reqPolicyMap.put("authRecipient", attrMap.get("Request-AuthRecipient"));
      String reqPolicyEP = providerEndpoint + "/request-policy";
      RestUtil.restRequest(reqPolicyEP, reqPolicyMap, "POST", null, false);

      Map respPolicyMap = new HashMap();
      respPolicyMap.put("authSource", attrMap.get("Response-AuthSource"));
      respPolicyMap.put("authRecipient", attrMap.get("Response-AuthRecipient"));
      String respPolicyEP = providerEndpoint + "/response-policy";
      RestUtil.restRequest(respPolicyEP, respPolicyMap, "POST", null, false);
    } catch (Exception ex) {
      GuiUtil.handleException(handlerCtx, ex);
    }
  }
Exemplo n.º 22
0
  /**
   * This handler will invoke another handler. This allows a generic handler to invoke another one
   * and return the response(s), if any.
   *
   * <p>The following are the inputs are supported:
   *
   * <ul>
   *   <li><b>handler</b> - (required) This input specifies the handler which should be invoked.
   *   <li><b>args</b> - (required) This specifies all of the arguments to be passed to the handler
   *       (both input and output arguments). The value of this should be a String formatted as a
   *       comma separated list of name-value pairs (which are themselves separated by colons (:).
   *       The value of the name-value pairs should be URL encoded (so that commas are escaped).
   *   <li><b>depth</b> - (optional) This property specifies the max depth of nesting for any output
   *       values from the handler. Output values are encoded in JSON. This prevents infinite
   *       looping in the case where an Object refers to itself (or in the case wehre there is
   *       unnecessarily deep data structures).
   * </ul>
   */
  @Handler(
      id = "gf.invokeHandler",
      input = {
        @HandlerInput(name = "handler", type = String.class, required = true),
        @HandlerInput(name = "args", type = String.class, required = true),
        @HandlerInput(name = "depth", type = Integer.class, required = false)
      },
      output = {@HandlerOutput(name = "values", type = String.class)})
  public static Object invokeHandler(HandlerContext handlerCtx) {
    // First find the HandlerDefinition
    String handlerName = (String) handlerCtx.getInputValue("handler");
    HandlerDefinition handlerDef = LayoutDefinitionManager.getGlobalHandlerDefinition(handlerName);
    if (handlerDef == null) {
      throw new IllegalArgumentException("Handler '" + handlerName + "' not found!");
    }

    // Before working with the new Handler, save the old Handler...
    com.sun.jsftemplating.layout.descriptors.handler.Handler oldHandler = handlerCtx.getHandler();

    // Create the Handler to invoke...
    com.sun.jsftemplating.layout.descriptors.handler.Handler handler =
        new com.sun.jsftemplating.layout.descriptors.handler.Handler(handlerDef);

    // Now try to get the inputs / outputs
    List<String> outputNames = new ArrayList<String>();
    String args = (String) handlerCtx.getInputValue("args");
    StringTokenizer tok = new StringTokenizer(args, ",");
    String nvp, name, value;
    Object val = null;
    int colon;
    while (tok.hasMoreTokens()) {
      // Get the NVP...
      nvp = tok.nextToken();
      colon = nvp.indexOf(':');
      if (colon == -1) {
        throw new IllegalArgumentException("Handler I/O name:value must be separated by a ':'!");
      }
      name = nvp.substring(0, colon).trim();
      value = nvp.substring(colon + 1).trim();

      // URL decode 'value'...
      try {
        value = URLDecoder.decode(value, "UTF-8");
      } catch (UnsupportedEncodingException ex) {
        throw new IllegalArgumentException("Unable to decode value, this is not normal!", ex);
      }

      // See if it is an input...
      if (handlerDef.getInputDef(name) != null) {
        // It's an input...
        if (value.startsWith("{") && value.endsWith("}")) {
          Object t = parseString(value.substring(1, (value.length()) - 1));
          val = t;
        } else {
          val = value;
        }
        handler.setInputValue(name, val);
      } else {
        // Assume it's an output mapping...
        handler.setOutputMapping(name, val.toString(), OutputTypeManager.EL_TYPE);
        outputNames.add(name);
      }
    }

    // We have the new handler (yea!), invoke it...
    List<com.sun.jsftemplating.layout.descriptors.handler.Handler> handlers =
        new ArrayList<com.sun.jsftemplating.layout.descriptors.handler.Handler>(1);
    handlers.add(handler);
    Object result = handlerCtx.getLayoutElement().dispatchHandlers(handlerCtx, handlers);

    // Now... lets get the output values from the "child" handler...
    Map<String, Object> outputValues = new HashMap<String, Object>();
    String outName;
    Iterator<String> it = outputNames.iterator();
    while (it.hasNext()) {
      // For each output specified, save it in a Map to be encoded later
      outName = it.next();
      outputValues.put(outName, handler.getOutputValue(handlerCtx, outName));
    }

    // Now we're done with the "child" Handler, restore this Handler...
    handlerCtx.setHandler(oldHandler);

    // Finally, translate the Map to JSON and set the String as an output
    Integer depth = (Integer) handlerCtx.getInputValue("depth");
    if (depth == null) {
      depth = 10;
    }
    handlerCtx.setOutputValue("values", JSONUtil.javaToJSON(outputValues, depth));

    return result;
  }
Exemplo n.º 23
0
  /**
   * This handler returns the a Map for storing the attributes for editing a realm. This can be used
   * by either the node agent realm or the realm in configuration-Security-realm
   *
   * @param handlerCtx The HandlerContext.
   */
  @Handler(
      id = "getRealmAttrForEdit",
      input = {@HandlerInput(name = "endpoint", type = String.class)},
      output = {
        @HandlerOutput(name = "attrMap", type = Map.class),
        @HandlerOutput(name = "classnameOption", type = String.class),
        @HandlerOutput(name = "realmClasses", type = List.class),
        @HandlerOutput(name = "properties", type = List.class)
      })
  public static void getRealmAttrForEdit(HandlerContext handlerCtx) {

    String endpoint = (String) handlerCtx.getInputValue("endpoint");

    HashMap<String, Object> realmMap =
        (HashMap<String, Object>) RestUtil.getEntityAttrs(endpoint, "entity");

    HashMap<String, Object> responseMap =
        (HashMap<String, Object>)
            RestUtil.restRequest(endpoint + "/property.json", null, "GET", null, false);
    HashMap propsMap =
        (HashMap) ((Map<String, Object>) responseMap.get("data")).get("extraProperties");
    ArrayList<HashMap> propList = (ArrayList<HashMap>) propsMap.get("properties");
    HashMap origProps = new HashMap();
    for (HashMap prop : propList) {
      origProps.put(prop.get("name"), prop.get("value"));
    }

    Map attrMap = new HashMap();
    attrMap.put("Name", (String) realmMap.get("name"));
    attrMap.put("fileJaax", "fileRealm");
    attrMap.put("ldapJaax", "ldapRealm");
    attrMap.put("solarisJaax", "solarisRealm");
    attrMap.put("jdbcJaax", "jdbcRealm");

    String classname = (String) realmMap.get("classname");

    if (realmClassList.contains(classname)) {
      handlerCtx.setOutputValue("classnameOption", "predefine");
      attrMap.put("predefinedClassname", Boolean.TRUE);
      attrMap.put("classname", classname);
      List props = getChildrenMapForTableList(propList, "property", skipRealmPropsList);
      handlerCtx.setOutputValue("properties", props);

      if (classname.indexOf("FileRealm") != -1) {
        attrMap.put("file", origProps.get("file"));
        attrMap.put("fileJaax", origProps.get("jaas-context"));
        attrMap.put("fileAsGroups", origProps.get("assign-groups"));
      } else if (classname.indexOf("LDAPRealm") != -1) {
        attrMap.put("ldapJaax", origProps.get("jaas-context"));
        attrMap.put("ldapAsGroups", origProps.get("assign-groups"));
        attrMap.put("directory", origProps.get("directory"));
        attrMap.put("baseDn", origProps.get("base-dn"));
      } else if (classname.indexOf("SolarisRealm") != -1) {
        attrMap.put("solarisJaax", origProps.get("jaas-context"));
        attrMap.put("solarisAsGroups", origProps.get("assign-groups"));
      } else if (classname.indexOf("PamRealm") != -1) {
        attrMap.put("pamJaax", origProps.get("jaas-context"));
      } else if (classname.indexOf("JDBCRealm") != -1) {
        attrMap.put("jdbcJaax", origProps.get("jaas-context"));
        attrMap.put("jdbcAsGroups", origProps.get("assign-groups"));
        attrMap.put("datasourceJndi", origProps.get("datasource-jndi"));
        attrMap.put("userTable", origProps.get("user-table"));
        attrMap.put("userNameColumn", origProps.get("user-name-column"));
        attrMap.put("passwordColumn", origProps.get("password-column"));
        attrMap.put("groupTable", origProps.get("group-table"));
        attrMap.put("groupTableUserName", origProps.get("group-table-user-name-column"));
        attrMap.put("groupNameColumn", origProps.get("group-name-column"));
        attrMap.put("dbUser", origProps.get("db-user"));
        attrMap.put("dbPassword", origProps.get("db-password"));
        attrMap.put("digestAlgorithm", origProps.get("digest-algorithm"));
        attrMap.put("pswdEncAlgorithm", origProps.get("digestrealm-password-enc-algorithm"));
        attrMap.put("encoding", origProps.get("encoding"));
        attrMap.put("charset", origProps.get("charset"));

      } else if (classname.indexOf("CertificateRealm") != -1) {
        attrMap.put("certAsGroups", origProps.get("assign-groups"));
      }
    } else {
      // Custom realm class
      handlerCtx.setOutputValue("classnameOption", "input");
      attrMap.put("predefinedClassname", Boolean.FALSE);
      attrMap.put("classnameInput", classname);
      attrMap.put("classname", classname);
      List props = getChildrenMapForTableList(propList, "property", null);
      handlerCtx.setOutputValue("properties", props);
    }

    handlerCtx.setOutputValue("attrMap", attrMap);
    handlerCtx.setOutputValue("realmClasses", realmClassList);
  }
Exemplo n.º 24
0
  @Handler(
      id = "saveRealm",
      input = {
        @HandlerInput(name = "endpoint", type = String.class),
        @HandlerInput(name = "classnameOption", type = String.class),
        @HandlerInput(name = "attrMap", type = Map.class),
        @HandlerInput(name = "edit", type = Boolean.class, required = true),
        @HandlerInput(name = "contentType", type = String.class, required = false),
        @HandlerInput(name = "propList", type = List.class)
      },
      output = {@HandlerOutput(name = "newPropList", type = List.class)})
  public static void saveRealm(HandlerContext handlerCtx) {
    String option = (String) handlerCtx.getInputValue("classnameOption");
    List<Map<String, String>> propListOrig = (List) handlerCtx.getInputValue("propList");
    List<Map<String, String>> propList = new ArrayList(propListOrig);
    Map<String, String> attrMap = (Map) handlerCtx.getInputValue("attrMap");
    Boolean edit = (Boolean) handlerCtx.getInputValue("edit");

    if (attrMap == null) {
      attrMap = new HashMap();
    }
    String classname = "";
    try {
      if (option.equals("predefine")) {
        classname = attrMap.get("classname");

        if (classname.indexOf("FileRealm") != -1) {
          putOptional(attrMap, propList, "file", "file");
          putOptional(attrMap, propList, "jaas-context", "fileJaax");
          putOptional(attrMap, propList, "assign-groups", "fileAsGroups");
        } else if (classname.indexOf("LDAPRealm") != -1) {
          if (!edit) {
            attrMap.put("baseDn", "\"" + attrMap.get("baseDn") + "\"");
            attrMap.put("directory", "\"" + attrMap.get("directory") + "\"");
            for (Map<String, String> m : propList) {
              m.put("value", "\"" + m.get("value") + "\"");
            }
          }
          putOptional(attrMap, propList, "jaas-context", "ldapJaax");
          putOptional(attrMap, propList, "base-dn", "baseDn");
          putOptional(attrMap, propList, "directory", "directory");
          putOptional(attrMap, propList, "assign-groups", "ldapAsGroups");
        } else if (classname.indexOf("SolarisRealm") != -1) {
          putOptional(attrMap, propList, "jaas-context", "solarisJaax");
          putOptional(attrMap, propList, "assign-groups", "solarisAsGroups");
        } else if (classname.indexOf("PamRealm") != -1) {
          putOptional(attrMap, propList, "jaas-context", "pamJaax");
        } else if (classname.indexOf("JDBCRealm") != -1) {
          putOptional(attrMap, propList, "jaas-context", "jdbcJaax");
          putOptional(attrMap, propList, "datasource-jndi", "datasourceJndi");
          putOptional(attrMap, propList, "user-table", "userTable");
          putOptional(attrMap, propList, "user-name-column", "userNameColumn");
          putOptional(attrMap, propList, "password-column", "passwordColumn");
          putOptional(attrMap, propList, "group-table", "groupTable");
          putOptional(attrMap, propList, "group-table-user-name-column", "groupTableUserName");
          putOptional(attrMap, propList, "group-name-column", "groupNameColumn");
          putOptional(attrMap, propList, "db-user", "dbUser");
          putOptional(attrMap, propList, "db-password", "dbPassword");
          putOptional(attrMap, propList, "digest-algorithm", "digestAlgorithm");
          putOptional(attrMap, propList, "digestrealm-password-enc-algorithm", "pswdEncAlgorithm");
          putOptional(attrMap, propList, "encoding", "encoding");
          putOptional(attrMap, propList, "charset", "charset");
          putOptional(attrMap, propList, "assign-groups", "jdbcAsGroups");
        } else {
          if (classname.indexOf("CertificateRealm") != -1) {
            putOptional(attrMap, propList, "assign-groups", "certAsGroups");
          }
        }
      } else {
        classname = attrMap.get("classnameInput");
      }

      String endpoint = (String) handlerCtx.getInputValue("endpoint");
      // for edit case, only properties will be changed since we don't allow classname change.
      // return the prop list so it can continue processing in the .jsf
      if (edit) {
        handlerCtx.setOutputValue("newPropList", propList);
        return;
      }
      Map<String, Object> cMap = new HashMap();
      cMap.put("name", attrMap.get("Name"));
      cMap.put("classname", classname);
      StringBuilder sb = new StringBuilder();
      for (Map oneProp : propList) {
        if (GuiUtil.isEmpty((String) oneProp.get("name"))
            || GuiUtil.isEmpty((String) oneProp.get("value"))) {
          continue;
        }
        sb.append(oneProp.get("name")).append("=");
        String value = ((String) oneProp.get("value")).replaceAll("\\\\", "\\\\\\\\");
        value = UtilHandlers.escapePropertyValue(value);
        sb.append(value).append(":");
      }
      endpoint = endpoint + "/auth-realm";
      cMap.put("target", attrMap.get("target"));
      cMap.put("property", sb.toString());
      RestUtil.restRequest(endpoint, cMap, "post", handlerCtx, false);
    } catch (Exception ex) {
      GuiUtil.handleException(handlerCtx, ex);
    }
  }