コード例 #1
0
  @Test
  @Transactional(readOnly = true)
  public void testGetEventGridWidgetDefinitionWithAuthentication()
      throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
          SecurityException, NoSuchMethodException, IOException {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(auth);
    AbstractLicensableWidget eventGridWidget = uIService.getWidgetDefinition(EventGridWidgetName);
    Assert.notNull(eventGridWidget);
    Assert.isTrue(
        eventGridWidget.getActionConfig().getActionConfig().size() == 2,
        "Event grid widget action config does not have expected # of permissions values");
    Assert.isTrue(
        eventGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("create-event"))
            == Boolean.TRUE,
        "Event grid widget action config does not have create-event permission true");
    Assert.isTrue(
        eventGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("edit-event"))
            == Boolean.TRUE,
        "Event grid widget action config does not have edit-event permission true");

    // Assertions for AutoRefreshConfig
    JSONObject defaultViewConfigJSON = new JSONObject(eventGridWidget.getDefaultViewConfig());
    Assert.isTrue(
        defaultViewConfigJSON.has("autoRefreshConfig"),
        "Could not find property 'AutoRefreshConfig'");

    JSONObject autoRefreshConfigJSON =
        new JSONObject(defaultViewConfigJSON.get("autoRefreshConfig").toString());
    Assert.isTrue(
        autoRefreshConfigJSON.has("globalOverride"), "Could not find property 'globalOverride'");
    Assert.isTrue(autoRefreshConfigJSON.has("enabled"), "Could not find property 'enabled'");
    Assert.isTrue(autoRefreshConfigJSON.has("interval"), "Could not find property 'interval'");

    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("globalOverride") == false,
        "Incorrect value for property 'globalOverride'");
    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("enabled") == true,
        "Incorrect value for property 'enabled'");
    Assert.isTrue(
        autoRefreshConfigJSON.getInt("interval") == 120, "Incorrect value for property 'interval'");
  }
コード例 #2
0
 /**
  * Gets the body as a map.
  *
  * @return The body as a map
  */
 Map<String, Object> getFormVariables() {
   Map<String, Object> map = new HashMap<String, Object>();
   Iterator keys = jsonBody.keys();
   String key, typeKey, type;
   String[] keyPair;
   Object value;
   while (keys.hasNext()) {
     key = (String) keys.next();
     keyPair = key.split("_");
     if (keyPair.length == 1) {
       typeKey = keyPair[0] + "_type";
       if (jsonBody.has(typeKey)) {
         type = jsonBody.getString(typeKey);
         if (type.equals("Integer")) {
           value = jsonBody.getInt(key);
         } else if (type.equals("Boolean")) {
           value = jsonBody.getBoolean(key);
         } else if (type.equals("Date")) {
           value = jsonBody.getString(key);
         } else if (type.equals("User")) {
           value = jsonBody.getString(key);
         } else {
           throw new WebScriptException(
               Status.STATUS_BAD_REQUEST,
               "Parameter '" + keyPair[0] + "' is of unknown type '" + type + "'");
         }
       } else {
         value = jsonBody.get(key);
       }
       map.put(key, value);
     } else if (keyPair.length == 2) {
       if (keyPair[1].equals("required")) {
         if (!jsonBody.has(keyPair[0]) || jsonBody.get(keyPair[0]) == null) {
           throw new WebScriptException(
               Status.STATUS_BAD_REQUEST, "Parameter '" + keyPair[0] + "' has no value");
         }
       }
     }
   }
   return map;
 }
コード例 #3
0
  /*
   * (non-Javadoc)
   *
   * @see activitipoc.IFormHandler#parseResult(java.lang.String)
   */
  public FormResult parseResult(String data) {
    final Map<String, Object> parameters = new LinkedHashMap<String, Object>();
    final Map<String, Collection<String>> routes = new LinkedHashMap<String, Collection<String>>();

    JSONObject jObject = new JSONObject(data);
    Iterator<?> keys = jObject.keys();

    while (keys.hasNext()) {

      // TODO dangerous cast
      String key = (String) keys.next();

      // separate properties from roles
      if (key.startsWith(SINGLE_USER_KEY_PREFIX)) {
        routes.put(
            key.replaceFirst(SINGLE_USER_KEY_PREFIX, ""), Arrays.asList(jObject.getString(key)));
      } else if (key.startsWith(GROUP_USER_KEY_PREFIX)) {
        Set<String> users = new HashSet<String>();
        JSONArray usersJ = jObject.getJSONArray(key);
        for (int i = 0; i < usersJ.length(); i++) {
          users.add(usersJ.getString(i));
        }
        routes.put(key.replaceFirst(GROUP_USER_KEY_PREFIX, ""), users);
      } else {
        Object value = jObject.get(key);
        parameters.put(key, value);
      }
    }

    return new FormResult() {

      public Map<String, Collection<String>> getRolesToUsersMapping() {
        return routes;
      }

      public Map<String, Object> getProperties() {
        return parameters;
      }
    };
  }
コード例 #4
0
 /**
  * Gets a body parameter string value.
  *
  * @param param The name of the parameter
  * @return The string value of the parameter
  */
 int getInt(String param) {
   return jsonBody.getInt(param);
 }
コード例 #5
0
 /**
  * Gets a body parameter string value.
  *
  * @param param The name of the parameter
  * @return The string value of the parameter
  */
 String getString(String param) {
   return jsonBody.getString(param);
 }
コード例 #6
0
  @Test
  @Transactional(readOnly = true)
  public void testGetSearchUserGridWidgetDefinitionWithAuthentication()
      throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
          SecurityException, NoSuchMethodException, IOException {
    String listenForListString = "\"listensForList\":[\"userName\"]";
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(auth);
    AbstractLicensableWidget searchUserGridWidget =
        uIService.getWidgetDefinition(SearchUserGridWidgetName);
    Assert.notNull(searchUserGridWidget);
    Assert.isTrue(
        searchUserGridWidget.getActionConfig().getActionConfig().size() == 2,
        "Search user grid widget action config does not have expected # of permissions values");
    Assert.isTrue(
        searchUserGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("delete-user"))
            == Boolean.TRUE,
        "Search user grid widget action config does not have delete-user permission true");
    Assert.isTrue(
        searchUserGridWidget
                .getActionConfig()
                .getActionConfig()
                .get("widget-actions")
                .get(new Permission("disable-user"))
            == Boolean.TRUE,
        "Search user grid widget action config does not have disable-user permission true");
    Assert.notNull(
        searchUserGridWidget.getReactToList(),
        "Search user grid widget definition does not have react to map");
    Assert.notNull(
        searchUserGridWidget.getBroadcastList(),
        "Search user grid widget definition does not have the broadcast list");
    Assert.isTrue(
        searchUserGridWidget.getBroadcastList().size() == 1,
        "Search user grid widget definition does not have the required broadcast list size");
    String defaultViewConfig = searchUserGridWidget.getDefaultViewConfig();
    Assert.isTrue(
        defaultViewConfig.contains(listenForListString),
        "Default view config does not have the expected listen for list");

    // Assertions for AutoRefreshConfig
    JSONObject defaultViewConfigJSON = new JSONObject(searchUserGridWidget.getDefaultViewConfig());
    Assert.isTrue(
        defaultViewConfigJSON.has("autoRefreshConfig"),
        "Could not find property 'AutoRefreshConfig'");

    JSONObject autoRefreshConfigJSON =
        new JSONObject(defaultViewConfigJSON.get("autoRefreshConfig").toString());
    Assert.isTrue(
        autoRefreshConfigJSON.has("globalOverride"), "Could not find property 'globalOverride'");
    Assert.isTrue(autoRefreshConfigJSON.has("enabled"), "Could not find property 'enabled'");
    Assert.isTrue(autoRefreshConfigJSON.has("interval"), "Could not find property 'interval'");

    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("globalOverride") == false,
        "Incorrect value for property 'globalOverride'");
    Assert.isTrue(
        autoRefreshConfigJSON.getBoolean("enabled") == true,
        "Incorrect value for property 'enabled'");
    Assert.isTrue(
        autoRefreshConfigJSON.getInt("interval") == 120, "Incorrect value for property 'interval'");
  }
コード例 #7
0
  /**
   * Add users and roles to the string representation of a JSON msg.
   *
   * @param base
   * @param singleRoles
   * @param groupRoles
   * @param users
   * @return the base String with the necessary fields to add users and roles
   */
  private String concatUsersAndRoles(
      String base,
      Collection<String> singleRoles,
      Collection<String> groupRoles,
      Collection<String> users) {

    // insert roles to users mapping
    JSONObject res = new JSONObject(base);

    JSONArray userArray = new JSONArray(users);

    for (String role : singleRoles) {
      JSONObject o = new JSONObject();
      o.put("title", "Role: " + role);
      o.put("type", "string");
      o.put("enum", userArray);
      o.put("required", true);
      res.getJSONObject("schema").put(SINGLE_USER_KEY_PREFIX + role, o);
    }

    for (String role : groupRoles) {
      JSONObject items = new JSONObject();
      items.put("type", "string");
      items.put("enum", userArray);

      JSONObject o = new JSONObject();
      o.put("title", "Group Role: " + role);
      o.put("type", "array");
      o.put("items", items);
      o.put("minItems", 1);
      o.put("required", true);
      res.getJSONObject("schema").put(GROUP_USER_KEY_PREFIX + role, o);
    }

    JSONObject rolesForm = new JSONObject();
    rolesForm.put("type", "fieldset");
    rolesForm.put("title", "Roles Assignment");

    JSONArray items = new JSONArray();
    for (String role : singleRoles) {
      JSONObject o = new JSONObject();
      o.put("key", SINGLE_USER_KEY_PREFIX + role);
      items.put(o);
    }
    for (String role : groupRoles) {
      JSONObject o = new JSONObject();
      o.put("key", GROUP_USER_KEY_PREFIX + role);
      o.put("type", "checkboxes");
      items.put(o);
    }

    rolesForm.put("items", items);

    JSONArray form = res.getJSONArray("form");
    // remove this object and insert it back at the end
    Object submitButton = form.remove(form.length() - 1);
    form.put(rolesForm);
    form.put(submitButton);

    return res.toString();
  }