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));
}
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));
}
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));
}
});
}
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);
}
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();
}
Aggregations