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