001/* 002 * Copyright 2011-2016 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 * Retrieve all or selected attributes of a resource. 061 * 062 * @param request The Get Resource request. 063 * 064 * @return The response to the request. 065 * 066 * @throws SCIMException if an error occurs while processing the request. 067 */ 068 public abstract BaseResource getResource( 069 final GetResourceRequest request) throws SCIMException; 070 071 072 073 /** 074 * Retrieve selected resources. 075 * 076 * @param request The Get Resources request. 077 * 078 * @return The response to the request. 079 * 080 * @throws SCIMException if an error occurs while processing the request. 081 */ 082 public abstract Resources getResources( 083 final GetResourcesRequest request) throws SCIMException; 084 085 086 087 /** 088 * Create a new resource. 089 * 090 * 091 * @param request The Post Resource request. 092 * 093 * @return The response to the request. 094 * 095 * @throws SCIMException if an error occurs while processing the request. 096 */ 097 public abstract BaseResource postResource( 098 final PostResourceRequest request) throws SCIMException; 099 100 101 102 /** 103 * Delete a specific resource. 104 * 105 * 106 * @param request The Delete Resource request. 107 * 108 * @throws SCIMException if an error occurs while processing the request. 109 */ 110 public abstract void deleteResource( 111 final DeleteResourceRequest request) throws SCIMException; 112 113 114 115 /** 116 * Replace the contents of an existing resource. 117 * 118 * 119 * @param request The Put Resource request. 120 * 121 * @return The response to the request. 122 * 123 * @throws SCIMException if an error occurs while processing the request. 124 */ 125 public abstract BaseResource putResource( 126 final PutResourceRequest request) throws SCIMException; 127 128 129 130 /** 131 * Update the contents of an existing resource with attributes specified. 132 * 133 * 134 * @param request The Patch Resource request. 135 * 136 * @return The response to the request. 137 * 138 * @throws SCIMException if an error occurs while processing the request. 139 */ 140 public abstract BaseResource patchResource( 141 final PatchResourceRequest request) throws SCIMException; 142 143 144 /** 145 * Retrieves whether this backend supports sorting. 146 * 147 * @return {@code true} if sorting is supported or {@code false} otherwise. 148 */ 149 public boolean supportsSorting() 150 { 151 return true; 152 } 153 154 155 /** 156 * Retrieves whether this backends supports resource versioning. 157 * 158 * @return {@code true} if versioning is supported or {@code false} otherwise. 159 */ 160 public boolean supportsVersioning() 161 { 162 return false; 163 } 164 165 166 167 /** 168 * Retrieves the authentication schemes supported by this backend. 169 * 170 * @return The authentication schemes supported by this backend. 171 */ 172 public Collection<AuthenticationScheme> getSupportedAuthenticationSchemes() 173 { 174 return Collections.singleton(AuthenticationScheme.createBasic(true)); 175 } 176 177 178 179 /** 180 * Retrieve the resource descriptors served by this backend. 181 * 182 * @return The resource descriptors served by this backend. 183 */ 184 public abstract Collection<ResourceDescriptor> getResourceDescriptors(); 185 186 187 188 /** 189 * Retrieve the resource descriptor for the specified endpoint. 190 * 191 * @param endpoint The endpoint of the resource descriptor to retrieve. 192 * 193 * @return The resource descriptor for the specified endpoint or {@code null} 194 * if no resource descriptors with the specified endpoint was found. 195 */ 196 public ResourceDescriptor getResourceDescriptor(final String endpoint) 197 { 198 for(ResourceDescriptor resourceDescriptor : getResourceDescriptors()) 199 { 200 if(resourceDescriptor.getEndpoint().equals(endpoint)) 201 { 202 return resourceDescriptor; 203 } 204 } 205 206 return null; 207 } 208}