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

de.captaingoldfish.scim.sdk.server.endpoints.Context Maven / Gradle / Ivy

There is a newer version: 1.26.0
Show newest version
// Generated by delombok at Sat Aug 24 10:10:59 CEST 2024
package de.captaingoldfish.scim.sdk.server.endpoints;

import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import de.captaingoldfish.scim.sdk.server.endpoints.authorize.Authorization;
import de.captaingoldfish.scim.sdk.server.endpoints.authorize.DefaultAuthorization;
import de.captaingoldfish.scim.sdk.server.utils.UriInfos;


/**
 * a context object that may be optionally added to the request. If a null instance is used on the
 * {@link ResourceEndpoint#handleRequest(...)} methods the API will instantiate an instance by itself which
 * will then be used
 *
 * @author Pascal Knueppel
 * @since 19.06.2021
 */
public class Context
{

  /**
   * the authorization information of the current request
   */
  private Authorization authorization;

  /**
   * the request infos
   */
  private UriInfos uriInfos;

  /**
   * allows to get the current resource URL reference by passing an id 
*
* e.g. if called on the {@link ResourceHandler} implementation for Groups * *
   *     getResourceReferenceUrl().apply("123456")
   *     => http://localhost:8080/scim/v2/Groups/123456
   * 
*/ private Function resourceReferenceUrl; /** * allows to get cross resource URL of a related resource by passing its name and its id.
*
* e.g. if called on the {@link ResourceHandler} implementation for Groups * *
   *     getExternalResourceReferenceUrl().apply("User", "123456")
   *     => http://localhost:8080/scim/v2/Users/123456
   * 
*/ private BiFunction crossResourceReferenceUrl; /** * allows to access the original request body if necessary */ private Supplier requestBodySupplier; public Context(Authorization authorization) { this.authorization = Optional.ofNullable(authorization).orElse(new DefaultAuthorization()); } /** * creates a direct reference url to the current resource.
*
* e.g. if called on the {@link ResourceHandler} implementation for Users * *
   *     getResourceReferenceUrl("123456")
   *     => http://localhost:8080/scim/v2/Users/123456
   * 
* * @param id the id of the resource. The id is not checked if a resource with this id does exist or not * @return the fully qualified url to the specific resource with the given id */ public String getResourceReferenceUrl(String id) { return resourceReferenceUrl.apply(id); } /** * creates a cross-reference url to another resource.
*
* e.g. if called on the {@link ResourceHandler} implementation for Groups to create a reference to a user * member of the group * *
   *     getExternalResourceReferenceUrl("123456", "User")
   *     => http://localhost:8080/scim/v2/Users/123456
   * 
* * @param id the id of the resource. The id is not checked if a resource with this id does exist or not * @return the fully qualified url to the specific resource with the given id or an empty if no resource with * the given name was registered */ public Optional getCrossResourceReferenceUrl(String id, String resourceName) { return Optional.ofNullable(crossResourceReferenceUrl.apply(id, resourceName)); } /** * will retrieve the original request body before it was parsed and modified */ public String getRequestBody() { return requestBodySupplier.get(); } /** * the authorization information of the current request */ @java.lang.SuppressWarnings("all") @lombok.Generated public Authorization getAuthorization() { return this.authorization; } /** * the request infos */ @java.lang.SuppressWarnings("all") @lombok.Generated public UriInfos getUriInfos() { return this.uriInfos; } /** * the request infos */ @java.lang.SuppressWarnings("all") @lombok.Generated protected void setUriInfos(final UriInfos uriInfos) { this.uriInfos = uriInfos; } /** * allows to get the current resource URL reference by passing an id
*
* e.g. if called on the {@link ResourceHandler} implementation for Groups * *
   *     getResourceReferenceUrl().apply("123456")
   *     => http://localhost:8080/scim/v2/Groups/123456
   * 
*/ @java.lang.SuppressWarnings("all") @lombok.Generated protected void setResourceReferenceUrl(final Function resourceReferenceUrl) { this.resourceReferenceUrl = resourceReferenceUrl; } /** * allows to get cross resource URL of a related resource by passing its name and its id.
*
* e.g. if called on the {@link ResourceHandler} implementation for Groups * *
   *     getExternalResourceReferenceUrl().apply("User", "123456")
   *     => http://localhost:8080/scim/v2/Users/123456
   * 
*/ @java.lang.SuppressWarnings("all") @lombok.Generated protected void setCrossResourceReferenceUrl(final BiFunction crossResourceReferenceUrl) { this.crossResourceReferenceUrl = crossResourceReferenceUrl; } /** * allows to access the original request body if necessary */ @java.lang.SuppressWarnings("all") @lombok.Generated protected void setRequestBodySupplier(final Supplier requestBodySupplier) { this.requestBodySupplier = requestBodySupplier; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy