use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException 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());
}
use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.
the class OsgiJpaAclTransitionDbTest method testUpdateEpisode.
@Test
public void testUpdateEpisode() throws Exception {
final ManagedAcl macl = createAcl();
EpisodeACLTransition t1 = db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
EpisodeACLTransition u1 = db.updateEpisodeAclTransition(ORG, t1.getTransitionId(), t1.getApplicationDate(), none(0L), Option.some(workflow("full")));
assertEquals(t1.getTransitionId(), u1.getTransitionId());
assertEquals(t1.getEpisodeId(), u1.getEpisodeId());
assertEquals(t1.getOrganizationId(), u1.getOrganizationId());
assertTrue(u1.getAccessControlList().isNone());
assertNotSame(t1.isDelete(), u1.isDelete());
assertNotSame(t1.getWorkflow(), u1.getWorkflow());
try {
db.updateEpisodeAclTransition(ORG2, t1.getTransitionId(), t1.getApplicationDate(), some(macl.getId()), Option.some(workflow("full")));
fail("Updating from non-owner org should not be possible");
} catch (AclTransitionDbException ignore1) {
} catch (NotFoundException ignore2) {
}
}
use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.
the class OsgiJpaAclTransitionDbTest method testUpdateSeries.
@Test
public void testUpdateSeries() throws Exception {
final ManagedAcl macl = createAcl();
SeriesACLTransition t1 = db.storeSeriesAclTransition(ORG, "uuid", new Date(), macl.getId(), true, Option.<ConfiguredWorkflowRef>none());
SeriesACLTransition u1 = db.updateSeriesAclTransition(ORG, t1.getTransitionId(), t1.getApplicationDate(), macl.getId(), false, Option.some(workflow("full")));
assertEquals(t1.getTransitionId(), u1.getTransitionId());
assertEquals(t1.getSeriesId(), u1.getSeriesId());
assertEquals(t1.getOrganizationId(), u1.getOrganizationId());
assertEquals(t1.getAccessControlList().getId(), u1.getAccessControlList().getId());
assertNotSame(t1.getWorkflow(), u1.getWorkflow());
assertNotSame(t1.isOverride(), u1.isOverride());
try {
db.updateSeriesAclTransition(ORG2, t1.getTransitionId(), t1.getApplicationDate(), macl.getId(), false, Option.some(workflow("full")));
fail("Updating from non-owner org should not be possible");
} catch (AclTransitionDbException ignore1) {
} catch (NotFoundException ignore2) {
}
}
use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.
the class OsgiJpaAclTransitionDb method markSeriesTransitionAsCompleted.
@Override
public SeriesACLTransition markSeriesTransitionAsCompleted(Organization org, long transitionId) throws AclTransitionDbException, NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
SeriesAclTransitionEntity entity = getSeriesEntity(transitionId, org.getId(), em);
if (entity == null)
throw new NotFoundException("Series transition " + transitionId + " not found!");
entity.setDone(true);
em.merge(entity);
tx.commit();
return entity;
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not update the scheduled series ACL: {}", e.getMessage());
if (tx != null && tx.isActive())
tx.rollback();
throw new AclTransitionDbException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.
the class OsgiJpaAclTransitionDb method storeEpisodeAclTransition.
@Override
public EpisodeACLTransition storeEpisodeAclTransition(Organization org, String episodeId, Date applicationDate, Option<Long> managedAclId, Option<ConfiguredWorkflowRef> workflow) throws AclTransitionDbException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
EpisodeAclTransitionEntity entity = new EpisodeAclTransitionEntity().update(episodeId, org.getId(), applicationDate, getManagedAcl(em, managedAclId, org), workflow);
em.persist(entity);
tx.commit();
return entity;
} catch (AclTransitionDbException e) {
throw e;
} catch (Exception e) {
if (tx != null && tx.isActive())
tx.rollback();
boolean isConstraintViolation = Util.isConstraintViolationException(e);
if (isConstraintViolation)
throw new AclTransitionDbDuplicatedException();
else {
logger.error("Could not store the scheduled episode ACL: {}", e.getMessage());
throw new AclTransitionDbException(e);
}
} finally {
if (em != null)
em.close();
}
}
Aggregations