Search in sources :

Example 26 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class AclServiceImpl method deleteAcl.

@Override
public boolean deleteAcl(long id) throws AclServiceException, NotFoundException {
    final TransitionQuery query = TransitionQuery.query().withDone(false).withAclId(id);
    final TransitionResult result = persistence.getByQuery(organization, query);
    if (result.getEpisodeTransistions().size() > 0 || result.getSeriesTransistions().size() > 0)
        return false;
    Option<ManagedAcl> deletedAcl = getAcl(id);
    if (aclDb.deleteAcl(organization, id)) {
        if (deletedAcl.isSome()) {
            AclItem aclItem = AclItem.delete(deletedAcl.get().getName());
            messageSender.sendObjectMessage(AclItem.ACL_QUEUE, MessageSender.DestinationType.Queue, aclItem);
        }
        return true;
    }
    throw new NotFoundException("Managed acl with id " + id + " not found.");
}
Also used : AclItem(org.opencastproject.message.broker.api.acl.AclItem) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) NotFoundException(org.opencastproject.util.NotFoundException) TransitionResult(org.opencastproject.authorization.xacml.manager.api.TransitionResult)

Example 27 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class OsgiAclServiceFactory method repopulate.

@Override
public void repopulate(final String indexName) {
    final String destinationId = AclItem.ACL_QUEUE_PREFIX + WordUtils.capitalize(indexName);
    for (final Organization organization : organizationDirectoryService.getOrganizations()) {
        SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

            @Override
            protected void run() {
                AclService aclService = serviceFor(organization);
                List<ManagedAcl> acls = aclService.getAcls();
                int total = aclService.getAcls().size();
                logger.info("Re-populating index with acls. There are {} acls(s) to add to the index.", total);
                int current = 1;
                for (ManagedAcl acl : acls) {
                    logger.trace("Adding acl '{}' for org '{}'", acl.getName(), organization.getId());
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, AclItem.create(acl.getName()));
                    messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Acl, total, current));
                    current++;
                }
            }
        });
    }
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Acl));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Effect0(org.opencastproject.util.data.Effect0) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) List(java.util.List) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 28 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class AccessInformationUtilTest method testSerializeEpisodeACLTransition.

/**
 * Test method for {@link AccessInformationUtil#serializeEpisodeACLTransition(EpisodeACLTransition)}
 */
@Test
public void testSerializeEpisodeACLTransition() throws Exception {
    ManagedAcl acl = createNiceMock(ManagedAcl.class);
    expect(acl.getId()).andStubReturn(TRANSITION_ACL_ID);
    replay(acl);
    EpisodeACLTransition trans = createNiceMock(EpisodeACLTransition.class);
    expect(trans.getTransitionId()).andStubReturn(TRANSITION_ID);
    expect(trans.getApplicationDate()).andStubReturn(TRANSITION_APPLICATION_DATE);
    expect(trans.getWorkflow()).andStubReturn(TRANSITION_WORKFLOW_ID);
    expect(trans.isDone()).andStubReturn(TRANSITION_DONE);
    expect(trans.getAccessControlList()).andStubReturn(Option.some(acl));
    expect(trans.isDelete()).andStubReturn(TRANSITION_IS_DELETED);
    replay(trans);
    JSONObject t = AccessInformationUtil.serializeEpisodeACLTransition(trans);
    assertEquals(TRANSITION_ID, t.getLong("id"));
    assertEquals(TRANSITION_APPLICATION_DATE, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))));
    assertEquals(TRANSITION_WORKFLOW_ID, Option.some(ConfiguredWorkflowRef.workflow(t.getString("workflow_id"))));
    assertEquals(TRANSITION_IS_DELETED, t.getBoolean("is_deleted"));
    assertEquals(TRANSITION_ACL_ID, t.getLong("acl_id"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Date(java.util.Date) Test(org.junit.Test)

Example 29 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class AccessInformationUtilTest method testSerializeManagedAcl.

/**
 * Test method for {@link AccessInformationUtil#serializeManagedAcl(ManagedAcl)}
 */
@Test
public void testSerializeManagedAcl() throws Exception {
    AccessControlList acl = new AccessControlList();
    acl.getEntries().add(ACE_ROLE_ADMIN_ALLOW_ACTION_READ);
    ManagedAcl manAcl = new ManagedAclImpl(1L, MANAGED_ACL_1_NAME, ORGANISATION_1_ID, acl);
    JSONObject aclJson = AccessInformationUtil.serializeManagedAcl(manAcl);
    assertEquals(1L, aclJson.getLong("id"));
    assertEquals(MANAGED_ACL_1_NAME, aclJson.getString("name"));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) JSONObject(org.codehaus.jettison.json.JSONObject) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ManagedAclImpl(org.opencastproject.authorization.xacml.manager.impl.ManagedAclImpl) Test(org.junit.Test)

Example 30 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class AccessInformationUtilTest method testSerializeSeriesACLTransition.

/**
 * Test method for {@link AccessInformationUtil#serializeSeriesACLTransition(SeriesACLTransition)}
 */
@Test
public void testSerializeSeriesACLTransition() throws Exception {
    ManagedAcl acl = createNiceMock(ManagedAcl.class);
    expect(acl.getId()).andStubReturn(TRANSITION_ACL_ID);
    replay(acl);
    SeriesACLTransition trans = createNiceMock(SeriesACLTransition.class);
    expect(trans.getTransitionId()).andStubReturn(TRANSITION_ID);
    expect(trans.getApplicationDate()).andStubReturn(TRANSITION_APPLICATION_DATE);
    expect(trans.getWorkflow()).andStubReturn(TRANSITION_WORKFLOW_ID);
    expect(trans.isDone()).andStubReturn(TRANSITION_DONE);
    expect(trans.getAccessControlList()).andStubReturn(acl);
    expect(trans.isOverride()).andStubReturn(TRANSITION_OVERRIDE_EPISODES);
    replay(trans);
    JSONObject t = AccessInformationUtil.serializeSeriesACLTransition(trans);
    assertEquals(TRANSITION_ID, t.getLong("id"));
    assertEquals(TRANSITION_APPLICATION_DATE, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))));
    assertEquals(TRANSITION_WORKFLOW_ID, Option.some(ConfiguredWorkflowRef.workflow(t.getString("workflow_id"))));
    assertEquals(TRANSITION_DONE, t.getBoolean("done"));
    assertEquals(TRANSITION_ACL_ID, t.getLong("acl_id"));
    assertEquals(TRANSITION_OVERRIDE_EPISODES, t.getBoolean("override_episodes"));
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) JSONObject(org.codehaus.jettison.json.JSONObject) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)35 Test (org.junit.Test)18 AccessControlList (org.opencastproject.security.api.AccessControlList)16 Date (java.util.Date)12 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)8 ArrayList (java.util.ArrayList)7 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)7 NotFoundException (org.opencastproject.util.NotFoundException)7 File (java.io.File)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 RestQuery (org.opencastproject.util.doc.rest.RestQuery)5 TransitionQuery (org.opencastproject.authorization.xacml.manager.api.TransitionQuery)4 AclTransitionDbException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)4 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)4 GET (javax.ws.rs.GET)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 ManagedAclImpl (org.opencastproject.authorization.xacml.manager.impl.ManagedAclImpl)3 Event (org.opencastproject.index.service.impl.index.event.Event)3