Search in sources :

Example 11 with SecurityService

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

the class JpaGroupRoleProviderTest method setUp.

@Before
public void setUp() throws Exception {
    JpaUser adminUser = new JpaUser("admin", "pass1", org1, "Admin", "admin@localhost", "opencast", true, Collections.set(new JpaRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org1)));
    // Set the security sevice
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(adminUser).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(org1).anyTimes();
    EasyMock.replay(securityService);
    // Create the message sender service
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    messageSender.sendObjectMessage(EasyMock.anyObject(String.class), EasyMock.anyObject(MessageSender.DestinationType.class), EasyMock.anyObject(Serializable.class));
    EasyMock.expectLastCall();
    EasyMock.replay(messageSender);
    provider = new JpaGroupRoleProvider();
    provider.setSecurityService(securityService);
    provider.setMessageSender(messageSender);
    provider.setEntityManagerFactory(newTestEntityManagerFactory(JpaUserAndRoleProvider.PERSISTENCE_UNIT));
    provider.activate(null);
}
Also used : Serializable(java.io.Serializable) SecurityService(org.opencastproject.security.api.SecurityService) MessageSender(org.opencastproject.message.broker.api.MessageSender) JpaRole(org.opencastproject.security.impl.jpa.JpaRole) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) Before(org.junit.Before)

Example 12 with SecurityService

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

the class JpaGroupRoleProviderTest method testUpdateGroupNotAllowedAsNonAdminUser.

@Test
public void testUpdateGroupNotAllowedAsNonAdminUser() throws UnauthorizedException {
    JpaGroup group = new JpaGroup("test", org1, "Test", "Test group", Collections.set(new JpaRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org1)));
    try {
        provider.addGroup(group);
        Group loadGroup = provider.loadGroup(group.getGroupId(), group.getOrganization().getId());
        assertNotNull(loadGroup);
        assertEquals(loadGroup.getGroupId(), loadGroup.getGroupId());
    } catch (Exception e) {
        fail("The group schould be added");
    }
    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);
    try {
        // try add ROLE_USER
        Response updateGroupResponse = provider.updateGroup(group.getGroupId(), group.getName(), group.getDescription(), "ROLE_USER, " + SecurityConstants.GLOBAL_ADMIN_ROLE, null);
        assertNotNull(updateGroupResponse);
        assertEquals(HttpStatus.SC_FORBIDDEN, updateGroupResponse.getStatus());
        // try remove ROLE_ADMIN
        updateGroupResponse = provider.updateGroup(group.getGroupId(), group.getName(), group.getDescription(), "ROLE_USER", null);
        assertNotNull(updateGroupResponse);
        assertEquals(HttpStatus.SC_FORBIDDEN, updateGroupResponse.getStatus());
    } catch (NotFoundException e) {
        fail("The existing group isn't found");
    }
}
Also used : JpaGroup(org.opencastproject.security.impl.jpa.JpaGroup) Response(javax.ws.rs.core.Response) JpaGroup(org.opencastproject.security.impl.jpa.JpaGroup) Group(org.opencastproject.security.api.Group) SecurityService(org.opencastproject.security.api.SecurityService) JpaRole(org.opencastproject.security.impl.jpa.JpaRole) NotFoundException(org.opencastproject.util.NotFoundException) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Example 13 with SecurityService

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

the class UserAndRoleDirectoryServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    org = new DefaultOrganization();
    userName = "sampleUser";
    role1 = new JaxbRole("role1", org);
    role2 = new JaxbRole("role2", org);
    role3 = new JaxbRole("role3", org);
    JaxbUser user1 = new JaxbUser(userName, "matterhorn", org, role1, role2);
    user1.setManageable(true);
    User user2 = new JaxbUser(userName, "secret", "test", true, org, role2, role3);
    User user3 = new JaxbUser("userSample", "test", org, role2, role3);
    List<User> users = new ArrayList<User>();
    users.add(user1);
    UserProvider provider1 = EasyMock.createNiceMock(UserProvider.class);
    EasyMock.expect(provider1.getOrganization()).andReturn(org.getId()).anyTimes();
    EasyMock.expect(provider1.loadUser((String) EasyMock.anyObject())).andReturn(user1).anyTimes();
    EasyMock.expect(provider1.findUsers("%mple%", 0, 0)).andReturn(users.iterator()).once();
    EasyMock.expect(provider1.findUsers("%mple%", 0, 0)).andReturn(users.iterator()).once();
    EasyMock.expect(provider1.getUsers()).andReturn(users.iterator()).once();
    EasyMock.expect(provider1.getName()).andReturn("test").once();
    List<User> users2 = new ArrayList<User>();
    users2.add(user3);
    UserProvider provider2 = EasyMock.createNiceMock(UserProvider.class);
    EasyMock.expect(provider2.getOrganization()).andReturn(org.getId()).anyTimes();
    EasyMock.expect(provider2.loadUser((String) EasyMock.anyObject())).andReturn(user2).anyTimes();
    EasyMock.expect(provider2.findUsers("%mple%", 0, 0)).andReturn(users2.iterator()).once();
    EasyMock.expect(provider2.findUsers("%mple%", 0, 0)).andReturn(users2.iterator()).once();
    EasyMock.expect(provider2.getUsers()).andReturn(users2.iterator()).once();
    EasyMock.expect(provider2.getName()).andReturn("matterhorn").once();
    List<Role> roles1 = new ArrayList<Role>();
    roles1.add(new JaxbRole("ROLE_ASTRO_2011", org));
    roles1.add(new JaxbRole("ROLE_ASTRO_2012", org));
    List<Role> rolesForUser1 = new ArrayList<Role>();
    rolesForUser1.add(new JaxbRole("ROLE_ASTRO_2012", org));
    List<Role> findRoles1 = new ArrayList<Role>();
    findRoles1.add(new JaxbRole("ROLE_ASTRO_2012", org));
    RoleProvider roleProvider1 = EasyMock.createNiceMock(RoleProvider.class);
    EasyMock.expect(roleProvider1.getOrganization()).andReturn(org.getId()).anyTimes();
    EasyMock.expect(roleProvider1.getRoles()).andReturn(roles1.iterator()).anyTimes();
    EasyMock.expect(roleProvider1.getRolesForUser((String) EasyMock.anyObject())).andReturn(rolesForUser1).anyTimes();
    EasyMock.expect(roleProvider1.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles1.iterator()).once();
    EasyMock.expect(roleProvider1.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles1.iterator()).once();
    List<Role> roles2 = new ArrayList<Role>();
    roles2.add(new JaxbRole("ROLE_MATH_2011", org));
    roles2.add(new JaxbRole("ROLE_MATH_2012", org));
    List<Role> rolesForUser2 = new ArrayList<Role>();
    rolesForUser2.add(new JaxbRole("ROLE_MATH_2012", org));
    List<Role> findRoles2 = new ArrayList<Role>();
    findRoles2.add(new JaxbRole("ROLE_MATH_2012", org));
    RoleProvider roleProvider2 = EasyMock.createNiceMock(RoleProvider.class);
    EasyMock.expect(roleProvider2.getOrganization()).andReturn(org.getId()).anyTimes();
    EasyMock.expect(roleProvider2.getRoles()).andReturn(roles2.iterator()).anyTimes();
    EasyMock.expect(roleProvider2.getRolesForUser((String) EasyMock.anyObject())).andReturn(rolesForUser2).anyTimes();
    EasyMock.expect(roleProvider2.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles2.iterator()).once();
    EasyMock.expect(roleProvider2.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles2.iterator()).once();
    RoleProvider otherOrgRoleProvider = EasyMock.createNiceMock(RoleProvider.class);
    EasyMock.expect(otherOrgRoleProvider.getOrganization()).andReturn("otherOrg").anyTimes();
    EasyMock.expect(otherOrgRoleProvider.getRoles()).andReturn(roles2.iterator()).anyTimes();
    EasyMock.expect(otherOrgRoleProvider.getRolesForUser((String) EasyMock.anyObject())).andReturn(rolesForUser2).anyTimes();
    EasyMock.expect(otherOrgRoleProvider.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(new ArrayList<Role>().iterator()).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.replay(provider1, provider2, roleProvider1, roleProvider2, otherOrgRoleProvider, securityService);
    directory = new UserAndRoleDirectoryServiceImpl();
    directory.activate(null);
    directory.setSecurityService(securityService);
    directory.addUserProvider(provider1);
    directory.addUserProvider(provider2);
    directory.addRoleProvider(roleProvider1);
    directory.addRoleProvider(roleProvider2);
    directory.addRoleProvider(otherOrgRoleProvider);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) ArrayList(java.util.ArrayList) JaxbUser(org.opencastproject.security.api.JaxbUser) RoleProvider(org.opencastproject.security.api.RoleProvider) Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbRole(org.opencastproject.security.api.JaxbRole) UserProvider(org.opencastproject.security.api.UserProvider) SecurityService(org.opencastproject.security.api.SecurityService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 14 with SecurityService

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

the class JpaUserProviderTest method mockSecurityServiceWithUser.

private static SecurityService mockSecurityServiceWithUser(User currentUser) {
    // Set the security sevice
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(currentUser.getOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(currentUser).anyTimes();
    EasyMock.replay(securityService);
    return securityService;
}
Also used : SecurityService(org.opencastproject.security.api.SecurityService)

Example 15 with SecurityService

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

the class AnnotationServiceJpaImplTest method setUp.

@Before
public void setUp() throws Exception {
    // Set up a mock security service that always returns "me" as the current user
    DefaultOrganization organization = new DefaultOrganization();
    JaxbRole role = new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, organization, "");
    HashSet<JaxbRole> roles = new HashSet<JaxbRole>();
    roles.add(role);
    User me = new JaxbUser("me", "test", organization, roles);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(me).anyTimes();
    EasyMock.replay(securityService);
    // Set up the annotation service
    annotationService = new AnnotationServiceJpaImpl();
    annotationService.setEntityManagerFactory(newTestEntityManagerFactory(AnnotationServiceJpaImpl.PERSISTENCE_UNIT));
    annotationService.setSecurityService(securityService);
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashSet(java.util.HashSet) Before(org.junit.Before)

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