Search in sources :

Example 6 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class DefaultsWorkflowOperationHandlerTest method usesEventLevelPreset.

@Test
public void usesEventLevelPreset() throws WorkflowOperationException {
    Organization organization = EasyMock.createMock(Organization.class);
    EasyMock.replay(organization);
    String seriesID = "series-ID";
    Map<String, String> workflowConfiguration = new HashMap<String, String>();
    workflowConfiguration.put(OPT_KEY, WORKFLOW_PRESET_VALUE);
    WorkflowInstance workflowInstance = setupInstance(organization, seriesID, workflowConfiguration, true);
    DefaultsWorkflowOperationHandler handler = new DefaultsWorkflowOperationHandler();
    handler.setPresetProvider(presetProvider);
    WorkflowOperationResult result = handler.start(workflowInstance, null);
    assertEquals(EVENT_PRESET_VALUE, result.getProperties().get(OPT_KEY));
}
Also used : Organization(org.opencastproject.security.api.Organization) HashMap(java.util.HashMap) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 7 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class DefaultsWorkflowOperationHandlerTest method usesOrganizationLevelPresetNullSeries.

@Test
public void usesOrganizationLevelPresetNullSeries() throws WorkflowOperationException, NotFoundException {
    Organization organization = EasyMock.createMock(Organization.class);
    EasyMock.replay(organization);
    String seriesID = null;
    presetProvider = EasyMock.createMock(PresetProvider.class);
    EasyMock.expect(presetProvider.getProperty(seriesID, OPT_KEY)).andReturn(ORGANIZATION_PRESET_VALUE);
    EasyMock.replay(presetProvider);
    // Workflow configuration
    Map<String, String> workflowConfiguration = new HashMap<String, String>();
    workflowConfiguration.put(OPT_KEY, WORKFLOW_PRESET_VALUE);
    WorkflowInstance workflowInstance = setupInstance(organization, seriesID, workflowConfiguration, false);
    DefaultsWorkflowOperationHandler handler = new DefaultsWorkflowOperationHandler();
    handler.setPresetProvider(presetProvider);
    WorkflowOperationResult result = handler.start(workflowInstance, null);
    assertEquals(ORGANIZATION_PRESET_VALUE, result.getProperties().get(OPT_KEY));
}
Also used : Organization(org.opencastproject.security.api.Organization) PresetProvider(org.opencastproject.presets.api.PresetProvider) HashMap(java.util.HashMap) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 8 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class SecurityUtil method getUserOfOrganization.

/**
 * Get a user of a certain organization by its ID.
 */
public static Option<User> getUserOfOrganization(SecurityService sec, OrganizationDirectoryService orgDir, String orgId, UserDirectoryService userDir, String userId) {
    final Organization prevOrg = sec.getOrganization();
    try {
        final Organization org = orgDir.getOrganization(orgId);
        sec.setOrganization(org);
        return option(userDir.loadUser(userId));
    } catch (NotFoundException e) {
        return none();
    } finally {
        sec.setOrganization(prevOrg);
    }
}
Also used : JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Organization(org.opencastproject.security.api.Organization) NotFoundException(org.opencastproject.util.NotFoundException)

Example 9 with Organization

use of org.opencastproject.security.api.Organization 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 10 with Organization

use of org.opencastproject.security.api.Organization 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)

Aggregations

Organization (org.opencastproject.security.api.Organization)135 User (org.opencastproject.security.api.User)60 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)46 NotFoundException (org.opencastproject.util.NotFoundException)43 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)29 SecurityService (org.opencastproject.security.api.SecurityService)29 IOException (java.io.IOException)24 Before (org.junit.Before)24 ArrayList (java.util.ArrayList)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)22 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)22 JaxbRole (org.opencastproject.security.api.JaxbRole)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 JaxbUser (org.opencastproject.security.api.JaxbUser)20 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)19 File (java.io.File)18 HashMap (java.util.HashMap)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)17 Test (org.junit.Test)15