Search in sources :

Example 91 with SecurityService

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");
}
Also used : JpaGroup(org.opencastproject.security.impl.jpa.JpaGroup) SecurityService(org.opencastproject.security.api.SecurityService) JpaRole(org.opencastproject.security.impl.jpa.JpaRole) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) Test(org.junit.Test)

Example 92 with SecurityService

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);
}
Also used : JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) SecurityService(org.opencastproject.security.api.SecurityService) Before(org.junit.Before)

Example 93 with SecurityService

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ComponentContext(org.osgi.service.component.ComponentContext) MessageSender(org.opencastproject.message.broker.api.MessageSender) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Callable(java.util.concurrent.Callable) JaxbRole(org.opencastproject.security.api.JaxbRole) SchedulerServiceDatabaseImpl(org.opencastproject.scheduler.impl.persistence.SchedulerServiceDatabaseImpl) BaseMessage(org.opencastproject.message.broker.api.BaseMessage) MessageReceiver(org.opencastproject.message.broker.api.MessageReceiver) AuthorizationService(org.opencastproject.security.api.AuthorizationService) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) BundleContext(org.osgi.framework.BundleContext) BeforeClass(org.junit.BeforeClass)

Example 94 with SecurityService

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));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 95 with SecurityService

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;
        }
    };
}
Also used : Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) ConfigurationException(org.osgi.service.cm.ConfigurationException) SecurityService(org.opencastproject.security.api.SecurityService) NotFoundException(org.opencastproject.util.NotFoundException) Function0(org.opencastproject.util.data.Function0) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService)

Aggregations

SecurityService (org.opencastproject.security.api.SecurityService)99 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)62 Before (org.junit.Before)55 JaxbUser (org.opencastproject.security.api.JaxbUser)44 User (org.opencastproject.security.api.User)43 JaxbRole (org.opencastproject.security.api.JaxbRole)39 Organization (org.opencastproject.security.api.Organization)31 Test (org.junit.Test)30 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)29 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)29 Workspace (org.opencastproject.workspace.api.Workspace)29 MediaPackage (org.opencastproject.mediapackage.MediaPackage)22 InputStream (java.io.InputStream)21 URI (java.net.URI)21 File (java.io.File)20 ArrayList (java.util.ArrayList)20 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)18 MessageSender (org.opencastproject.message.broker.api.MessageSender)16 AuthorizationService (org.opencastproject.security.api.AuthorizationService)16 IOException (java.io.IOException)15