001/*
002 * Copyright 2015-2024 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.annotations.NotNull;
022import com.unboundid.scim2.common.types.ServiceProviderConfigResource;
023import com.unboundid.scim2.common.exceptions.ScimException;
024import com.unboundid.scim2.server.annotations.ResourceType;
025import com.unboundid.scim2.server.utils.ResourcePreparer;
026import com.unboundid.scim2.server.utils.ResourceTypeDefinition;
027
028import jakarta.ws.rs.GET;
029import jakarta.ws.rs.Path;
030import jakarta.ws.rs.Produces;
031import jakarta.ws.rs.core.Context;
032import jakarta.ws.rs.core.MediaType;
033import jakarta.ws.rs.core.UriInfo;
034
035import static com.unboundid.scim2.common.utils.ApiConstants.MEDIA_TYPE_SCIM;
036
037/**
038 * An abstract JAX-RS resource class for servicing the Service Provider Config
039 * endpoint.
040 */
041@ResourceType(
042    description = "SCIM 2.0 Service Provider Config",
043    name = "ServiceProviderConfig",
044    schema = ServiceProviderConfigResource.class,
045    discoverable = false)
046@Path("ServiceProviderConfig")
047public abstract class AbstractServiceProviderConfigEndpoint
048{
049  @NotNull
050  private static final ResourceTypeDefinition RESOURCE_TYPE_DEFINITION =
051      ResourceTypeDefinition.fromJaxRsResource(
052          AbstractServiceProviderConfigEndpoint.class);
053
054  /**
055   * Service request to retrieve the Service Provider Config.
056   *
057   * @param uriInfo UriInfo of the request.
058   * @return The Service Provider Config.
059   * @throws ScimException if an error occurs.
060   */
061  @GET
062  @Produces({MEDIA_TYPE_SCIM, MediaType.APPLICATION_JSON})
063  @NotNull
064  public GenericScimResource get(@NotNull @Context final UriInfo uriInfo)
065      throws ScimException
066  {
067    ServiceProviderConfigResource serviceProviderConfig =
068        getServiceProviderConfig();
069    ResourcePreparer<GenericScimResource> resourcePreparer =
070        new ResourcePreparer<GenericScimResource>(
071            RESOURCE_TYPE_DEFINITION, uriInfo);
072    GenericScimResource resource =
073        serviceProviderConfig.asGenericScimResource();
074    resourcePreparer.setResourceTypeAndLocation(resource);
075    return resource;
076  }
077
078  /**
079   * Retrieve the current service provider config.
080   *
081   * @return The current service provider config.
082   * @throws ScimException if an error occurs.
083   */
084  @NotNull
085  public abstract ServiceProviderConfigResource getServiceProviderConfig()
086      throws ScimException;
087}