Package org.apache.sling.commons.json

Examples of org.apache.sling.commons.json.JSONArray


    assertEquals(testUserId, principalString);

          int order = aceObject.optInt("order");
          assertEquals(0, order);

    JSONArray grantedArray = aceObject.optJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(1, grantedArray.length());
    assertEquals("jcr:read", grantedArray.getString(0));

    JSONArray deniedArray = aceObject.optJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals(1, deniedArray.length());
    assertEquals("jcr:write", deniedArray.getString(0));
  }
View Full Code Here


          assertEquals(0, order);

    String principalString = aceObject.optString("principal");
    assertEquals(testGroupId, principalString);
   
    JSONArray grantedArray = aceObject.optJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(1, grantedArray.length());
    assertEquals("jcr:read", grantedArray.getString(0));

    JSONArray deniedArray = aceObject.optJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals("jcr:write", deniedArray.getString(0));
  }
View Full Code Here

    assertEquals(testUserId, principalString);
   
          int order = aceObject.optInt("order");
          assertEquals(0, order);

    JSONArray grantedArray = aceObject.optJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(3, grantedArray.length());
    Set<String> grantedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < grantedArray.length(); i++) {
      grantedPrivilegeNames.add(grantedArray.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:readAccessControl");
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:addChildNodes");

    JSONArray deniedArray = aceObject.optJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals(2, deniedArray.length());
    Set<String> deniedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < deniedArray.length(); i++) {
      deniedPrivilegeNames.add(deniedArray.getString(i));
    }
    H.assertPrivilege(deniedPrivilegeNames, true, "jcr:modifyAccessControl");
    H.assertPrivilege(deniedPrivilegeNames, true, "jcr:removeChildNodes");
   
   
   
        //2. post a new set of privileges to merge with the existing privileges
    List<NameValuePair> postParams2 = new ArrayList<NameValuePair>();
    postParams2.add(new NameValuePair("principalId", testUserId));
    //jcr:read and jcr:addChildNodes are not posted, so they should remain in the granted ACE
    postParams2.add(new NameValuePair("privilege@jcr:readAccessControl", "none")); //clear the existing privilege
    postParams2.add(new NameValuePair("privilege@jcr:modifyProperties", "granted")); //add a new privilege
    //jcr:modifyAccessControl is not posted, so it should remain in the denied ACE
    postParams2.add(new NameValuePair("privilege@jcr:modifyAccessControl", "denied")); //deny the modifyAccessControl privilege
    postParams2.add(new NameValuePair("privilege@jcr:removeChildNodes", "none")); //clear the existing privilege
    postParams2.add(new NameValuePair("privilege@jcr:removeNode", "denied")); //deny a new privilege
   
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams2, null);
   
   
    //fetch the JSON for the acl to verify the settings.
    String json2 = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json2);
    JSONObject jsonObject2 = new JSONObject(json2);
    assertEquals(1, jsonObject2.length());
   
    JSONObject aceObject2 = jsonObject2.optJSONObject(testUserId);
    assertNotNull(aceObject2);

    String principalString2 = aceObject2.optString("principal");
    assertEquals(testUserId, principalString2);
   
    JSONArray grantedArray2 = aceObject2.optJSONArray("granted");
    assertNotNull(grantedArray2);
    assertEquals(3, grantedArray2.length());
    Set<String> grantedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < grantedArray2.length(); i++) {
      grantedPrivilegeNames2.add(grantedArray2.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:read");
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:addChildNodes");
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:modifyProperties");

    JSONArray deniedArray2 = aceObject2.optJSONArray("denied");
    assertNotNull(deniedArray2);
    assertEquals(2, deniedArray2.length());
    Set<String> deniedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < deniedArray2.length(); i++) {
      deniedPrivilegeNames2.add(deniedArray2.getString(i));
    }
    H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:modifyAccessControl");
    H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:removeNode");
  }
View Full Code Here

    JSONObject aceObject = jsonObject.optJSONObject(testUserId);
    assertNotNull(aceObject);
   
    assertEquals(testUserId, aceObject.optString("principal"));
   
    JSONArray grantedArray = aceObject.optJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(1, grantedArray.length());
    Set<String> grantedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < grantedArray.length(); i++) {
      grantedPrivilegeNames.add(grantedArray.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");

    JSONArray deniedArray = aceObject.optJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals(1, deniedArray.length());
    Set<String> deniedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < deniedArray.length(); i++) {
      deniedPrivilegeNames.add(deniedArray.getString(i));
    }
    H.assertPrivilege(deniedPrivilegeNames, true, "jcr:write");
   
   
   
        //2. post a new set of privileges to merge with the existing privileges
    List<NameValuePair> postParams2 = new ArrayList<NameValuePair>();
    postParams2.add(new NameValuePair("principalId", testUserId));
    //jcr:read is not posted, so it should remain in the granted ACE
    postParams2.add(new NameValuePair("privilege@jcr:modifyProperties", "granted")); //add a new privilege
    //jcr:write is not posted, but one of the aggregate privileges is now granted, so the aggregate priviledge should be disagreaged into
    //  the remaining denied privileges in the denied ACE
   
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams2, null);
   
   
    //fetch the JSON for the acl to verify the settings.
    String json2 = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json2);
   
    JSONObject jsonObject2 = new JSONObject(json2);
    assertEquals(1, jsonObject2.length());
   
    JSONObject aceObject2 = jsonObject2.optJSONObject(testUserId);
    assertNotNull(aceObject2);
   
    assertEquals(testUserId, aceObject2.optString("principal"));
   
    JSONArray grantedArray2 = aceObject2.optJSONArray("granted");
    assertNotNull(grantedArray2);
    assertEquals(2, grantedArray2.length());
    Set<String> grantedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < grantedArray2.length(); i++) {
      grantedPrivilegeNames2.add(grantedArray2.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:read");
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:modifyProperties");

    JSONArray deniedArray2 = aceObject2.optJSONArray("denied");
    assertNotNull(deniedArray2);
    assertEquals(3, deniedArray2.length());
    Set<String> deniedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < deniedArray2.length(); i++) {
      deniedPrivilegeNames2.add(deniedArray2.getString(i));
    }
    H.assertPrivilege(deniedPrivilegeNames2, false, "jcr:write");
    //only the remaining privileges from the disaggregated jcr:write collection should remain.
    H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:addChildNodes");
    H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:removeNode");
View Full Code Here

    JSONObject aceObject = jsonObject.optJSONObject(testUserId);
    assertNotNull(aceObject);
   
    assertEquals(testUserId, aceObject.optString("principal"));
   
    JSONArray grantedArray = aceObject.getJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(1, grantedArray.length());
    Set<String> grantedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < grantedArray.length(); i++) {
      grantedPrivilegeNames.add(grantedArray.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");

    JSONArray deniedArray = aceObject.getJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals(1, deniedArray.length());
    Set<String> deniedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < deniedArray.length(); i++) {
      deniedPrivilegeNames.add(deniedArray.getString(i));
    }
    H.assertPrivilege(deniedPrivilegeNames, true, "jcr:removeNode");
   
   
   
        //2. post a new set of privileges to merge with the existing privileges
    List<NameValuePair> postParams2 = new ArrayList<NameValuePair>();
    postParams2.add(new NameValuePair("principalId", testUserId));
    //jcr:read is not posted, so it should remain in the granted ACE
   
    //deny the full jcr:write aggregate privilege, which should merge with the
    //existing part.
    postParams2.add(new NameValuePair("privilege@jcr:write", "denied")); //add a new privilege
   
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams2, null);
   
   
    //fetch the JSON for the acl to verify the settings.
    String json2 = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json2);
   
    JSONObject jsonObject2 = new JSONObject(json2);
    assertEquals(1, jsonObject2.length());
   
    JSONObject aceObject2 = jsonObject2.optJSONObject(testUserId);
    assertNotNull(aceObject2);
   
    assertEquals(testUserId, aceObject.optString("principal"));
   
    JSONArray grantedArray2 = aceObject2.optJSONArray("granted");
    assertNotNull(grantedArray2);
    assertEquals(1, grantedArray2.length());
    Set<String> grantedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < grantedArray2.length(); i++) {
      grantedPrivilegeNames2.add(grantedArray2.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:read");

    JSONArray deniedArray2 = aceObject2.optJSONArray("denied");
    assertNotNull(deniedArray2);
    assertEquals(1, deniedArray2.length());
    Set<String> deniedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < deniedArray2.length(); i++) {
      deniedPrivilegeNames2.add(deniedArray2.getString(i));
    }
    H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:write");
  }
View Full Code Here

    JSONObject aceObject = jsonObject.optJSONObject(testUserId);
    assertNotNull(aceObject);
   
    assertEquals(testUserId, aceObject.optString("principal"));
   
    JSONArray grantedArray = aceObject.optJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(1, grantedArray.length());
    Set<String> grantedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < grantedArray.length(); i++) {
      grantedPrivilegeNames.add(grantedArray.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:write");

    assertFalse(aceObject.has("denied"));
   
   
        //2. post a new set of privileges to merge with the existing privileges
    List<NameValuePair> postParams2 = new ArrayList<NameValuePair>();
    postParams2.add(new NameValuePair("principalId", testUserId));
    //jcr:write is not posted, so it should remain in the granted ACE
   
    //deny the jcr:nodeTypeManagement privilege, which should merge with the
    //existing ACE.
    postParams2.add(new NameValuePair("privilege@jcr:nodeTypeManagement", "denied")); //add a new privilege
   
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams2, null);
   
   
    //fetch the JSON for the acl to verify the settings.
    String json2 = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json2);

    JSONObject jsonObject2 = new JSONObject(json2);
    assertEquals(1, jsonObject2.length());
   
    JSONObject aceObject2 = jsonObject2.optJSONObject(testUserId);
    assertNotNull(aceObject2);
   
    assertEquals(testUserId, aceObject2.optString("principal"));
   
    JSONArray grantedArray2 = aceObject2.optJSONArray("granted");
    assertNotNull(grantedArray2);
    assertEquals(1, grantedArray2.length());
    Set<String> grantedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < grantedArray2.length(); i++) {
      grantedPrivilegeNames2.add(grantedArray2.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:write");

    JSONArray deniedArray2 = aceObject2.optJSONArray("denied");
    assertNotNull(deniedArray2);
    assertEquals(1, deniedArray2.length());
    Set<String> deniedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < deniedArray2.length(); i++) {
      deniedPrivilegeNames2.add(deniedArray2.getString(i));
    }
    H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:nodeTypeManagement");
  }
View Full Code Here

    JSONObject aceObject = jsonObject.optJSONObject(testUserId);
    assertNotNull(aceObject);
   
    assertEquals(testUserId, aceObject.optString("principal"));
   
    JSONArray grantedArray = aceObject.getJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(4, grantedArray.length());
    Set<String> grantedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < grantedArray.length(); i++) {
      grantedPrivilegeNames.add(grantedArray.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:versionManagement");
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyAccessControl");
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:write");

    JSONArray deniedArray = aceObject.getJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals(1, deniedArray.length());
    Set<String> deniedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < deniedArray.length(); i++) {
      deniedPrivilegeNames.add(deniedArray.getString(i));
    }
    //the leftovers from the denied rep:write that were not granted with jcr:write
    H.assertPrivilege(deniedPrivilegeNames, true, "jcr:nodeTypeManagement");
  }
View Full Code Here

    JSONObject aceObject = jsonObject.optJSONObject(testUserId);
    assertNotNull(aceObject);
   
    assertEquals(testUserId, aceObject.optString("principal"));
   
    JSONArray grantedArray = aceObject.getJSONArray("granted");
    assertNotNull(grantedArray);
    Set<String> grantedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < grantedArray.length(); i++) {
      grantedPrivilegeNames.add(grantedArray.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:versionManagement");
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
    H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyAccessControl");
    H.assertPrivilege(grantedPrivilegeNames, true, "rep:write"); //jcr:nodeTypeManagement + jcr:write
        assertEquals("Expecting the correct number of privileges in " + grantedPrivilegeNames, 4, grantedPrivilegeNames.size());

    //should be nothing left in the denied set.
    JSONArray deniedArray = aceObject.optJSONArray("denied");
    assertNull(deniedArray);
  }
View Full Code Here

        final Map<String, String> options = new HashMap<String, String>();
        options.put("forceReload", "true");
        final RequestExecutor executor = testClient.runTests(testPackageOrClassName, null, "json", options);
        executor.assertContentType("application/json");
        String content = executor.getContent();
        final JSONArray json = new JSONArray(new JSONTokener(content));

        for(int i = 0 ; i < json.length(); i++) {
            final JSONObject obj = json.getJSONObject(i);
            if("test".equals(obj.getString("INFO_TYPE"))) {
                r.testCount++;
                if(obj.has("failure")) {
                    r.failures.add(obj.get("failure").toString());
                }
View Full Code Here

    assertNotNull(aceObject);

    String principalString = aceObject.optString("principal");
    assertEquals(testUserId, principalString);
   
    JSONArray grantedArray = aceObject.optJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals(1, grantedArray.length());
    Set<String> grantedPrivilegeNames = new HashSet<String>();
    for (int i=0; i < grantedArray.length(); i++) {
      grantedPrivilegeNames.add(grantedArray.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames,true,"jcr:write");

    JSONArray deniedArray = aceObject.optJSONArray("denied");
    assertNull(deniedArray);

    JSONObject aceObject2 = jsonObject.optJSONObject(testUserId2);
    assertNotNull(aceObject2);

    String principalString2 = aceObject2.optString("principal");
    assertEquals(testUserId2, principalString2);
   
    JSONArray grantedArray2 = aceObject2.optJSONArray("granted");
    assertNotNull(grantedArray2);
    assertEquals(2, grantedArray2.length());
    Set<String> grantedPrivilegeNames2 = new HashSet<String>();
    for (int i=0; i < grantedArray2.length(); i++) {
      grantedPrivilegeNames2.add(grantedArray2.getString(i));
    }
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:write");
    H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:lockManagement");

    JSONArray deniedArray2 = aceObject2.optJSONArray("denied");
    assertNull(deniedArray2);
 
  }
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.