use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class OsgiAclServiceFactory method repopulate.
@Override
public void repopulate(final String indexName) {
final String destinationId = AclItem.ACL_QUEUE_PREFIX + WordUtils.capitalize(indexName);
for (final Organization organization : organizationDirectoryService.getOrganizations()) {
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {
@Override
protected void run() {
AclService aclService = serviceFor(organization);
List<ManagedAcl> acls = aclService.getAcls();
int total = aclService.getAcls().size();
logger.info("Re-populating index with acls. There are {} acls(s) to add to the index.", total);
int current = 1;
for (ManagedAcl acl : acls) {
logger.trace("Adding acl '{}' for org '{}'", acl.getName(), organization.getId());
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, AclItem.create(acl.getName()));
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Acl, total, current));
current++;
}
}
});
}
Organization organization = new DefaultOrganization();
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {
@Override
protected void run() {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Acl));
}
});
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class IndexServiceImplTest method setupSecurityService.
private SecurityService setupSecurityService(String username, String org) {
// Setup Security Service, Organization and User
Organization organization = EasyMock.createNiceMock(Organization.class);
EasyMock.expect(organization.getId()).andReturn(org).anyTimes();
EasyMock.replay(organization);
User user = EasyMock.createMock(User.class);
EasyMock.expect(user.getOrganization()).andReturn(organization).anyTimes();
EasyMock.expect(user.getUsername()).andReturn(username);
EasyMock.replay(user);
SecurityService securityService = EasyMock.createMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user);
EasyMock.replay(securityService);
return securityService;
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class ListProvidersScannerTest method testInstallInputOrgInPropertiesFileExpectsAddedToService.
@Test
public void testInstallInputOrgInPropertiesFileExpectsAddedToService() throws Exception {
Organization org1 = EasyMock.createMock(Organization.class);
EasyMock.expect(org1.getId()).andReturn("org1").anyTimes();
EasyMock.replay(org1);
Organization org2 = EasyMock.createMock(Organization.class);
EasyMock.expect(org2.getId()).andReturn("org2").anyTimes();
EasyMock.replay(org2);
String listName = "BLACKLISTS.USERS.REASONS";
File file = new File(ListProvidersScannerTest.class.getResource("/ListProvidersScannerTest-WithOrg.properties").toURI());
Capture<ResourceListProvider> resourceListProvider = new Capture<>();
Capture<String> captureListName = new Capture<>();
ListProvidersService listProvidersService = EasyMock.createNiceMock(ListProvidersService.class);
listProvidersService.addProvider(EasyMock.capture(captureListName), EasyMock.capture(resourceListProvider));
EasyMock.expectLastCall();
EasyMock.replay(listProvidersService);
ListProvidersScanner listProvidersScanner = new ListProvidersScanner();
listProvidersScanner.setListProvidersService(listProvidersService);
listProvidersScanner.install(file);
ResourceListQuery query = new ResourceListQueryImpl();
assertEquals(1, resourceListProvider.getValues().size());
assertEquals(listName, resourceListProvider.getValue().getListNames()[0]);
Map<String, String> stuff = resourceListProvider.getValue().getList(listName, query, org1);
for (String key : stuff.keySet()) {
logger.info("Key: {}, Value {}.", key, stuff.get(key));
}
assertEquals(3, resourceListProvider.getValue().getList(listName, query, org1).size());
assertNull(resourceListProvider.getValue().getList(listName, query, org2));
assertNull(resourceListProvider.getValue().getList(listName, query, null));
assertEquals("Sick Leave", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.SICK_LEAVE"));
assertEquals("Leave", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.LEAVE"));
assertEquals("Family Emergency", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.FAMILY_EMERGENCY"));
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class AclEndpoint method updateAcl.
@PUT
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateacl", description = "Update an ACL", returnDescription = "Update an ACL", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "The ACL identifier", type = INTEGER) }, restParameters = { @RestParameter(name = "name", isRequired = true, description = "The ACL name", type = STRING), @RestParameter(name = "acl", isRequired = true, description = "The access control list", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has successfully been updated"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The ACL has not been found"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the ACL") })
public Response updateAcl(@PathParam("id") long aclId, @FormParam("name") String name, @FormParam("acl") String accessControlList) throws NotFoundException {
final Organization org = securityService.getOrganization();
final AccessControlList acl = parseAcl.apply(accessControlList);
final ManagedAclImpl managedAcl = new ManagedAclImpl(aclId, name, org.getId(), acl);
if (!aclService().updateAcl(managedAcl)) {
logger.info("No ACL with id '{}' could be found under organization '{}'", aclId, org.getId());
throw new NotFoundException();
}
return RestUtils.okJson(full(managedAcl));
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class UsersEndpoint method deleteUser.
@DELETE
@Path("{username}.json")
@RestQuery(name = "deleteUser", description = "Deleter a new user", returnDescription = "Status ok", pathParameters = @RestParameter(name = "username", type = STRING, isRequired = true, description = "The username"), reponses = { @RestResponse(responseCode = SC_OK, description = "User has been deleted."), @RestResponse(responseCode = SC_FORBIDDEN, description = "Not enough permissions to delete a user with admin role."), @RestResponse(responseCode = SC_NOT_FOUND, description = "User not found.") })
public Response deleteUser(@PathParam("username") String username) throws NotFoundException {
Organization organization = securityService.getOrganization();
try {
jpaUserAndRoleProvider.deleteUser(username, organization.getId());
userDirectoryService.invalidate(username);
} catch (NotFoundException e) {
logger.error("User {} not found.", username);
return Response.status(SC_NOT_FOUND).build();
} catch (UnauthorizedException e) {
return Response.status(SC_FORBIDDEN).build();
} catch (Exception e) {
logger.error("Error during deletion of user {}: {}", username, e);
return Response.status(SC_INTERNAL_SERVER_ERROR).build();
}
logger.debug("User {} removed.", username);
return Response.status(SC_OK).build();
}
Aggregations