Search in sources :

Example 31 with JpaUser

use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.

the class JpaUserProviderTest method testAddUserWithGlobalAdminRoleNotAllowedAsOrgAdmin.

@Test(expected = UnauthorizedException.class)
public void testAddUserWithGlobalAdminRoleNotAllowedAsOrgAdmin() throws Exception {
    provider.setSecurityService(mockSecurityServiceWithUser(createUserWithRoles(org1, "org1_admin", org1.getAdminRole())));
    JpaUser newUser = createUserWithRoles(org1, "admin2", SecurityConstants.GLOBAL_ADMIN_ROLE);
    provider.addUser(newUser);
    fail("The current user shouldn't able to create an global admin user.");
}
Also used : JpaUser(org.opencastproject.security.impl.jpa.JpaUser) Test(org.junit.Test)

Example 32 with JpaUser

use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.

the class JpaUserProviderTest method testDeleteUserNotAllowedAsNonAdmin.

@Test(expected = UnauthorizedException.class)
public void testDeleteUserNotAllowedAsNonAdmin() throws UnauthorizedException, Exception {
    JpaUser adminUser = createUserWithRoles(org1, "admin", "ROLE_ADMIN");
    JpaUser nonAdminUser = createUserWithRoles(org1, "user1", "ROLE_USER");
    try {
        provider.addUser(adminUser);
        provider.addUser(nonAdminUser);
    } catch (UnauthorizedException ex) {
        fail("The user shuld be created");
    }
    provider.setSecurityService(mockSecurityServiceWithUser(nonAdminUser));
    provider.deleteUser(adminUser.getUsername(), org1.getId());
    fail("An non admin user may not delete an admin user");
}
Also used : UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) Test(org.junit.Test)

Example 33 with JpaUser

use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.

the class JpaUserProviderTest method testAddUserWithOrgAdminRoleAsGlobalAdmin.

@Test
public void testAddUserWithOrgAdminRoleAsGlobalAdmin() throws Exception {
    JpaUser newUser = createUserWithRoles(org1, "org_admin2", org1.getAdminRole());
    provider.addUser(newUser);
    User loadedUser = provider.loadUser(newUser.getUsername());
    assertNotNull("The currently added user isn't loaded as expected", loadedUser);
    assertEquals(newUser.getUsername(), loadedUser.getUsername());
    assertEquals(newUser.getRoles(), loadedUser.getRoles());
}
Also used : User(org.opencastproject.security.api.User) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) Test(org.junit.Test)

Example 34 with JpaUser

use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.

the class JpaUserProviderTest method testUsers.

@Test
public void testUsers() throws Exception {
    Set<JpaRole> authorities = new HashSet<JpaRole>();
    authorities.add(new JpaRole("ROLE_COOL_ONE", org1));
    JpaUser userOne = createUserWithRoles(org1, "user_test_1", "ROLE_COOL_ONE");
    JpaUser userTwo = createUserWithRoles(org1, "user2", "ROLE_CCOL_ONE");
    JpaUser userThree = createUserWithRoles(org1, "user3", "ROLE_COOL_ONE");
    JpaUser userFour = createUserWithRoles(org1, "user_test_4", "ROLE_COOL_ONE");
    provider.addUser(userOne);
    provider.addUser(userTwo);
    provider.addUser(userThree);
    provider.addUser(userFour);
    assertEquals("There should be two roles", 4, IteratorUtils.toList(provider.getUsers()).size());
}
Also used : JpaRole(org.opencastproject.security.impl.jpa.JpaRole) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with JpaUser

use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.

the class JpaUserProviderTest method testFindRoles.

@Test
public void testFindRoles() throws UnauthorizedException {
    JpaRole astroRole = new JpaRole("ROLE_ASTRO_105_SPRING_2013_STUDENT", org1, "Astro role");
    provider.addRole(astroRole);
    JpaUser userOne = createUserWithRoles(org1, "user1", "ROLE_COOL_ONE", "ROLE_COOL_TWO");
    provider.addUser(userOne);
    // We expect findRoles() for this provider to return an empty set,
    // as it is not authoritative for roles that it persists.
    assertEquals(0, IteratorUtils.toList(provider.findRoles("%coOL%", Role.Target.ALL, 0, 0)).size());
    assertEquals(0, IteratorUtils.toList(provider.findRoles("%cOoL%", Role.Target.ALL, 0, 1)).size());
    assertEquals(0, IteratorUtils.toList(provider.findRoles("%oLe%", Role.Target.ALL, 0, 0)).size());
    assertEquals(0, IteratorUtils.toList(provider.findRoles("%olE%", Role.Target.ALL, 1, 2)).size());
}
Also used : JpaRole(org.opencastproject.security.impl.jpa.JpaRole) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) Test(org.junit.Test)

Aggregations

JpaUser (org.opencastproject.security.impl.jpa.JpaUser)35 Test (org.junit.Test)19 JpaRole (org.opencastproject.security.impl.jpa.JpaRole)18 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)13 User (org.opencastproject.security.api.User)12 NotFoundException (org.opencastproject.util.NotFoundException)9 HashSet (java.util.HashSet)8 JpaOrganization (org.opencastproject.security.impl.jpa.JpaOrganization)8 EntityManager (javax.persistence.EntityManager)5 Path (javax.ws.rs.Path)4 SecurityService (org.opencastproject.security.api.SecurityService)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 EntityTransaction (javax.persistence.EntityTransaction)3 NoResultException (javax.persistence.NoResultException)3 Before (org.junit.Before)3 Role (org.opencastproject.security.api.Role)3 JpaGroup (org.opencastproject.security.impl.jpa.JpaGroup)3 JObject (com.entwinemedia.fn.data.json.JObject)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2