use of org.opencastproject.security.api.User in project opencast by opencast.
the class AssetManagerMessageReceiverImpl method handleMessage.
/**
* Handle a delete message.
*/
private void handleMessage(DeleteEpisode msg) {
final String eventId = msg.getMediaPackageId();
final String organization = getSecurityService().getOrganization().getId();
final User user = getSecurityService().getUser();
logger.debug("Received AssetManager delete episode message {}", eventId);
// Remove the archived entry from the search index
try {
getSearchIndex().deleteAssets(organization, user, eventId);
logger.debug("Archived media package {} removed from admin ui search index", eventId);
} catch (NotFoundException e) {
logger.warn("Archived media package {} not found for deletion", eventId);
} catch (SearchIndexException e) {
logger.error("Error deleting the archived entry {} from the search index: {}", eventId, ExceptionUtils.getStackTrace(e));
}
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class UsersListProvider method getList.
@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) {
Map<String, String> usersList = new HashMap<String, String>();
int offset = 0;
int limit = 0;
if (query != null) {
if (query.getLimit().isSome())
limit = query.getLimit().get();
if (query.getOffset().isSome())
offset = query.getOffset().get();
}
Iterator<User> users = userDirectoryService.findUsers("%", offset, limit);
while (users.hasNext()) {
User u = users.next();
if (EMAIL.equals(listName) && StringUtils.isNotBlank(u.getEmail())) {
usersList.put(u.getEmail(), u.getEmail());
} else if (USERNAME.equals(listName) && StringUtils.isNotBlank(u.getUsername())) {
usersList.put(u.getUsername(), u.getUsername());
} else if (USERDIRECTORY.equals(listName) && StringUtils.isNotBlank(u.getProvider())) {
usersList.put(u.getProvider(), u.getProvider());
} else if (NAME.equals(listName) && StringUtils.isNotBlank(u.getName())) {
usersList.put(u.getName(), u.getName());
} else if (INVERSE.equals(listName) || INVERSE_WITH_EMAIL.equals(listName) || INVERSE_WITH_USERNAME.equals(listName)) {
usersList.put(createDisplayName(u, listName), u.getUsername());
} else if (DEFAULT.equals(listName) || DEFAULT_WITH_EMAIL.equals(listName) || DEFAULT_WITH_USERNAME.equals(listName)) {
usersList.put(u.getUsername(), createDisplayName(u, listName));
} else if (ROLE.equals(listName) && u.getRoles().size() > 0) {
for (Role role : u.getRoles()) {
usersList.put(role.getName(), role.getName());
}
}
}
return usersList;
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class SeriesServiceDatabaseImpl method userHasReadAccess.
private boolean userHasReadAccess(SeriesEntity entity) throws IOException, AccessControlParsingException {
// Ensure this user is allowed to read this series
String accessControlXml = entity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
// There are several reasons a user may need to load a series: to read content, to edit it, or add content
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.READ.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.CONTRIBUTE.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.WRITE.toString())) {
return false;
}
}
return true;
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class SeriesServiceDatabaseImpl method userHasWriteAccess.
private boolean userHasWriteAccess(SeriesEntity entity) throws IOException, AccessControlParsingException {
// Ensure this user is allowed to write this series
String accessControlXml = entity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.WRITE.toString())) {
return false;
}
}
return true;
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class SeriesServiceDatabaseImpl method deleteSeries.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#deleteSeries(java.lang.String)
*/
@Override
public void deleteSeries(String seriesId) throws SeriesServiceDatabaseException, NotFoundException {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
throw new NotFoundException("Series with ID " + seriesId + " does not exist");
}
// Ensure this user is allowed to delete this series
String accessControlXml = entity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.WRITE.toString())) {
throw new UnauthorizedException(currentUser + " is not authorized to update series " + seriesId);
}
}
em.remove(entity);
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not delete series: {}", e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SeriesServiceDatabaseException(e);
} finally {
em.close();
}
}
Aggregations