use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class JpaGroupRoleProviderTest method testAddGroupNotAllowedAsNonAdminUser.
@Test(expected = UnauthorizedException.class)
public void testAddGroupNotAllowedAsNonAdminUser() throws UnauthorizedException {
JpaUser user = new JpaUser("user", "pass1", org1, "User", "user@localhost", "opencast", true, Collections.set(new JpaRole("ROLE_USER", org1)));
// Set the security sevice
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(org1).anyTimes();
EasyMock.replay(securityService);
provider.setSecurityService(securityService);
JpaGroup group = new JpaGroup("test", org1, "Test", "Test group", Collections.set(new JpaRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org1)));
provider.addGroup(group);
fail("The group with admin role should not be created by an non admin user");
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class JpaUserProviderTest method setUp.
@Before
public void setUp() throws Exception {
org1 = new JpaOrganization("org1", "org1", "localhost", 80, "admin", "anon", null);
org2 = new JpaOrganization("org2", "org2", "127.0.0.1", 80, "admin", "anon", null);
SecurityService securityService = mockSecurityServiceWithUser(createUserWithRoles(org1, "admin", SecurityConstants.GLOBAL_SYSTEM_ROLES));
JpaGroupRoleProvider groupRoleProvider = EasyMock.createNiceMock(JpaGroupRoleProvider.class);
provider = new JpaUserAndRoleProvider();
provider.setSecurityService(securityService);
provider.setEntityManagerFactory(newTestEntityManagerFactory(JpaUserAndRoleProvider.PERSISTENCE_UNIT));
provider.setGroupRoleProvider(groupRoleProvider);
provider.activate(null);
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class SchedulerServiceImplTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
wfProperties.put("test", "true");
wfProperties.put("clear", "all");
wfPropertiesUpdated.put("test", "false");
wfPropertiesUpdated.put("skip", "true");
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
schedulerDatabase = new SchedulerServiceDatabaseImpl();
schedulerDatabase.setEntityManagerFactory(mkEntityManagerFactory(SchedulerServiceDatabaseImpl.PERSISTENCE_UNIT));
schedulerDatabase.setSecurityService(securityService);
schedulerDatabase.activate(null);
workspace = new UnitTestWorkspace();
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
final BaseMessage baseMessageMock = EasyMock.createNiceMock(BaseMessage.class);
MessageReceiver messageReceiver = EasyMock.createNiceMock(MessageReceiver.class);
EasyMock.expect(messageReceiver.receiveSerializable(EasyMock.anyString(), EasyMock.anyObject(MessageSender.DestinationType.class))).andStubReturn(new FutureTask<>(new Callable<Serializable>() {
@Override
public Serializable call() throws Exception {
return baseMessageMock;
}
}));
AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
acl = new AccessControlList(new AccessControlEntry("ROLE_ADMIN", "write", true), new AccessControlEntry("ROLE_ADMIN", "read", true), new AccessControlEntry("ROLE_USER", "read", true));
EasyMock.expect(authorizationService.getAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class))).andReturn(Option.some(acl)).anyTimes();
OrganizationDirectoryService orgDirectoryService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectoryService.getOrganizations()).andReturn(Arrays.asList((Organization) new DefaultOrganization())).anyTimes();
EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bundleContext.getProperty(EasyMock.anyString())).andReturn("adminuser").anyTimes();
ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
EasyMock.replay(messageSender, baseMessageMock, messageReceiver, authorizationService, securityService, extendedAdapter, episodeAdapter, orgDirectoryService, componentContext, bundleContext);
testConflictHandler = new TestConflictHandler();
schedSvc = new SchedulerServiceImpl();
schedSvc.setAuthorizationService(authorizationService);
schedSvc.setSecurityService(securityService);
schedSvc.setPersistence(schedulerDatabase);
schedSvc.setWorkspace(workspace);
schedSvc.setMessageSender(messageSender);
schedSvc.setMessageReceiver(messageReceiver);
schedSvc.setConflictHandler(testConflictHandler);
schedSvc.addCatalogUIAdapter(episodeAdapter);
schedSvc.addCatalogUIAdapter(extendedAdapter);
schedSvc.setOrgDirectoryService(orgDirectoryService);
schedSvc.activate(componentContext);
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class SearchServicePersistenceTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
securityService = EasyMock.createNiceMock(SecurityService.class);
DefaultOrganization defaultOrganization = new DefaultOrganization();
User user = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, defaultOrganization));
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
searchDatabase = new SearchServiceDatabaseImpl();
searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
searchDatabase.setSecurityService(securityService);
searchDatabase.activate(null);
mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
accessControlList = new AccessControlList();
List<AccessControlEntry> acl = accessControlList.getEntries();
acl.add(new AccessControlEntry("admin", Permissions.Action.WRITE.toString(), true));
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class OaiPmhHarvester method createSecurityConfigurator.
/**
* Return a function that configures the security service with a {@link User} and {@link Organization}.
*/
private static Function0<Void> createSecurityConfigurator(Dictionary properties, ComponentContext cc) throws ConfigurationException {
// get services
final OrganizationDirectoryService organizationDirectoryService = (OrganizationDirectoryService) cc.locateService(REF_ORG_SERVICE);
final SecurityService securityService = (SecurityService) cc.locateService(REF_SECURITY_SERVICE);
final UserDirectoryService userDirectoryService = (UserDirectoryService) cc.locateService(REF_USER_SERVICE);
// get the organization
String organizationName = getCfg(properties, CFG_USER_ORGANIZATION);
final Organization organization;
try {
organization = organizationDirectoryService.getOrganization(organizationName);
} catch (NotFoundException e) {
throw new ConfigurationException(CFG_USER_ORGANIZATION, "Organization '" + organizationName + "' does not exist");
}
// get the user
final User user;
final Organization originalOrg = securityService.getOrganization();
try {
String userName = getCfg(properties, CFG_USER_NAME);
securityService.setOrganization(organization);
user = userDirectoryService.loadUser(userName);
} finally {
securityService.setOrganization(originalOrg);
}
return new Function0<Void>() {
@Override
public Void apply() {
securityService.setOrganization(organization);
securityService.setUser(user);
return null;
}
};
}
Aggregations