use of org.opencastproject.security.impl.jpa.JpaRole in project opencast by opencast.
the class JpaGroupRoleProviderTest method testDuplicateGroup.
@Test
public void testDuplicateGroup() throws UnauthorizedException {
Set<JpaRole> roles1 = set(new JpaRole("ROLE_ASTRO_101_SPRING_2011_STUDENT", org1));
Set<JpaRole> roles2 = set(new JpaRole("ROLE_ASTRO_101_SPRING_2011_STUDENT", org2));
Set<String> members = set("admin");
provider.addGroup(new JpaGroup("test1", org1, "Test", "Test group", roles1, members));
provider.addGroup(new JpaGroup("test1", org2, "Test 2", "Test group 2", roles2, members));
assertEquals("Test", provider.loadGroup("test1", org1.getId()).getName());
// duplicate group, but add group does an update so it will pass
provider.addGroup(new JpaGroup("test1", org1, "Test 1", "Test group 1", roles1, members));
assertEquals("Test 1", provider.loadGroup("test1", org1.getId()).getName());
}
use of org.opencastproject.security.impl.jpa.JpaRole in project opencast by opencast.
the class JpaUserProviderTest method testRoles.
@Test
public void testRoles() throws Exception {
JpaUser userOne = createUserWithRoles(org1, "user1", "ROLE_ONE");
provider.addUser(userOne);
Set<JpaRole> authoritiesTwo = new HashSet<JpaRole>();
authoritiesTwo.add(new JpaRole("ROLE_ONE", org1));
authoritiesTwo.add(new JpaRole("ROLE_TWO", org1));
JpaUser userTwo = createUserWithRoles(org1, "user2", "ROLE_ONE", "ROLE_TWO");
provider.addUser(userTwo);
assertEquals("There should be two roles", 2, IteratorUtils.toList(provider.getRoles()).size());
}
use of org.opencastproject.security.impl.jpa.JpaRole in project opencast by opencast.
the class JpaUserProviderTest method testRolesForUser.
@Test
public void testRolesForUser() {
JpaRole astroRole = new JpaRole("ROLE_ASTRO_105_SPRING_2013_STUDENT", org1, "Astro role");
provider.addRole(astroRole);
JpaUser userOne = createUserWithRoles(org1, "user1", "ROLE_ONE", "ROLE_TWO");
try {
provider.addUser(userOne);
} catch (UnauthorizedException e) {
fail("User should be created");
}
assertEquals("There should be three roles", 3, IteratorUtils.toList(provider.getRoles()).size());
List<Role> rolesForUser = provider.getRolesForUser("user1");
assertEquals("There should be two roles", 2, rolesForUser.size());
assertEquals("ROLE_ONE", rolesForUser.get(0).getName());
assertEquals("ROLE_TWO", rolesForUser.get(1).getName());
}
use of org.opencastproject.security.impl.jpa.JpaRole in project opencast by opencast.
the class JpaUserProviderTest method testAddAndGetRole.
@Test
public void testAddAndGetRole() throws Exception {
JpaRole astroRole = new JpaRole("ROLE_ASTRO_105_SPRING_2013_STUDENT", org1, "Astro role");
provider.addRole(astroRole);
Iterator<Role> roles = provider.getRoles();
assertTrue("There should be one role", roles.hasNext());
Role role = roles.next();
assertEquals(astroRole.getName(), role.getName());
assertEquals(astroRole.getOrganization(), role.getOrganization());
assertEquals(astroRole.getDescription(), role.getDescription());
assertFalse("There should onyl be one role", roles.hasNext());
}
use of org.opencastproject.security.impl.jpa.JpaRole in project opencast by opencast.
the class JpaUserProviderTest method testUpdateUserForbiddenForNonAdminUsers.
@Test
public void testUpdateUserForbiddenForNonAdminUsers() throws Exception {
JpaUser adminUser = createUserWithRoles(org1, "admin", SecurityConstants.GLOBAL_ADMIN_ROLE);
JpaUser user = createUserWithRoles(org1, "user", "ROLE_USER");
provider.addUser(adminUser);
provider.addUser(user);
provider.setSecurityService(mockSecurityServiceWithUser(user));
// try to add ROLE_USER
Set<JpaRole> updatedRoles = Collections.set(new JpaRole("ROLE_USER", org1), new JpaRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org1));
try {
provider.updateUser(new JpaUser(adminUser.getUsername(), adminUser.getPassword(), org1, adminUser.getName(), true, updatedRoles));
fail("The current user may not edit an admin user");
} catch (UnauthorizedException e) {
// pass
}
// try to remove ROLE_ADMIN
updatedRoles = Collections.set(new JpaRole("ROLE_USER", org1));
try {
provider.updateUser(new JpaUser(adminUser.getUsername(), adminUser.getPassword(), org1, adminUser.getName(), true, updatedRoles));
fail("The current user may not remove the admin role on other user");
} catch (UnauthorizedException e) {
// pass
}
}
Aggregations