OsgiAclServiceRestEndpoint.java

/*
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 *
 * The Apereo Foundation licenses this file to you under the Educational
 * Community License, Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the License
 * at:
 *
 *   http://opensource.org/licenses/ecl2.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

package org.opencastproject.authorization.xacml.manager.endpoint;

import static org.opencastproject.util.RestUtil.getEndpointUrl;

import org.opencastproject.assetmanager.api.AssetManager;
import org.opencastproject.authorization.xacml.manager.api.AclServiceFactory;
import org.opencastproject.security.api.AuthorizationService;
import org.opencastproject.security.api.SecurityService;
import org.opencastproject.util.UrlSupport;
import org.opencastproject.util.data.Tuple;
import org.opencastproject.util.doc.rest.RestService;

import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.Path;

/** REST endpoint for ACL manager. */
@Path("/acl-manager")
@RestService(
    name = "aclmanager",
    title = "ACL Manager",
    abstractText = "This service creates, edits, retrieves and helps managing access policies (ACL templates).",
    notes = {}
)
@Component(
    name = "org.opencastproject.authorization.xacml.manager.endpoint.ACLManagerRestService",
    service = OsgiAclServiceRestEndpoint.class,
    property = {
        "service.description=ACL Manager REST endpoint",
        "opencast.service.type=org.opencastproject.authorization.xacml.manager",
        "opencast.service.path=/acl-manager"
    }
)
@JaxrsResource
public final class OsgiAclServiceRestEndpoint extends AbstractAclServiceRestEndpoint {
  /** Logging utility */
  private static final Logger logger = LoggerFactory.getLogger(OsgiAclServiceRestEndpoint.class);

  private AclServiceFactory aclServiceFactory;
  private SecurityService securityService;
  private AuthorizationService authorizationService;
  private String endpointBaseUrl;
  private AssetManager assetManager;

  /** OSGi callback. */
  public void activate(ComponentContext cc) {
    logger.info("Start ACL manager rest service");
    final Tuple<String, String> endpointUrl = getEndpointUrl(cc);
    endpointBaseUrl = UrlSupport.concat(endpointUrl.getA(), endpointUrl.getB());
  }

  /** OSGi callback. */
  public void deactivate() {
    logger.info("Stop ACL manager rest service");
  }

  /** OSGi callback for setting persistence. */
  @Reference
  public void setAclServiceFactory(AclServiceFactory aclServiceFactory) {
    this.aclServiceFactory = aclServiceFactory;
  }

  /** OSGi callback for setting security service. */
  @Reference
  public void setSecurityService(SecurityService securityService) {
    this.securityService = securityService;
  }

  /** OSGi DI callback. */
  @Reference
  public void setAuthorizationService(AuthorizationService authorizationService) {
    this.authorizationService = authorizationService;
  }

  /** OSGi DI callback. */
  @Reference
  public void setAssetManager(AssetManager assetManager) {
    this.assetManager = assetManager;
  }

  @Override
  protected AclServiceFactory getAclServiceFactory() {
    return aclServiceFactory;
  }

  @Override
  protected SecurityService getSecurityService() {
    return securityService;
  }

  @Override
  protected AssetManager getAssetManager() {
    return assetManager;
  }

  @Override
  protected AuthorizationService getAuthorizationService() {
    return authorizationService;
  }
}