Package org.forgerock.http.filter.cors
Class CorsPolicy.Builder
- java.lang.Object
-
- org.forgerock.http.filter.cors.CorsPolicy.Builder
-
- Enclosing class:
- CorsPolicy
public static class CorsPolicy.Builder extends Object
Builder forCorsPolicy
instances.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CorsPolicy.Builder
acceptedOrigin(String acceptedOrigin)
Adds an accepted origin to this configuration (case insensitive).CorsPolicy.Builder
acceptHeaders(Predicate<Set<String>> predicate)
Will accept the set of headers accepted by the givenpredicate
.CorsPolicy.Builder
acceptMethods(Predicate<String> predicate)
Will accept any method accepted by the givenpredicate
.CorsPolicy.Builder
acceptOrigin(Predicate<String> predicate)
This configuration accepts whatever origin is accepted by the given predicate.CorsPolicy.Builder
allowCredentials(boolean allowCredentials)
Sets totrue
to inform the CORS client that credentials are allowed.static <T> Predicate<T>
any()
Accepts any input value.static Predicate<String>
anyOf(String... values)
Accepts String that are contained within the given set (case sensitive).CorsPolicy
build()
Returns a newCorsPolicy
immutable instance.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 ofacceptedValues
.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 ofacceptedValues
.CorsPolicy.Builder
exposedHeader(String exposedHeader)
Adds an exposed header name to this configuration.CorsPolicy.Builder
maxAge(Duration maxAge)
Sets a maximum age for user-agent to cache for valid pre-flight responses.static <T> Predicate<T>
none()
Rejects any input value.
-
-
-
Method Detail
-
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 ofacceptedValues
.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(Set)
-
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 ofacceptedValues
.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 givenpredicate
. 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 givenpredicate
. 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 totrue
to inform the CORS client that credentials are allowed.- Parameters:
allowCredentials
- are credentials allowed- Returns:
- this builder
-
build
public CorsPolicy build()
Returns a newCorsPolicy
immutable instance.- Returns:
- a new
CorsPolicy
immutable instance.
-
-