use of org.opencastproject.security.api.AccessControlEntry in project opencast by opencast.
the class SeriesServiceImplTest method testACLEquality3.
@Test
public void testACLEquality3() {
AccessControlList a = new AccessControlList();
AccessControlList b = new AccessControlList(new AccessControlEntry("b", Permissions.Action.WRITE.toString(), false));
assertFalse(AccessControlUtil.equals(a, b));
}
use of org.opencastproject.security.api.AccessControlEntry in project opencast by opencast.
the class SeriesServiceSolrTest method testAccessControlManagmentRewrite.
@Test
public void testAccessControlManagmentRewrite() throws Exception {
// sample access control list
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
User user = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole("ROLE_ANONYMOUS", new DefaultOrganization()));
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
// deactivate the default index created in setUp()
index.deactivate();
// create a new index with the security service anonymous user
index = new SeriesServiceSolrIndex();
index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
dcService = new DublinCoreCatalogService();
index.setDublinCoreService(dcService);
index.setSecurityService(securityService);
index.activate(null);
AccessControlList accessControlList = new AccessControlList();
List<AccessControlEntry> acl = accessControlList.getEntries();
acl.add(new AccessControlEntry("ROLE_ANONYMOUS", Permissions.Action.READ.toString(), true));
index.updateIndex(testCatalog);
String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
index.updateSecurityPolicy(seriesID, accessControlList);
SeriesQuery q = new SeriesQuery();
DublinCoreCatalogList result = index.search(q);
Assert.assertTrue("Only one anomymous series", result.size() == 1);
index.updateSecurityPolicy(seriesID, new AccessControlList());
q = new SeriesQuery();
result = index.search(q);
Assert.assertTrue("No anomymous series", result.size() == 0);
}
use of org.opencastproject.security.api.AccessControlEntry in project opencast by opencast.
the class SeriesServiceSolrTest method testAccessControlManagment.
@Test
public void testAccessControlManagment() throws Exception {
// sample access control list
AccessControlList accessControlList = new AccessControlList();
List<AccessControlEntry> acl = accessControlList.getEntries();
acl.add(new AccessControlEntry("admin", "delete", true));
index.updateIndex(testCatalog);
String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
index.updateSecurityPolicy(seriesID, accessControlList);
AccessControlList retrievedACL = index.getAccessControl(seriesID);
Assert.assertNotNull(retrievedACL);
acl = retrievedACL.getEntries();
Assert.assertEquals(acl.size(), 1);
Assert.assertEquals(acl.get(0).getRole(), "admin");
try {
index.updateSecurityPolicy("failid", accessControlList);
Assert.fail("Should fail when indexing ACL to nonexistent series");
} catch (NotFoundException e) {
// expected
}
}
use of org.opencastproject.security.api.AccessControlEntry in project opencast by opencast.
the class EventsEndpointTest method testSerializationOfAcl.
@Ignore
@Test
public void testSerializationOfAcl() throws IOException {
String emptyAclJson = IOUtils.toString(getClass().getResource("/acl-empty.json"));
// Test empty acl
AccessControlList acl = new AccessControlList();
Event event = new Event();
event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
Response result = ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(AclUtils.serializeAclToJson(acl)));
assertTrue(result.getMetadata().get("Content-Type") != null);
assertEquals("application/" + ApiVersion.CURRENT_VERSION + "+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
assertThat(emptyAclJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
// Test acl with one entry
String oneAclJson = IOUtils.toString(getClass().getResource("/acl-one.json"));
AccessControlEntry ace = new AccessControlEntry("ROLE_ADMIN", "write", true);
acl = new AccessControlList(ace);
event = new Event();
event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
result = ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(AclUtils.serializeAclToJson(acl)));
assertTrue(result.getMetadata().get("Content-Type") != null);
assertEquals("application/" + ApiVersion.CURRENT_VERSION + "+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
assertThat(oneAclJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
// Test acl with many entries
String manyAclJson = IOUtils.toString(getClass().getResource("/acl-many.json"));
AccessControlEntry ace1 = new AccessControlEntry("ROLE_ADMIN", "write", true);
AccessControlEntry ace2 = new AccessControlEntry("ROLE_USER", "read", true);
acl = new AccessControlList(ace1, ace2);
event = new Event();
event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
result = ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(AclUtils.serializeAclToJson(acl)));
assertTrue(result.getMetadata().get("Content-Type") != null);
assertEquals("application/" + ApiVersion.CURRENT_VERSION + "+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
assertThat(manyAclJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
}
use of org.opencastproject.security.api.AccessControlEntry in project opencast by opencast.
the class AclUtils method deserializeJsonToAcl.
/**
* De-serialize an JSON into an {@link AccessControlList}.
*
* @param json
* The {@link AccessControlList} to serialize.
* @param assumeAllow
* Assume that all entries are allows.
* @return An {@link AccessControlList} representation of the Json
* @throws IllegalArgumentException
* Thrown if essential parts of an access control element is missing.
* @throws ParseException
* Thrown if unable to parse the json value of the acl.
*/
public static AccessControlList deserializeJsonToAcl(String json, boolean assumeAllow) throws IllegalArgumentException, ParseException {
JSONParser parser = new JSONParser();
JSONArray aclJson = (JSONArray) parser.parse(json);
@SuppressWarnings("unchecked") ListIterator<Object> iterator = aclJson.listIterator();
JSONObject aceJson;
List<AccessControlEntry> entries = new ArrayList<AccessControlEntry>();
while (iterator.hasNext()) {
aceJson = (JSONObject) iterator.next();
String action = aceJson.get(ACTION_JSON_KEY) != null ? aceJson.get(ACTION_JSON_KEY).toString() : "";
String allow;
if (assumeAllow) {
allow = "true";
} else {
allow = aceJson.get(ALLOW_JSON_KEY) != null ? aceJson.get(ALLOW_JSON_KEY).toString() : "";
}
String role = aceJson.get(ROLE_JSON_KEY) != null ? aceJson.get(ROLE_JSON_KEY).toString() : "";
if (StringUtils.trimToNull(action) != null && StringUtils.trimToNull(allow) != null && StringUtils.trimToNull(role) != null) {
AccessControlEntry ace = new AccessControlEntry(role, action, Boolean.parseBoolean(allow));
entries.add(ace);
} else {
throw new IllegalArgumentException(String.format("One of the access control elements is missing a property. The action was '%s', allow was '%s' and the role was '%s'", action, allow, role));
}
}
return new AccessControlList(entries);
}
Aggregations