示例#1
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);
  }
示例#2
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);
  }
示例#3
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);
 }
示例#4
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);
 }
示例#5
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);
  }
示例#6
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);
  }
示例#7
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());
  }
示例#8
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);
 }
示例#9
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));
 }
示例#10
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());
 }
示例#11
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));
  }
示例#12
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);
 }
示例#13
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);
 }
示例#14
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);
  }
示例#15
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);
    }
  }
示例#16
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;
  }
示例#17
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);
  }