Search in sources :

Example 11 with AccessControlEntry

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));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Test(org.junit.Test)

Example 12 with AccessControlEntry

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 13 with AccessControlEntry

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
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Example 14 with AccessControlEntry

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());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Response(javax.ws.rs.core.Response) Event(org.opencastproject.index.service.impl.index.event.Event) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with AccessControlEntry

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject)

Aggregations

AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)38 AccessControlList (org.opencastproject.security.api.AccessControlList)30 Test (org.junit.Test)18 MediaPackage (org.opencastproject.mediapackage.MediaPackage)12 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)7 Job (org.opencastproject.job.api.Job)6 JaxbRole (org.opencastproject.security.api.JaxbRole)6 JobBarrier (org.opencastproject.job.api.JobBarrier)5 JaxbUser (org.opencastproject.security.api.JaxbUser)5 Date (java.util.Date)4 List (java.util.List)4 Map (java.util.Map)4 SearchQuery (org.opencastproject.search.api.SearchQuery)4 AuthorizationService (org.opencastproject.security.api.AuthorizationService)4 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)4 SecurityService (org.opencastproject.security.api.SecurityService)4 User (org.opencastproject.security.api.User)4 NotFoundException (org.opencastproject.util.NotFoundException)4 File (java.io.File)3