Class CorsPolicy.Builder

java.lang.Object
org.forgerock.http.filter.cors.CorsPolicy.Builder
Enclosing class:
CorsPolicy

public static class CorsPolicy.Builder extends Object
Builder for CorsPolicy instances.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • any

      public static <T> Predicate<T> any()
      Accepts any input value.
      Type Parameters:
      T - input type
      Returns:
      a new predicate that always returns true
    • none

      public static <T> Predicate<T> none()
      Rejects any input value.
      Type Parameters:
      T - input type
      Returns:
      a new predicate that always returns false
    • anyOf

      public static Predicate<String> anyOf(String... values)
      Accepts String that are contained within the given set (case sensitive).
      Parameters:
      values - allowed values
      Returns:
      a predicate that accepts Strings that are contained within the given set (case sensitive)
    • containedInIgnoringCase

      public static Predicate<Set<String>> containedInIgnoringCase(String... acceptedValues)
      Accepts a set of values if all values from that set are contained (case insensitively) in the given set of acceptedValues.

      If a single tested value is not within that set, this predicate returns false.

      Parameters:
      acceptedValues - all accepted values
      Returns:
      a predicate that accepts a set of values if all values from that set are contained in the given set of acceptedValues (case insensitively).
      See Also:
    • containedIn

      public static Predicate<Set<String>> containedIn(Set<String> acceptedValues)
      Accepts a set of values if all values from that set are contained in the given set of acceptedValues.

      If a single tested value is not within that set, this predicate returns false.

      Parameters:
      acceptedValues - set of accepted values
      Returns:
      a predicate that accepts a set of values if all values from that set are contained in the given set of acceptedValues.
    • acceptedOrigin

      public CorsPolicy.Builder acceptedOrigin(String acceptedOrigin)
      Adds an accepted origin to this configuration (case insensitive).
      Parameters:
      acceptedOrigin - URL of the origin to add
      Returns:
      this builder
    • acceptOrigin

      public CorsPolicy.Builder acceptOrigin(Predicate<String> predicate)
      This configuration accepts whatever origin is accepted by the given predicate.
      Parameters:
      predicate - Additional origin predicate (Or-ed)
      Returns:
      this builder
    • acceptMethods

      public CorsPolicy.Builder acceptMethods(Predicate<String> predicate)
      Will accept any method accepted by the given predicate. Removes any prior accepted methods from this configuration.
      Parameters:
      predicate - predicate for matching requested method name
      Returns:
      this builder
    • acceptHeaders

      public CorsPolicy.Builder acceptHeaders(Predicate<Set<String>> predicate)
      Will accept the set of headers accepted by the given predicate. Removes any prior accepted headers from this configuration.
      Parameters:
      predicate - predicate for matching requested headers
      Returns:
      this builder
    • exposedHeader

      public CorsPolicy.Builder exposedHeader(String exposedHeader)
      Adds an exposed header name to this configuration.
      Parameters:
      exposedHeader - name of the header to expose
      Returns:
      this builder
    • maxAge

      public CorsPolicy.Builder maxAge(Duration maxAge)
      Sets a maximum age for user-agent to cache for valid pre-flight responses.
      Parameters:
      maxAge - maximum age for user-agent to cache for valid pre-flight responses (not negative, can be null)
      Returns:
      this builder
    • allowCredentials

      public CorsPolicy.Builder allowCredentials(boolean allowCredentials)
      Sets to true to inform the CORS client that credentials are allowed.
      Parameters:
      allowCredentials - are credentials allowed
      Returns:
      this builder
    • build

      public CorsPolicy build()
      Returns a new CorsPolicy immutable instance.
      Returns:
      a new CorsPolicy immutable instance.