use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class AssetManagerWithSecurity method isAuthorizedByAcl.
private boolean isAuthorizedByAcl(AccessControlList acl, String action) {
final User user = secSvc.getUser();
final Organization org = secSvc.getOrganization();
return AccessControlUtil.isAuthorized(acl, user, org, action);
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class Protector method protect.
/**
* Evaluate a product if the current user is authorized to perform the given actions.
*/
public <A> Protected<A> protect(final AccessControlList acl, List<String> actions, P1<A> p) {
final User user = secSvc.getUser();
final Organization org = secSvc.getOrganization();
final Pred<String> isAuthorizedToDo = new Pred<String>() {
@Override
public Boolean apply(String action) {
return AccessControlUtil.isAuthorized(acl, user, org, action);
}
};
final boolean isAuthorized = $(actions).map(isAuthorizedToDo).foldl(false, or);
return isAuthorized ? Protected.granted(p.get1()) : Protected.<A>rejected(new UnauthorizedException(user, $(actions).mkString(",")));
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class PaellaConfigRest method getMyInfo.
@GET
@Path("config.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "config.json", description = "Paella configuration file", reponses = { @RestResponse(description = "Returns the paella configuration file", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
@SuppressWarnings("unchecked")
public String getMyInfo() throws IOException {
// Add the current user's organizational information
Organization org = securityService.getOrganization();
File configFile = new File(PathSupport.concat(new String[] { paellaConfigFolder, org.getId(), "config.json" }));
String configContent = FileUtils.readFileToString(configFile);
return configContent;
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class OrganizationPersistenceTest method testList.
@Test
public void testList() throws Exception {
Map<String, String> orgProperties = new HashMap<String, String>();
orgProperties.put("test", "one");
JpaOrganization org1 = new JpaOrganization("newOrg", "test organization", "test.org", 8080, "ROLE_TEST_ADMIN", "ROLE_TEST_ANONYMOUS", orgProperties);
organizationDatabase.storeOrganization(org1);
orgProperties.put("test", "one");
orgProperties.put("test2", "two");
JpaOrganization org2 = new JpaOrganization("newOrg2", "test organization 2", "test2.org", 8081, "ROLE_TEST2_ADMIN", "ROLE_TEST2_ANONYMOUS", orgProperties);
organizationDatabase.storeOrganization(org2);
Assert.assertEquals(2, organizationDatabase.countOrganizations());
List<Organization> organizations = organizationDatabase.getOrganizations();
Assert.assertEquals(2, organizations.size());
Assert.assertEquals(org1, organizations.get(0));
Assert.assertEquals(org2, organizations.get(1));
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class OrganizationPersistenceTest method testAdding.
@Test
public void testAdding() throws Exception {
Map<String, String> orgProperties = new HashMap<String, String>();
orgProperties.put("test", "one");
JpaOrganization org = new JpaOrganization("newOrg", "test organization", "test.org", 8080, "ROLE_TEST_ADMIN", "ROLE_TEST_ANONYMOUS", orgProperties);
organizationDatabase.storeOrganization(org);
Assert.assertTrue(organizationDatabase.containsOrganization("newOrg"));
Organization orgById = organizationDatabase.getOrganization("newOrg");
try {
organizationDatabase.getOrganizationByHost("test.org", 8081);
Assert.fail();
} catch (NotFoundException e) {
Assert.assertNotNull(e);
}
Organization orgByHost = organizationDatabase.getOrganizationByHost("test.org", 8080);
Assert.assertEquals(orgById, orgByHost);
Assert.assertEquals("newOrg", orgById.getId());
Assert.assertEquals("test organization", orgById.getName());
Assert.assertEquals("ROLE_TEST_ADMIN", orgById.getAdminRole());
Assert.assertEquals("ROLE_TEST_ANONYMOUS", orgById.getAnonymousRole());
Map<String, Integer> servers = orgById.getServers();
Assert.assertEquals(1, servers.size());
Assert.assertTrue(servers.containsKey("test.org"));
Assert.assertTrue(servers.containsValue(8080));
Map<String, String> properties = orgById.getProperties();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.containsKey("test"));
Assert.assertTrue(properties.containsValue("one"));
}
Aggregations