001/*
002 * Copyright 2011-2013 UnboundID Corp.
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.scim.sdk;
019
020import com.unboundid.scim.data.AuthenticationScheme;
021import com.unboundid.scim.data.BaseResource;
022import com.unboundid.scim.schema.ResourceDescriptor;
023
024import java.util.Collection;
025import java.util.Collections;
026
027/**
028 * This class defines an API for a backend that can be plugged into the SCIM
029 * server.
030 */
031public abstract class SCIMBackend
032{
033  /**
034   * The mutable configuration settings for the backend.
035   */
036  private final SCIMBackendConfig config = new SCIMBackendConfig();
037
038
039
040  /**
041   * Performs any cleanup which may be necessary when this backend is to be
042   * taken out of service.
043   */
044  public abstract void finalizeBackend();
045
046
047
048  /**
049   * Retrieve the mutable configuration settings for the backend.
050   * @return  The mutable configuration settings for the backend.
051   */
052  public SCIMBackendConfig getConfig()
053  {
054    return config;
055  }
056
057
058
059  /**
060   * Perform basic authentication using the provided information.
061   *
062   * @param userID    The user ID to be authenticated.
063   * @param password  The user password to be verified.
064   *
065   * @return {@code true} if the provided user ID and password are valid.
066   */
067  public abstract boolean authenticate(final String userID,
068                                       final String password);
069
070
071
072  /**
073   * Retrieve all or selected attributes of a resource.
074   *
075   * @param request  The Get Resource request.
076   *
077   * @return  The response to the request.
078   *
079   * @throws SCIMException if an error occurs while processing the request.
080   */
081  public abstract BaseResource getResource(
082      final GetResourceRequest request) throws SCIMException;
083
084
085
086  /**
087   * Retrieve selected resources.
088   *
089   * @param request  The Get Resources request.
090   *
091   * @return  The response to the request.
092   *
093   * @throws SCIMException if an error occurs while processing the request.
094   */
095  public abstract Resources getResources(
096      final GetResourcesRequest request) throws SCIMException;
097
098
099
100  /**
101   * Create a new resource.
102   *
103   *
104   * @param request  The Post Resource request.
105   *
106   * @return  The response to the request.
107   *
108   * @throws SCIMException if an error occurs while processing the request.
109   */
110  public abstract BaseResource postResource(
111      final PostResourceRequest request) throws SCIMException;
112
113
114
115  /**
116   * Delete a specific resource.
117   *
118   *
119   * @param request  The Delete Resource request.
120   *
121   * @throws SCIMException if an error occurs while processing the request.
122   */
123  public abstract void deleteResource(
124      final DeleteResourceRequest request) throws SCIMException;
125
126
127
128  /**
129   * Replace the contents of an existing resource.
130   *
131   *
132   * @param request  The Put Resource request.
133   *
134   * @return  The response to the request.
135   *
136   * @throws SCIMException if an error occurs while processing the request.
137   */
138  public abstract BaseResource putResource(
139      final PutResourceRequest request) throws SCIMException;
140
141
142
143  /**
144   * Update the contents of an existing resource with attributes specified.
145   *
146   *
147   * @param request  The Patch Resource request.
148   *
149   * @return  The response to the request.
150   *
151   * @throws SCIMException if an error occurs while processing the request.
152   */
153  public abstract BaseResource patchResource(
154          final PatchResourceRequest request) throws SCIMException;
155
156
157
158  /**
159   * Retrieves whether this backend supports sorting.
160   *
161   * @return {@code true} if sorting is supported or {@code false} otherwise.
162   */
163  public boolean supportsSorting()
164  {
165    return true;
166  }
167
168
169
170  /**
171   * Retrieves the authentication schemes supported by this backend.
172   *
173   * @return The authentication schemes supported by this backend.
174   */
175  public Collection<AuthenticationScheme> getSupportedAuthenticationSchemes()
176  {
177    return Collections.singleton(AuthenticationScheme.createBasic(true));
178  }
179
180
181
182  /**
183   * Retrieve the resource descriptors served by this backend.
184   *
185   * @return  The resource descriptors served by this backend.
186   */
187  public abstract Collection<ResourceDescriptor> getResourceDescriptors();
188
189
190
191  /**
192   * Retrieve the resource descriptor for the specified endpoint.
193   *
194   * @param endpoint The endpoint of the resource descriptor to retrieve.
195   *
196   * @return The resource descriptor for the specified endpoint or {@code null}
197   *         if no resource descriptors with the specified endpoint was found.
198   */
199  public ResourceDescriptor getResourceDescriptor(final String endpoint)
200  {
201    for(ResourceDescriptor resourceDescriptor : getResourceDescriptors())
202    {
203      if(resourceDescriptor.getEndpoint().equals(endpoint))
204      {
205        return resourceDescriptor;
206      }
207    }
208
209    return null;
210  }
211}