Search in sources :

Example 76 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class BaseEndpoint method getEndpointInfo.

@GET
@Path("")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getendpointinfo", description = "Returns key characteristics of the API such as the server name and the default version.", returnDescription = "", reponses = { @RestResponse(description = "The api information is returned.", responseCode = HttpServletResponse.SC_OK) })
public Response getEndpointInfo() {
    Organization organization = securityService.getOrganization();
    String orgExternalAPIUrl = organization.getProperties().get(OpencastConstants.EXTERNAL_API_URL_ORG_PROPERTY);
    JString url;
    if (StringUtils.isNotBlank(orgExternalAPIUrl)) {
        url = v(orgExternalAPIUrl);
    } else {
        url = v(endpointBaseUrl);
    }
    JValue json = obj(f("url", url), f("version", v(ApiVersion.CURRENT_VERSION.toString())));
    return RestUtil.R.ok(MediaType.APPLICATION_JSON_TYPE, serializer.toJson(json));
}
Also used : Organization(org.opencastproject.security.api.Organization) JValue(com.entwinemedia.fn.data.json.JValue) JString(com.entwinemedia.fn.data.json.JString) JString(com.entwinemedia.fn.data.json.JString) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 77 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class BaseEndpoint method getOrganizationInfo.

@GET
@Path("info/organization")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getorganizationinfo", description = "Returns the current organization.", returnDescription = "", reponses = { @RestResponse(description = "The organization details are returned.", responseCode = HttpServletResponse.SC_OK) })
public Response getOrganizationInfo() {
    final Organization org = securityService.getOrganization();
    JValue json = obj(f("adminRole", v(org.getAdminRole())), f("anonymousRole", v(org.getAnonymousRole())), f("id", v(org.getId())), f("name", v(org.getName())));
    return RestUtil.R.ok(MediaType.APPLICATION_JSON_TYPE, serializer.toJson(json));
}
Also used : Organization(org.opencastproject.security.api.Organization) JValue(com.entwinemedia.fn.data.json.JValue) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 78 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class EventCommentDatabaseServiceImpl method repopulate.

@Override
public void repopulate(final String indexName) throws Exception {
    final String destinationId = CommentItem.COMMENT_QUEUE_PREFIX + WordUtils.capitalize(indexName);
    try {
        final int total = countComments();
        final int[] current = new int[1];
        current[0] = 0;
        logger.info("Re-populating index '{}' with comments for events. There are {} events with comments to add", indexName, total);
        final int responseInterval = (total < 100) ? 1 : (total / 100);
        final Map<String, List<String>> eventsWithComments = getEventsWithComments();
        for (String orgId : eventsWithComments.keySet()) {
            Organization organization = organizationDirectoryService.getOrganization(orgId);
            SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

                @Override
                protected void run() {
                    for (String eventId : eventsWithComments.get(orgId)) {
                        try {
                            List<EventComment> comments = getComments(eventId);
                            boolean hasOpenComments = !Stream.$(comments).filter(filterOpenComments).toList().isEmpty();
                            boolean needsCutting = !Stream.$(comments).filter(filterNeedsCuttingComment).toList().isEmpty();
                            messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, CommentItem.update(eventId, !comments.isEmpty(), hasOpenComments, needsCutting));
                            current[0] += comments.size();
                            if (responseInterval == 1 || comments.size() > responseInterval || current[0] == total || current[0] % responseInterval < comments.size()) {
                                messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Comments, total, current[0]));
                            }
                        } catch (EventCommentDatabaseException e) {
                            logger.error("Unable to retrieve event comments for organization {}", orgId, e);
                        } catch (Throwable t) {
                            logger.error("Unable to update comment on event {} for organization {}", eventId, orgId, t);
                        }
                    }
                }
            });
        }
    } catch (Exception e) {
        logger.warn("Unable to index event comments", e);
        throw new ServiceException(e.getMessage());
    }
    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.Comments));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) ServiceException(org.osgi.framework.ServiceException) NoResultException(javax.persistence.NoResultException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceException(org.osgi.framework.ServiceException) Effect0(org.opencastproject.util.data.Effect0) ArrayList(java.util.ArrayList) List(java.util.List) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 79 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class UserSettingsServiceTest method before.

@Before
public void before() {
    User user = EasyMock.createNiceMock(User.class);
    EasyMock.expect(user.getUsername()).andReturn(USER_NAME);
    EasyMock.replay(user);
    Organization organization = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(organization.getId()).andReturn(ORG).anyTimes();
    EasyMock.replay(organization);
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser(USER_NAME)).andReturn(user).anyTimes();
    EasyMock.replay(userDirectoryService);
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) SecurityService(org.opencastproject.security.api.SecurityService) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) Before(org.junit.Before)

Example 80 with Organization

use of org.opencastproject.security.api.Organization in project opencast by opencast.

the class OsgiEndpointHttpAssetProvider method calcServerUrl.

/**
 * Calculate the server url based on the current organization.
 */
private String calcServerUrl(String organizationId) {
    Organization organization = null;
    try {
        organization = orgDir.getOrganization(organizationId);
    } catch (NotFoundException e) {
        logger.warn("No organization found! Using default server url ({})", serverUrl);
        return serverUrl.trim();
    }
    // Get asset manager URL. Default to admin node URL or to server URL
    String orgServerUrl = organization.getProperties().get(OpencastConstants.ASSET_MANAGER_URL_ORG_PROPERTY);
    if (StringUtils.isBlank(orgServerUrl)) {
        orgServerUrl = organization.getProperties().get(OpencastConstants.ADMIN_URL_ORG_PROPERTY);
        logger.debug("No asset manager URL for organization '{}'. Falling back to admin node url ({})", organization, orgServerUrl);
    }
    if (StringUtils.isBlank(orgServerUrl)) {
        logger.debug("No admin node URL for organization '{}' set. Falling back to default server url ({})", organization, serverUrl);
        orgServerUrl = serverUrl;
    }
    return orgServerUrl.trim();
}
Also used : Organization(org.opencastproject.security.api.Organization) NotFoundException(org.opencastproject.util.NotFoundException)

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