use of org.opencastproject.security.impl.jpa.JpaGroup 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");
}
}
use of org.opencastproject.security.impl.jpa.JpaGroup in project opencast by opencast.
the class JpaGroupRoleProviderTest method testRoles.
@Test
@SuppressWarnings("unchecked")
public void testRoles() throws Exception {
Set<JpaRole> authorities = new HashSet<JpaRole>();
authorities.add(new JpaRole("ROLE_ASTRO_101_SPRING_2011_STUDENT", org1));
authorities.add(new JpaRole("ROLE_ASTRO_109_SPRING_2012_STUDENT", org1));
Set<String> members = new HashSet<String>();
members.add("admin");
JpaGroup group = new JpaGroup("test", org1, "Test", "Test group", authorities, members);
provider.addGroup(group);
authorities.clear();
authorities.add(new JpaRole("ROLE_ASTRO_122_SPRING_2011_STUDENT", org1));
authorities.add(new JpaRole("ROLE_ASTRO_124_SPRING_2012_STUDENT", org1));
JpaGroup group2 = new JpaGroup("test2", org1, "Test2", "Test 2 group", authorities, members);
provider.addGroup(group2);
authorities.clear();
authorities.add(new JpaRole("ROLE_ASTRO_134_SPRING_2011_STUDENT", org2));
authorities.add(new JpaRole("ROLE_ASTRO_144_SPRING_2012_STUDENT", org2));
JpaGroup group3 = new JpaGroup("test2", org2, "Test2", "Test 2 group", authorities, members);
provider.addGroup(group3);
List<Role> roles = IteratorUtils.toList(provider.getRoles());
Assert.assertEquals("There should be four role", 6, roles.size());
roles.contains(new JpaRole(group.getRole(), org1));
roles.contains(new JpaRole(group2.getRole(), org1));
}
use of org.opencastproject.security.impl.jpa.JpaGroup 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.JpaGroup in project opencast by opencast.
the class JpaGroupRoleProvider method getGroupsRoles.
/**
* Returns all roles from a given group list
*
* @param groups
* the group list
* @return the role list
*/
private List<Role> getGroupsRoles(List<JpaGroup> groups) {
List<Role> roles = new ArrayList<Role>();
for (Group group : groups) {
roles.add(new JaxbRole(group.getRole(), JaxbOrganization.fromOrganization(group.getOrganization()), "", Role.Type.GROUP));
for (Role role : group.getRoles()) {
JaxbRole grouprole = new JaxbRole(role.getName(), JaxbOrganization.fromOrganization(role.getOrganization()), role.getDescription(), Role.Type.DERIVED);
roles.add(grouprole);
}
}
return roles;
}
use of org.opencastproject.security.impl.jpa.JpaGroup in project opencast by opencast.
the class JpaGroupRoleProvider method getGroupsAsXml.
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("groups.xml")
@RestQuery(name = "allgroupsasxml", description = "Returns a list of groups", returnDescription = "Returns a XML representation of the list of groups available the current user's organization", restParameters = { @RestParameter(defaultValue = "100", description = "The maximum number of items to return per page.", isRequired = false, name = "limit", type = RestParameter.Type.STRING), @RestParameter(defaultValue = "0", description = "The page number.", isRequired = false, name = "offset", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The groups.") })
public JaxbGroupList getGroupsAsXml(@QueryParam("limit") int limit, @QueryParam("offset") int offset) throws IOException {
if (limit < 1)
limit = 100;
String orgId = securityService.getOrganization().getId();
JaxbGroupList groupList = new JaxbGroupList();
List<JpaGroup> groups = UserDirectoryPersistenceUtil.findGroups(orgId, limit, offset, emf);
for (JpaGroup group : groups) {
groupList.add(group);
}
return groupList;
}
Aggregations