All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.captaingoldfish.scim.sdk.client.ScimRequestBuilder Maven / Gradle / Ivy

There is a newer version: 1.26.0
Show newest version
// Generated by delombok at Sat Oct 07 17:30:34 CEST 2023
package de.captaingoldfish.scim.sdk.client;

import de.captaingoldfish.scim.sdk.client.builder.BulkBuilder;
import de.captaingoldfish.scim.sdk.client.builder.CreateBuilder;
import de.captaingoldfish.scim.sdk.client.builder.DeleteBuilder;
import de.captaingoldfish.scim.sdk.client.builder.GetBuilder;
import de.captaingoldfish.scim.sdk.client.builder.ListBuilder;
import de.captaingoldfish.scim.sdk.client.builder.PatchBuilder;
import de.captaingoldfish.scim.sdk.client.builder.UpdateBuilder;
import de.captaingoldfish.scim.sdk.client.http.ScimHttpClient;
import de.captaingoldfish.scim.sdk.client.response.ServerResponse;
import de.captaingoldfish.scim.sdk.common.constants.EndpointPaths;
import de.captaingoldfish.scim.sdk.common.resources.ResourceNode;
import de.captaingoldfish.scim.sdk.common.resources.ServiceProvider;


/**
 * author Pascal Knueppel 
* created at: 07.12.2019 - 23:08
*
* this class can be used to build any type of request for SCIM */ public class ScimRequestBuilder implements AutoCloseable { @java.lang.SuppressWarnings("all") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ScimRequestBuilder.class); /** * must contain the baseUrl to the scim service */ private final String baseUrl; /** * the configuration for the client that should be used */ private final ScimClientConfig scimClientConfig; // for unit tests /** * a convenience implementation that wraps the apache http client */ private ScimHttpClient scimHttpClient; /** * the service provider configuration from the SCIM provider application */ private ServiceProvider serviceProvider; public ScimRequestBuilder(String baseUrl, ScimClientConfig scimClientConfig) { this.baseUrl = baseUrl.replaceFirst("/$", ""); this.scimClientConfig = scimClientConfig; this.scimHttpClient = new ScimHttpClient(scimClientConfig); } /** * tries to load the service provider configuration from the SCIM provider, but it will not cause any aborts * if loading of the configuration does fail */ public ServiceProvider loadServiceProviderConfiguration() { if (serviceProvider != null) { return serviceProvider; } try { log.info("Trying to load service provider configuration from SCIM provider"); ServerResponse response = this.get(ServiceProvider.class, EndpointPaths.SERVICE_PROVIDER_CONFIG) .sendRequest(); boolean isError = !response.isSuccess(); if (isError) { log.warn("Failed to load service provider configuration: status: \'{}\' responseBody: \'{}\'", response.getHttpStatus(), response.getResponseBody()); } serviceProvider = response.getResource(); return serviceProvider; } catch (Exception ex) { log.warn("Failed to load service provider configuration from SCIM provider", ex); return null; } } /** * builds a create builder class based on the given type * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @return a create-request builder for the given resource type */ public CreateBuilder create(Class type, String endpoint) { return new CreateBuilder<>(baseUrl, endpoint, type, scimHttpClient); } /** * builds a create builder class based on the given type * * @param fullyQualifiedUrl if the builder should not build the url on the baseUrl but use another fully * qualified url * @param type the type that should be created * @return a create-request builder for the given resource type */ public CreateBuilder create(String fullyQualifiedUrl, Class type) { return new CreateBuilder<>(fullyQualifiedUrl, type, scimHttpClient); } /** * builds a get builder class based on the given type * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @param resourceId the id of the resource that should be returned (may be null if the endpoint path already * contains the id) * @return a get-request builder for the given resource type */ public GetBuilder get(Class type, String endpoint, String resourceId) { return new GetBuilder<>(baseUrl, endpoint, resourceId, type, scimHttpClient); } /** * builds a get builder that is used to access a singleton resource from the provider * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @return a get-request builder for the given resource type */ public GetBuilder get(Class type, String endpoint) { return new GetBuilder<>(baseUrl, endpoint, null, type, scimHttpClient); } /** * builds a get builder class based on the given type * * @param fullyQualifiedUrl if the builder should not build the url on the baseUrl but use another fully * qualified url * @param type the type that should be created * @return a get-request builder for the given resource type */ public GetBuilder get(String fullyQualifiedUrl, Class type) { return new GetBuilder<>(fullyQualifiedUrl, type, scimHttpClient); } /** * builds a delete builder class based on the given type * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @param resourceId the id of the resource that should be returned (may be null if the endpoint path already * contains the id) * @return a delete-request builder for the given resource type */ public DeleteBuilder delete(Class type, String endpoint, String resourceId) { return new DeleteBuilder<>(baseUrl, endpoint, resourceId, type, scimHttpClient); } /** * builds a delete builder class based on the given type used to delete a singleton entry at the provider * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @return a delete-request builder for the given resource type */ public DeleteBuilder delete(Class type, String endpoint) { return new DeleteBuilder<>(baseUrl, endpoint, null, type, scimHttpClient); } /** * builds a delete builder class based on the given type * * @param fullyQualifiedUrl if the builder should not build the url on the baseUrl but use another fully * qualified url * @param type the type that should be created * @return a delete-request builder for the given resource type */ public DeleteBuilder delete(String fullyQualifiedUrl, Class type) { return new DeleteBuilder<>(fullyQualifiedUrl, type, scimHttpClient); } /** * builds an update builder class based on the given type * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @param resourceId the id of the resource that should be returned (may be null if the endpoint path already * contains the id) * @return a update-request builder for the given resource type */ public UpdateBuilder update(Class type, String endpoint, String resourceId) { return new UpdateBuilder<>(baseUrl, endpoint, resourceId, type, scimHttpClient); } /** * builds an update builder class used to update a singleton entry at the provider * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @return a update-request builder for the given resource type */ public UpdateBuilder update(Class type, String endpoint) { return new UpdateBuilder<>(baseUrl, endpoint, null, type, scimHttpClient); } /** * builds an update builder class based on the given type * * @param fullyQualifiedUrl if the builder should not build the url on the baseUrl but use another fully * qualified url * @param type the type that should be created * @return a update-request builder for the given resource type */ public UpdateBuilder update(String fullyQualifiedUrl, Class type) { return new UpdateBuilder<>(fullyQualifiedUrl, type, scimHttpClient); } /** * builds an update builder class based on the given type * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @return a update-request builder for the given resource type */ public ListBuilder list(Class type, String endpoint) { return new ListBuilder<>(baseUrl, endpoint, type, scimHttpClient); } /** * builds an update builder class based on the given type * * @param fullyQualifiedUrl if the builder should not build the url on the baseUrl but use another fully * qualified url * @param type the type that should be created * @return a update-request builder for the given resource type */ public ListBuilder list(String fullyQualifiedUrl, Class type) { return new ListBuilder<>(fullyQualifiedUrl, type, scimHttpClient); } /** * builds an bulk request builder * * @return a bulk-request builder */ public BulkBuilder bulk() { return new BulkBuilder(baseUrl, scimHttpClient, false, this::loadServiceProviderConfiguration); } /** * builds an bulk request builder * * @param fullyQualifiedUrl if the builder should not build the url on the baseUrl but use another fully * qualified url * @return a bulk-request builder */ public BulkBuilder bulk(String fullyQualifiedUrl) { return new BulkBuilder(fullyQualifiedUrl, scimHttpClient, true, this::loadServiceProviderConfiguration); } /** * builds a patch request builder * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @param resourceId the id of the resource that should be returned (may be null if the endpoint path already * contains the id) * @return a patch-request builder */ public PatchBuilder patch(Class type, String endpoint, String resourceId) { return new PatchBuilder<>(baseUrl, endpoint, resourceId, type, scimHttpClient); } /** * builds a patch request builder used to patch a singleton entry at the provider * * @param type the type that should be created * @param endpoint the endpoint path to the resource e.g. "/Users" or "/Groups" * @return a patch-request builder */ public PatchBuilder patch(Class type, String endpoint) { return new PatchBuilder<>(baseUrl, endpoint, null, type, scimHttpClient); } /** * builds a patch request builder * * @param fullyQualifiedUrl if the builder should not build the url on the baseUrl but use another fully * qualified url * @param type the type that should be created * @return a patch-request builder */ public PatchBuilder patch(String fullyQualifiedUrl, Class type) { return new PatchBuilder<>(fullyQualifiedUrl, type, scimHttpClient); } /** * closes the underlying apache http client. If the http client is closed this request builder is still * usable. The next request will simply be executed with a new http client instance */ @Override public void close() { scimHttpClient.close(); } /** * the configuration for the client that should be used */ @java.lang.SuppressWarnings("all") public ScimClientConfig getScimClientConfig() { return this.scimClientConfig; } /** * a convenience implementation that wraps the apache http client */ @java.lang.SuppressWarnings("all") protected ScimHttpClient getScimHttpClient() { return this.scimHttpClient; } /** * the service provider configuration from the SCIM provider application */ @java.lang.SuppressWarnings("all") public ServiceProvider getServiceProvider() { return this.serviceProvider; } /** * the service provider configuration from the SCIM provider application */ @java.lang.SuppressWarnings("all") public void setServiceProvider(final ServiceProvider serviceProvider) { this.serviceProvider = serviceProvider; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy