Search in sources :

Example 26 with User

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

the class JpaUserReferenceProvider method findUsers.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.security.api.UserProvider#findUsers(String, int, int)
 */
@Override
public Iterator<User> findUsers(String query, int offset, int limit) {
    if (query == null)
        throw new IllegalArgumentException("Query must be set");
    String orgId = securityService.getOrganization().getId();
    List<User> users = new ArrayList<User>();
    for (JpaUserReference userRef : findUserReferencesByQuery(orgId, query, limit, offset, emf)) {
        users.add(userRef.toUser(PROVIDER_NAME));
    }
    return users.iterator();
}
Also used : User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) JpaUserReference(org.opencastproject.security.impl.jpa.JpaUserReference)

Example 27 with User

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

the class JpaUserReferenceProvider method activate.

/**
 * Callback for activation of this component.
 *
 * @param cc
 *          the component context
 */
public void activate(ComponentContext cc) {
    logger.debug("activate");
    // Setup the caches
    cache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build(new CacheLoader<String, Object>() {

        @Override
        public Object load(String id) {
            String[] key = id.split(DELIMITER);
            logger.trace("Loading user '{}':'{}' from reference database", key[0], key[1]);
            User user = loadUser(key[0], key[1]);
            return user == null ? nullToken : user;
        }
    });
// Set up persistence
}
Also used : User(org.opencastproject.security.api.User) CacheLoader(com.google.common.cache.CacheLoader)

Example 28 with User

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

the class UserIdRoleProvider method findRoles.

/**
 * @see org.opencastproject.security.api.RoleProvider#findRoles(String,Role.Target, int, int)
 */
@Override
public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) {
    if (query == null)
        throw new IllegalArgumentException("Query must be set");
    // These roles are not meaningful for users/groups
    if (target == Role.Target.USER) {
        return Collections.emptyIterator();
    }
    logger.debug("findRoles(query={} offset={} limit={})", query, offset, limit);
    HashSet<Role> foundRoles = new HashSet<Role>();
    Organization organization = securityService.getOrganization();
    // Return authenticated user role if it matches the query pattern
    if (like(ROLE_USER, query)) {
        foundRoles.add(new JaxbRole(ROLE_USER, JaxbOrganization.fromOrganization(organization), "The authenticated user role", Role.Type.SYSTEM));
    }
    // (iterating through users may be slow)
    if (!"%".equals(query) && !query.startsWith(userRolePrefix)) {
        return foundRoles.iterator();
    }
    String userQuery = "%";
    if (query.startsWith(userRolePrefix)) {
        userQuery = query.substring(userRolePrefix.length());
    }
    Iterator<User> users = userDirectoryService.findUsers(userQuery, offset, limit);
    while (users.hasNext()) {
        User u = users.next();
        // We exclude the digest user, but then add the global ROLE_USER above
        if (!"system".equals(u.getProvider())) {
            foundRoles.add(new JaxbRole(getUserIdRole(u.getUsername()), JaxbOrganization.fromOrganization(u.getOrganization()), "User id role", Role.Type.SYSTEM));
        }
    }
    return foundRoles.iterator();
}
Also used : Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Organization(org.opencastproject.security.api.Organization) JaxbRole(org.opencastproject.security.api.JaxbRole) User(org.opencastproject.security.api.User) HashSet(java.util.HashSet)

Example 29 with User

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

the class VideoEditorTest method setUp.

/**
 * Setup for the video editor service, including creation of a mock workspace and all dependencies.
 *
 * @throws Exception
 *           if setup fails
 */
@Before
public void setUp() throws Exception {
    File tmpDir = folder.newFolder(getClass().getName());
    // output file
    tempFile1 = new File(tmpDir, "testoutput.mp4");
    /* mock the workspace for the input/output file */
    // workspace.get(new URI(sourceTrackUri));
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.rootDirectory()).andReturn(tmpDir.getAbsolutePath());
    EasyMock.expect(workspace.get(track1.getURI())).andReturn(new File(track1.getURI())).anyTimes();
    EasyMock.expect(workspace.get(track2.getURI())).andReturn(new File(track2.getURI())).anyTimes();
    EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(InputStream.class))).andAnswer(() -> {
        InputStream in = (InputStream) EasyMock.getCurrentArguments()[2];
        IOUtils.copy(in, new FileOutputStream(tempFile1));
        return tempFile1.toURI();
    });
    /* mock the role/org/security dependencies */
    User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization()));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    /* mock the osgi init for the video editor itself */
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    File storageDir = folder.newFolder();
    logger.info("storageDir: {}", storageDir);
    EasyMock.expect(bc.getProperty("org.opencastproject.storage.dir")).andReturn(storageDir.getPath()).anyTimes();
    EasyMock.expect(bc.getProperty("org.opencastproject.composer.ffmpegpath")).andReturn(FFMPEG_BINARY).anyTimes();
    EasyMock.expect(bc.getProperty(FFmpegAnalyzer.FFPROBE_BINARY_CONFIG)).andReturn("ffprobe").anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(bc, cc, workspace, userDirectoryService, organizationDirectoryService, securityService);
    /* mock inspector output so that the job will alway pass */
    String sourceTrackXml = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<track xmlns=\"http://mediapackage.opencastproject.org\" type='presentation/source' id='deadbeef-a926-4ba9-96d9-2fafbcc30d2a'>" + "<audio id='audio-1'><encoder type='MP3 (MPEG audio layer 3)'/><channels>2</channels>" + "<bitrate>96000.0</bitrate></audio><video id='video-1'><device/>" + "<encoder type='FLV / Sorenson Spark / Sorenson H.263 (Flash Video)'/>" + "<bitrate>512000.0</bitrate><framerate>15.0</framerate>" + "<resolution>854x480</resolution></video>" + "<mimetype>video/mpeg</mimetype><url>video.mp4</url></track>";
    inspectedTrack = (Track) MediaPackageElementParser.getFromXml(sourceTrackXml);
    veditor = new VideoEditorServiceImpl() {

        @Override
        protected Job inspect(Job job, URI workspaceURI) throws MediaInspectionException, ProcessFailedException {
            Job inspectionJob = EasyMock.createNiceMock(Job.class);
            try {
                EasyMock.expect(inspectionJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(inspectedTrack));
            } catch (MediaPackageException e) {
                throw new MediaInspectionException(e);
            }
            EasyMock.replay(inspectionJob);
            return inspectionJob;
        }
    };
    /* set up video editor */
    veditor.activate(cc);
    veditor.setWorkspace(workspace);
    veditor.setSecurityService(securityService);
    veditor.setUserDirectoryService(userDirectoryService);
    veditor.setSmilService(smilService);
    veditor.setOrganizationDirectoryService(organizationDirectoryService);
    serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
    final Capture<String> type = EasyMock.newCapture();
    final Capture<String> operation = EasyMock.newCapture();
    final Capture<List<String>> args = EasyMock.newCapture();
    EasyMock.expect(serviceRegistry.createJob(capture(type), capture(operation), capture(args), EasyMock.anyFloat())).andAnswer(() -> {
        Job job = new JobImpl(0);
        logger.error("type: {}", type.getValue());
        job.setJobType(type.getValue());
        job.setOperation(operation.getValue());
        job.setArguments(args.getValue());
        job.setPayload(veditor.process(job));
        return job;
    }).anyTimes();
    EasyMock.replay(serviceRegistry);
    veditor.setServiceRegistry(serviceRegistry);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) SecurityService(org.opencastproject.security.api.SecurityService) List(java.util.List) ArrayList(java.util.ArrayList) Job(org.opencastproject.job.api.Job) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JobImpl(org.opencastproject.job.api.JobImpl) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) FileOutputStream(java.io.FileOutputStream) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 30 with User

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

the class LdapUserProviderInstance method getUsers.

@Override
public Iterator<User> getUsers() {
    // TODO implement LDAP get all users
    // FIXME We return the current user, rather than an empty list, to make sure the current user's role is displayed in
    // the admin UI (MH-12526).
    User currentUser = securityService.getUser();
    if (loadUser(currentUser.getUsername()) != null) {
        List<User> retVal = new ArrayList<>();
        retVal.add(securityService.getUser());
        return retVal.iterator();
    }
    return Collections.<User>emptyList().iterator();
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) ArrayList(java.util.ArrayList)

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