Search in sources :

Example 11 with User

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));
    }
}
Also used : User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 12 with User

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;
}
Also used : Role(org.opencastproject.security.api.Role) User(org.opencastproject.security.api.User) HashMap(java.util.HashMap)

Example 13 with User

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;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization)

Example 14 with User

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;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization)

Example 15 with User

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();
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AccessControlParsingException(org.opencastproject.security.api.AccessControlParsingException)

Aggregations

User (org.opencastproject.security.api.User)156 Organization (org.opencastproject.security.api.Organization)61 JaxbUser (org.opencastproject.security.api.JaxbUser)60 JaxbRole (org.opencastproject.security.api.JaxbRole)49 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)44 SecurityService (org.opencastproject.security.api.SecurityService)43 NotFoundException (org.opencastproject.util.NotFoundException)32 Before (org.junit.Before)31 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)26 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)24 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)23 AccessControlList (org.opencastproject.security.api.AccessControlList)21 Role (org.opencastproject.security.api.Role)21 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)21 HashSet (java.util.HashSet)20 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)18 JpaUser (org.opencastproject.security.impl.jpa.JpaUser)17 IOException (java.io.IOException)16 MediaPackage (org.opencastproject.mediapackage.MediaPackage)16