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();
}
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
}
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();
}
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);
}
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();
}
Aggregations