use of org.opencastproject.security.api.Group in project opencast by opencast.
the class JpaGroupRoleProviderTest method testRemoveGroupNotAllowedAsNonAdminUser.
@Test
public void testRemoveGroupNotAllowedAsNonAdminUser() 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(group.getGroupId(), loadGroup.getGroupId());
} catch (Exception e) {
fail("The group should 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);
Response removeGroupResponse = provider.removeGroup(group.getGroupId());
assertNotNull(removeGroupResponse);
assertEquals(HttpStatus.SC_FORBIDDEN, removeGroupResponse.getStatus());
}
use of org.opencastproject.security.api.Group in project opencast by opencast.
the class JpaGroupRoleProviderTest method testAddAndGetGroup.
@Test
public void testAddAndGetGroup() throws Exception {
Set<JpaRole> authorities = new HashSet<JpaRole>();
authorities.add(new JpaRole("ROLE_ASTRO_101_SPRING_2011_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);
Group loadGroup = provider.loadGroup("test", org1.getId());
Assert.assertNotNull(loadGroup);
Assert.assertEquals(loadGroup.getGroupId(), loadGroup.getGroupId());
Assert.assertEquals(loadGroup.getName(), loadGroup.getName());
Assert.assertEquals(loadGroup.getDescription(), loadGroup.getDescription());
Assert.assertEquals(loadGroup.getOrganization(), loadGroup.getOrganization());
Assert.assertEquals(loadGroup.getRole(), loadGroup.getRole());
Assert.assertEquals(loadGroup.getRoles(), loadGroup.getRoles());
Assert.assertEquals(loadGroup.getMembers(), loadGroup.getMembers());
Assert.assertNull("Loading 'does not exist' should return null", provider.loadGroup("does not exist", org1.getId()));
Assert.assertNull("Loading 'does not exist' should return null", provider.loadGroup("user1", org2.getId()));
}
Aggregations