001/*
002 * Copyright 2015-2019 Ping Identity Corporation
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License (GPLv2 only)
006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007 * as published by the Free Software Foundation.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, see <http://www.gnu.org/licenses>.
016 */
017
018package com.unboundid.scim2.server.resources;
019
020import com.unboundid.scim2.common.GenericScimResource;
021import com.unboundid.scim2.common.types.ServiceProviderConfigResource;
022import com.unboundid.scim2.common.exceptions.ScimException;
023import com.unboundid.scim2.server.annotations.ResourceType;
024import com.unboundid.scim2.server.utils.ResourcePreparer;
025import com.unboundid.scim2.server.utils.ResourceTypeDefinition;
026
027import javax.ws.rs.GET;
028import javax.ws.rs.Path;
029import javax.ws.rs.Produces;
030import javax.ws.rs.core.Context;
031import javax.ws.rs.core.MediaType;
032import javax.ws.rs.core.UriInfo;
033
034import static com.unboundid.scim2.common.utils.ApiConstants.MEDIA_TYPE_SCIM;
035
036/**
037 * An abstract JAX-RS resource class for servicing the Service Provider Config
038 * endpoint.
039 */
040@ResourceType(
041    description = "SCIM 2.0 Service Provider Config",
042    name = "ServiceProviderConfig",
043    schema = ServiceProviderConfigResource.class,
044    discoverable = false)
045@Path("ServiceProviderConfig")
046public abstract class AbstractServiceProviderConfigEndpoint
047{
048  private static final ResourceTypeDefinition RESOURCE_TYPE_DEFINITION =
049      ResourceTypeDefinition.fromJaxRsResource(
050          AbstractServiceProviderConfigEndpoint.class);
051
052  /**
053   * Service request to retrieve the Service Provider Config.
054   *
055   * @param uriInfo UriInfo of the request.
056   * @return The Service Provider Config.
057   * @throws ScimException if an error occurs.
058   */
059  @GET
060  @Produces({MEDIA_TYPE_SCIM, MediaType.APPLICATION_JSON})
061  public GenericScimResource get(@Context final UriInfo uriInfo)
062      throws ScimException
063  {
064    ServiceProviderConfigResource serviceProviderConfig =
065        getServiceProviderConfig();
066    ResourcePreparer<GenericScimResource> resourcePreparer =
067        new ResourcePreparer<GenericScimResource>(
068            RESOURCE_TYPE_DEFINITION, uriInfo);
069    GenericScimResource resource =
070        serviceProviderConfig.asGenericScimResource();
071    resourcePreparer.setResourceTypeAndLocation(resource);
072    return resource;
073  }
074
075  /**
076   * Retrieve the current service provider config.
077   *
078   * @return The current service provider config.
079   * @throws ScimException if an error occurs.
080   */
081  public abstract ServiceProviderConfigResource getServiceProviderConfig()
082      throws ScimException;
083}