use of javax.json.JsonArray in project sling by apache.
the class UpdateGroupTest method getTestGroupMembers.
JsonArray getTestGroupMembers(Credentials creds) throws IOException, JsonException {
String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
//make sure the profile request returns some data
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
JsonArray members = jsonObj.getJsonArray("members");
return members;
}
use of javax.json.JsonArray in project sling by apache.
the class PostServletUpdateTest method testMixinTypes.
public void testMixinTypes() throws IOException, JsonException {
// create a node without mixin node types
final Map<String, String> props = new HashMap<String, String>();
props.put("jcr:primaryType", "nt:unstructured");
final String location = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
// assert no mixins
String content = getContent(location + ".json", CONTENT_TYPE_JSON);
JsonObject json = JsonUtil.parseObject(content);
assertFalse("jcr:mixinTypes not expected to be set", json.containsKey("jcr:mixinTypes"));
// add mixin
props.clear();
props.put("jcr:mixinTypes", "mix:versionable");
testClient.createNode(location, props);
content = getContent(location + ".json", CONTENT_TYPE_JSON);
json = JsonUtil.parseObject(content);
assertTrue("jcr:mixinTypes expected after setting them", json.containsKey("jcr:mixinTypes"));
Object mixObject = json.get("jcr:mixinTypes");
assertTrue("jcr:mixinTypes must be an array", mixObject instanceof JsonArray);
JsonArray mix = (JsonArray) mixObject;
assertTrue("jcr:mixinTypes must have a single entry", mix.size() == 1);
assertEquals("jcr:mixinTypes must have correct value", "mix:versionable", mix.getString(0));
// remove mixin
props.clear();
props.put("jcr:mixinTypes@Delete", "-");
testClient.createNode(location, props);
content = getContent(location + ".json", CONTENT_TYPE_JSON);
json = JsonUtil.parseObject(content);
final boolean noMixins = !json.containsKey("jcr:mixinTypes") || json.getJsonArray("jcr:mixinTypes").size() == 0;
assertTrue("no jcr:mixinTypes expected after clearing it", noMixins);
}
use of javax.json.JsonArray in project sling by apache.
the class PostServletImportTest method testImportAutoCheckoutNodes.
/**
* SLING-2108 Test import operation which auto checks out versionable nodes.
*/
public void testImportAutoCheckoutNodes() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
urlsToDelete.add(testNode);
//1. first create some content to update.
props.clear();
props.put(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT);
String testNodeName = "testNode_" + String.valueOf(random.nextInt());
props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName);
testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport3.json"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
props.put(SlingPostConstants.RP_CHECKIN, "true");
String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, testFile, SlingPostConstants.RP_CONTENT_FILE, null);
// assert content at new location
String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert that the versionable node is checked in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));
//2. try an update with the :autoCheckout value set to false
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "false"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
assertPostStatus(importedNodeUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, "Expected error from VersionException");
//3. now try an update with the :autoCheckout value set to true
postParams.clear();
postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
postParams.add(new NameValuePair(":http-equiv-accept", "application/json,*/*;q=0.9"));
HttpMethod post = assertPostStatus(importedNodeUrl, HttpServletResponse.SC_CREATED, postParams, "Expected 201 status");
String responseBodyAsString = post.getResponseBodyAsString();
JsonObject responseJSON = JsonUtil.parseObject(responseBodyAsString);
JsonArray changes = responseJSON.getJsonArray("changes");
JsonObject checkoutChange = changes.getJsonObject(0);
assertEquals("checkout", checkoutChange.getString("type"));
// assert content at new location
String content2 = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);
//make sure it was really updated
assertEquals("def2", jsonObj2.getString("abc"));
//assert that the versionable node is checked back in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));
}
use of javax.json.JsonArray in project sling by apache.
the class ModifyAceTest method testMergeAceForUserGrantNestedAggregatePrivilegeAfterDenySuperAggregatePrivilege.
/**
* Test for SLING-3010
*/
@Test
public void testMergeAceForUserGrantNestedAggregatePrivilegeAfterDenySuperAggregatePrivilege() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.json";
//1. setup an initial set of denied privileges for the test user
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "denied"));
postParams.add(new NameValuePair("privilege@jcr:read", "denied"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "denied"));
postParams.add(new NameValuePair("privilege@rep:write", "denied"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//2. now grant the jcr:write subset from the rep:write aggregate privilege
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "granted"));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "granted"));
//sub-aggregate of rep:write
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//3. verify that the acl has the correct values
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(1, jsonObject.size());
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
assertEquals(testUserId, aceObject.getString("principal"));
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals(4, grantedArray.size());
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); 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.size());
Set<String> deniedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < deniedArray.size(); 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");
}
use of javax.json.JsonArray in project sling by apache.
the class ModifyAceTest method testMergeAceForUserGrantAggregatePrivilegePartsAfterDenyAggregatePrivilege.
/**
* Test for SLING-3010
*/
@Test
public void testMergeAceForUserGrantAggregatePrivilegePartsAfterDenyAggregatePrivilege() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.json";
//1. setup an initial set of denied privileges for the test user
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "denied"));
postParams.add(new NameValuePair("privilege@jcr:read", "denied"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "denied"));
postParams.add(new NameValuePair("privilege@rep:write", "denied"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//2. now grant the all the privileges contained in the rep:write privilege
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "granted"));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "granted"));
//sub-privilege of rep:write
postParams.add(new NameValuePair("privilege@jcr:nodeTypeManagement", "granted"));
//sub-aggregate of rep:write
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//3. verify that the acl has the correct values
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(1, jsonObject.size());
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
assertEquals(testUserId, aceObject.getString("principal"));
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:versionManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyAccessControl");
//jcr:nodeTypeManagement + jcr:write
H.assertPrivilege(grantedPrivilegeNames, true, "rep:write");
assertEquals("Expecting the correct number of privileges in " + grantedPrivilegeNames, 4, grantedPrivilegeNames.size());
//should be nothing left in the denied set.
Object deniedArray = aceObject.get("denied");
assertNull(deniedArray);
}
Aggregations