use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class SearchServicePersistenceTest method testAdding.
@Test
public void testAdding() throws Exception {
Date modifictaionDate = new Date();
searchDatabase.storeMediaPackage(mediaPackage, accessControlList, modifictaionDate);
Iterator<Tuple<MediaPackage, String>> mediaPackages = searchDatabase.getAllMediaPackages();
while (mediaPackages.hasNext()) {
Tuple<MediaPackage, String> mediaPackage = mediaPackages.next();
String mediaPackageId = mediaPackage.getA().getIdentifier().toString();
AccessControlList acl = searchDatabase.getAccessControlList(mediaPackageId);
Assert.assertEquals(accessControlList.getEntries().size(), acl.getEntries().size());
Assert.assertEquals(accessControlList.getEntries().get(0), acl.getEntries().get(0));
Assert.assertNull(searchDatabase.getDeletionDate(mediaPackageId));
Assert.assertEquals(modifictaionDate, searchDatabase.getModificationDate(mediaPackageId));
Assert.assertEquals(mediaPackage.getA(), searchDatabase.getMediaPackage(mediaPackageId));
Assert.assertEquals(securityService.getOrganization().getId(), mediaPackage.getB());
Assert.assertEquals(securityService.getOrganization().getId(), searchDatabase.getOrganizationId(mediaPackageId));
}
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class SearchServicePersistenceTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
securityService = EasyMock.createNiceMock(SecurityService.class);
DefaultOrganization defaultOrganization = new DefaultOrganization();
User user = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, defaultOrganization));
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
searchDatabase = new SearchServiceDatabaseImpl();
searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
searchDatabase.setSecurityService(securityService);
searchDatabase.activate(null);
mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
accessControlList = new AccessControlList();
List<AccessControlEntry> acl = accessControlList.getEntries();
acl.add(new AccessControlEntry("admin", Permissions.Action.WRITE.toString(), true));
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getAccessControlList.
@Override
public AccessControlList getAccessControlList(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/acl"));
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_NO_CONTENT, SC_UNAUTHORIZED);
try {
if (response != null) {
switch(response.getStatusLine().getStatusCode()) {
case SC_NOT_FOUND:
throw new NotFoundException("Event '" + eventId + "' not found on remote scheduler service!");
case SC_NO_CONTENT:
return null;
case SC_UNAUTHORIZED:
logger.info("Unauthorized to get acl of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get acl of the event " + eventId);
default:
String aclString = EntityUtils.toString(response.getEntity(), "UTF-8");
AccessControlList accessControlList = AccessControlParser.parseAcl(aclString);
logger.info("Successfully get event {} access control list from the remote scheduler service", eventId);
return accessControlList;
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get event access control list from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event access control list from remote scheduler service");
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class SearchServiceDatabaseImpl method getDeletionDate.
/**
* {@inheritDoc}
*
* @see org.opencastproject.search.impl.persistence.SearchServiceDatabase#getDeletionDate(String)
*/
@Override
public Date getDeletionDate(String mediaPackageId) throws NotFoundException, SearchServiceDatabaseException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
SearchEntity searchEntity = getSearchEntity(mediaPackageId, em);
if (searchEntity == null) {
throw new NotFoundException("No media package with id=" + mediaPackageId + " exists");
}
// Ensure this user is allowed to read this media package
String accessControlXml = searchEntity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, READ.toString()))
throw new UnauthorizedException(currentUser + " is not authorized to read media package " + mediaPackageId);
}
return searchEntity.getDeletionDate();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not get deletion date {}: {}", mediaPackageId, e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SearchServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class SearchServiceDatabaseImpl method getModificationDate.
/**
* {@inheritDoc}
*
* @see org.opencastproject.search.impl.persistence.SearchServiceDatabase#getModificationDate(String)
*/
@Override
public Date getModificationDate(String mediaPackageId) throws NotFoundException, SearchServiceDatabaseException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
SearchEntity searchEntity = getSearchEntity(mediaPackageId, em);
if (searchEntity == null)
throw new NotFoundException("No media package with id=" + mediaPackageId + " exists");
// Ensure this user is allowed to read this media package
String accessControlXml = searchEntity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, READ.toString()))
throw new UnauthorizedException(currentUser + " is not authorized to read media package " + mediaPackageId);
}
return searchEntity.getModificationDate();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not get modification date {}: {}", mediaPackageId, e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SearchServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
Aggregations