Search in sources :

Example 31 with Organization

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);
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization)

Example 32 with Organization

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(",")));
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) Pred(com.entwinemedia.fn.Pred) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

Example 33 with Organization

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;
}
Also used : Organization(org.opencastproject.security.api.Organization) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 34 with Organization

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));
}
Also used : DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Organization(org.opencastproject.security.api.Organization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 35 with Organization

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"));
}
Also used : DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Organization(org.opencastproject.security.api.Organization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) HashMap(java.util.HashMap) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Aggregations

Organization (org.opencastproject.security.api.Organization)135 User (org.opencastproject.security.api.User)60 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)46 NotFoundException (org.opencastproject.util.NotFoundException)43 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)29 SecurityService (org.opencastproject.security.api.SecurityService)29 IOException (java.io.IOException)24 Before (org.junit.Before)24 ArrayList (java.util.ArrayList)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)22 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)22 JaxbRole (org.opencastproject.security.api.JaxbRole)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 JaxbUser (org.opencastproject.security.api.JaxbUser)20 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)19 File (java.io.File)18 HashMap (java.util.HashMap)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)17 Test (org.junit.Test)15