Search in sources :

Example 1 with EpisodeACLTransition

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

the class EpisodeAclTransitionEntity method update.

EpisodeAclTransitionEntity update(final String episodeId, final String orgId, final Date applicationDate, final Option<ManagedAclEntity> managedAcl, final Option<ConfiguredWorkflowRef> workflow) {
    final EpisodeAclTransitionEntity self = this;
    run(EpisodeACLTransition.class, new EpisodeACLTransition() {

        @Override
        public String getEpisodeId() {
            self.episodeId = episodeId;
            return null;
        }

        @Override
        public Option<ManagedAcl> getAccessControlList() {
            self.managedAcl = managedAcl.getOrElseNull();
            return null;
        }

        @Override
        public boolean isDelete() {
            return false;
        }

        @Override
        public long getTransitionId() {
            return 0;
        }

        @Override
        public String getOrganizationId() {
            self.organizationId = orgId;
            return null;
        }

        @Override
        public Date getApplicationDate() {
            self.applicationDate = applicationDate;
            return null;
        }

        @Override
        public Option<ConfiguredWorkflowRef> getWorkflow() {
            final Tuple<Option<String>, Option<String>> s = splitConfiguredWorkflowRef(workflow);
            self.workflowId = s.getA().getOrElseNull();
            self.workflowParams = s.getB().getOrElseNull();
            return null;
        }

        @Override
        public boolean isDone() {
            self.done = done;
            return false;
        }
    });
    return self;
}
Also used : Option(org.opencastproject.util.data.Option) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Date(java.util.Date) Tuple(org.opencastproject.util.data.Tuple)

Example 2 with EpisodeACLTransition

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

the class AbstractAclServiceRestEndpoint method updateEpisodeTransition.

@PUT
@Path("/episode/{transitionId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateepisodetransition", description = "Update an existing episode transition", returnDescription = "Update an existing episode transition", pathParameters = { @RestParameter(name = "transitionId", isRequired = true, description = "The transition id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = false, description = "The managed access control list id", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The workflow definition identifier", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "The workflow parameters as JSON", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The episode transition has successfully been updated"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating an episode transition") })
public String updateEpisodeTransition(@PathParam("transitionId") long transitionId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") Long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) throws NotFoundException {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        final EpisodeACLTransition t = aclService().updateEpisodeTransition(transitionId, option(managedAclId), at, workflow);
        return JsonConv.full(t).toJson();
    } catch (AclServiceException e) {
        logger.warn("Error updating episode transition:", e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.warn("Unable to parse the application date");
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(org.opencastproject.util.NotFoundException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Date(java.util.Date) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 3 with EpisodeACLTransition

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

the class OsgiJpaAclTransitionDbTest method testGetEpisodeTransitions.

@Test
public void testGetEpisodeTransitions() throws Exception {
    final ManagedAcl macl = createAcl();
    db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
    db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
    // there should now be two transitions for episode "uuid"
    List<EpisodeACLTransition> episodes = db.getEpisodeAclTransitions(ORG, "uuid");
    assertEquals(2, episodes.size());
    // transitions shouldn't be accessible from another organization
    assertEquals(0, db.getEpisodeAclTransitions(ORG2, "uuid").size());
}
Also used : 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 4 with EpisodeACLTransition

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

the class AclScannerTest method setUp.

@Before
public void setUp() throws Exception {
    Organization org1 = new JpaOrganization("org1", "org1", new HashMap<String, Integer>(), "ADMIN", "ANONYMOUS", new HashMap<String, String>());
    Organization org2 = new JpaOrganization("org2", "org2", new HashMap<String, Integer>(), "ADMIN", "ANONYMOUS", new HashMap<String, String>());
    Organization org3 = new JpaOrganization("org3", "org3", new HashMap<String, Integer>(), "ADMIN", "ANONYMOUS", new HashMap<String, String>());
    List<Organization> orgs = new ArrayList<>();
    orgs.add(org1);
    orgs.add(org2);
    orgs.add(org3);
    aclDb = EasyMock.createNiceMock(AclDb.class);
    orgService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgService.getOrganizations()).andReturn(orgs).anyTimes();
    final SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    final MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    final AclTransitionDb aclTransitionDb = EasyMock.createNiceMock(AclTransitionDb.class);
    List<EpisodeACLTransition> episodeTransitions = new ArrayList<>();
    List<SeriesACLTransition> seriesTransitions = new ArrayList<>();
    EasyMock.expect(aclTransitionDb.getByQuery(EasyMock.anyObject(Organization.class), EasyMock.anyObject(TransitionQuery.class))).andReturn(new TransitionResultImpl(episodeTransitions, seriesTransitions)).anyTimes();
    // EasyMock.replay(aclDb);
    EasyMock.replay(orgService, messageSender, aclTransitionDb, securityService);
    AclServiceFactory aclServiceFactory = new AclServiceFactory() {

        @Override
        public AclService serviceFor(Organization org) {
            return new AclServiceImpl(new DefaultOrganization(), aclDb, aclTransitionDb, null, null, null, null, messageSender, null);
        }
    };
    aclScanner = new AclScanner();
    aclScanner.setAclServiceFactory(aclServiceFactory);
    aclScanner.setOrganizationDirectoryService(orgService);
    aclScanner.setSecurityService(securityService);
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) EasyMock.anyString(org.easymock.EasyMock.anyString) AclServiceFactory(org.opencastproject.authorization.xacml.manager.api.AclServiceFactory) SecurityService(org.opencastproject.security.api.SecurityService) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 5 with EpisodeACLTransition

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

the class OsgiJpaAclTransitionDbTest method testStoreAndGetEpisodeACL.

@Test
public void testStoreAndGetEpisodeACL() throws Exception {
    final Date now = new Date();
    // a fallback to series transition should be saveable
    db.storeEpisodeAclTransition(ORG, "uuid", now, none(0L), Option.<ConfiguredWorkflowRef>none());
    // a transition referencing a non existing ACL should not be saveable
    try {
        db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(1L), Option.<ConfiguredWorkflowRef>none());
        fail("No ACL with ID 1");
    } catch (AclTransitionDbException ignore) {
    }
    // a transition referencing an existing ACL should be saveable
    final ManagedAcl macl = createAcl();
    final EpisodeACLTransition t3 = db.storeEpisodeAclTransition(ORG, "uuid-2", now, some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
    assertEquals("uuid-2", t3.getEpisodeId());
    assertEquals(now, t3.getApplicationDate());
    assertTrue(t3.getAccessControlList().isSome());
    assertEquals(macl.getName(), t3.getAccessControlList().get().getName());
    // a transition with the same properties should not be saveable
    try {
        db.storeEpisodeAclTransition(ORG, "uuid", now, some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
        fail("Duplicated episode ACL must not be stored");
    } catch (AclTransitionDbDuplicatedException ignore) {
    }
    List<EpisodeACLTransition> ts = db.getEpisodeAclTransitions(ORG, "uuid");
    assertEquals(1, ts.size());
    assertEquals("uuid", ts.get(0).getEpisodeId());
    assertTrue(ts.get(0).isDelete());
    assertTrue(!ts.get(0).isDone());
}
Also used : ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) Date(java.util.Date) Test(org.junit.Test)

Aggregations

EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)13 Date (java.util.Date)10 Test (org.junit.Test)7 ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)7 NotFoundException (org.opencastproject.util.NotFoundException)6 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)4 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)3 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)3 TransitionQuery (org.opencastproject.authorization.xacml.manager.api.TransitionQuery)3 SeriesException (org.opencastproject.series.api.SeriesException)3 GET (javax.ws.rs.GET)2 AclTransitionDbException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)2 AccessControlList (org.opencastproject.security.api.AccessControlList)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1