By default a newly created CorsConfiguration does not permit any
cross-origin requests and must be configured explicitly to indicate what
should be allowed. Use applyPermitDefaultValues() to flip the
initialization model to start with open defaults that permit all cross-origin
requests for GET, HEAD, and POST requests.
| Modifier and Type | Class and Description |
|---|---|
| private static class | CorsConfiguration.
Contains both the user-declared pattern (e.g. "https://*.domain.com") and
the regex |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | ALL
Wildcard representing all origins, methods, or headers. |
| private static final List | |
| private static final CorsConfiguration. | |
| private static final List | |
| private Boolean | |
| private List | |
| private List | |
| private List | |
| private List | |
| private Boolean | |
| private static final List | |
| private static final List | |
| private static final List | |
| private List | |
| private Long | |
| private List |
| Access | Constructor and Description |
|---|---|
| public | CorsConfiguration()
Construct a new |
| public | CorsConfiguration(CorsConfiguration other)
Construct a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | addAllowedHeader(String allowedHeader)
Variant of |
| public void | addAllowedMethod(HttpMethod method)
Variant of |
| public void | addAllowedMethod(String method)
Variant of |
| public void | |
| public void | addAllowedOriginPattern(String originPattern)
Variant of |
| public void | addExposedHeader(String exposedHeader)
Variant of |
| public CorsConfiguration | applyPermitDefaultValues()
By default |
| public List | Returns: the list of allowed headers to list in the response of a pre-flight request, ornull if none of the supplied request headers is allowedthe request headers to check requestHeaders)Check the supplied request headers (or the headers listed in the
|
| public List | Returns: the list of HTTP methods to list in the response of a pre-flight request, ornull if the supplied requestMethod is not allowedthe HTTP request method to check requestMethod)Check the HTTP request method (or the method from the
|
| public String | Returns: the origin to use for the response, ornull which
means the request origin is not allowedthe origin to check origin)Check the origin of the request against the configured allowed origins. |
| public CorsConfiguration | Returns: the combinedCorsConfiguration, or this
configuration if the supplied configuration is nullCombine the non-null properties of the supplied
|
| private List | |
| private List | combinePatterns(List<CorsConfiguration.
|
| public Boolean | |
| public List | |
| public List | getAllowedMethods()
Return the allowed HTTP methods, or |
| public List | |
| public List | |
| public Boolean | |
| public List | |
| public Long | |
| private static void | |
| public void | |
| public void | setAllowedHeaders(List<String> allowedHeaders)
Set the list of headers that a pre-flight request can list as allowed for use during an actual request. |
| public void | setAllowedMethods(List<String> allowedMethods)
Set the HTTP methods to allow, e.g. |
| public CorsConfiguration | setAllowedOriginPatterns(List<String> allowedOriginPatterns)
Alternative to |
| public void | setAllowedOrigins(List<String> origins)
A list of origins for which cross-origin requests are allowed where each value may be one of the following:
|
| public void | setAllowPrivateNetwork(Boolean allowPrivateNetwork)
Whether private network access is supported for user-agents restricting such access by default. |
| public void | setExposedHeaders(List<String> exposedHeaders)
Set the list of response headers that an actual response might have and can be exposed to the client. |
| public void | |
| public void | |
| private String | |
| public void | validateAllowCredentials()
Validate that when |
| public void | validateAllowPrivateNetwork()
Validate that when |
| ALL | back to summary |
|---|---|
| public static final String ALL Wildcard representing all origins, methods, or headers. | |
| ALL_LIST | back to summary |
|---|---|
| private static final List<String> ALL_LIST | |
| ALL_PATTERN | back to summary |
|---|---|
| private static final CorsConfiguration. | |
| ALL_PATTERN_LIST | back to summary |
|---|---|
| private static final List<CorsConfiguration. | |
| allowCredentials | back to summary |
|---|---|
| private Boolean allowCredentials
| |
| allowedHeaders | back to summary |
|---|---|
| private List<String> allowedHeaders
| |
| allowedMethods | back to summary |
|---|---|
| private List<String> allowedMethods
| |
| allowedOriginPatterns | back to summary |
|---|---|
| private List<CorsConfiguration. | |
| allowedOrigins | back to summary |
|---|---|
| private List<String> allowedOrigins
| |
| allowPrivateNetwork | back to summary |
|---|---|
| private Boolean allowPrivateNetwork
| |
| DEFAULT_METHODS | back to summary |
|---|---|
| private static final List<HttpMethod> DEFAULT_METHODS | |
| DEFAULT_PERMIT_ALL | back to summary |
|---|---|
| private static final List<String> DEFAULT_PERMIT_ALL | |
| DEFAULT_PERMIT_METHODS | back to summary |
|---|---|
| private static final List<String> DEFAULT_PERMIT_METHODS | |
| exposedHeaders | back to summary |
|---|---|
| private List<String> exposedHeaders
| |
| maxAge | back to summary |
|---|---|
| private Long maxAge
| |
| resolvedMethods | back to summary |
|---|---|
| private List<HttpMethod> resolvedMethods
| |
| CorsConfiguration | back to summary |
|---|---|
| public CorsConfiguration() Construct a new
| |
| CorsConfiguration | back to summary |
|---|---|
| public CorsConfiguration(CorsConfiguration other) Construct a new | |
| addAllowedHeader | back to summary |
|---|---|
| public void addAllowedHeader(String allowedHeader) Variant of | |
| addAllowedMethod | back to summary |
|---|---|
| public void addAllowedMethod(HttpMethod method) Variant of | |
| addAllowedMethod | back to summary |
|---|---|
| public void addAllowedMethod(String method) Variant of | |
| addAllowedOrigin | back to summary |
|---|---|
| public void addAllowedOrigin(String origin) Variant of | |
| addAllowedOriginPattern | back to summary |
|---|---|
| public void addAllowedOriginPattern(String originPattern) Variant of
| |
| addExposedHeader | back to summary |
|---|---|
| public void addExposedHeader(String exposedHeader) Variant of | |
| applyPermitDefaultValues | back to summary |
|---|---|
| public CorsConfiguration applyPermitDefaultValues() By default The following defaults are applied for values that are not set:
| |
| checkHeaders | back to summary |
|---|---|
| public List Check the supplied request headers (or the headers listed in the
| |
| checkHttpMethod | back to summary |
|---|---|
| public List Check the HTTP request method (or the method from the
| |
| checkOrigin | back to summary |
|---|---|
| public String checkOrigin(String origin) Check the origin of the request against the configured allowed origins. | |
| combine | back to summary |
|---|---|
| public CorsConfiguration combine(CorsConfiguration other) Combine the non-null properties of the supplied
When combining single values like Combining lists like
| |
| combine | back to summary |
|---|---|
| private List | |
| combinePatterns | back to summary |
|---|---|
| private List | |
| getAllowCredentials | back to summary |
|---|---|
| public Boolean getAllowCredentials() Return the configured
| |
| getAllowedHeaders | back to summary |
|---|---|
| public List Return the allowed actual request headers, or
| |
| getAllowedMethods | back to summary |
|---|---|
| public List Return the allowed HTTP methods, or
| |
| getAllowedOriginPatterns | back to summary |
|---|---|
| public List Return the configured origins patterns to allow, or
| |
| getAllowedOrigins | back to summary |
|---|---|
| public List Return the configured origins to allow, or
| |
| getAllowPrivateNetwork | back to summary |
|---|---|
| public Boolean getAllowPrivateNetwork() Return the configured
| |
| getExposedHeaders | back to summary |
|---|---|
| public List Return the configured response headers to expose, or
| |
| getMaxAge | back to summary |
|---|---|
| public Long getMaxAge() Return the configured
| |
| parseCommaDelimitedOrigin | back to summary |
|---|---|
| private static void parseCommaDelimitedOrigin(String rawValue, Consumer<String> valueConsumer) | |
| setAllowCredentials | back to summary |
|---|---|
| public void setAllowCredentials(Boolean allowCredentials) Whether user credentials are supported. Setting this property has an impact on how Note Be aware that this option establishes a high level of trust with the configured domains and also increases the surface attack of the web application by exposing sensitive user-specific information such as cookies and CSRF tokens. By default this is not set (i.e. user credentials are not supported). | |
| setAllowedHeaders | back to summary |
|---|---|
| public void setAllowedHeaders(List<String> allowedHeaders) Set the list of headers that a pre-flight request can list as allowed
for use during an actual request. The special value
A header name is not required to be listed if it is one of:
By default this is not set. | |
| setAllowedMethods | back to summary |
|---|---|
| public void setAllowedMethods(List<String> allowedMethods) Set the HTTP methods to allow, e.g.
If not set, only By default this is not set. Note CORS checks use values from "Forwarded"
(RFC 7239),
"X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers,
if present, in order to reflect the client-originated address.
Consider using the | |
| setAllowedOriginPatterns | back to summary |
|---|---|
| public CorsConfiguration setAllowedOriginPatterns(List<String> allowedOriginPatterns) Alternative to
In contrast to By default this is not set.
| |
| setAllowedOrigins | back to summary |
|---|---|
| public void setAllowedOrigins(List<String> origins) A list of origins for which cross-origin requests are allowed where each value may be one of the following:
For matched pre-flight and actual requests the
By default this is not set which means that no origins are allowed.
However, an instance of this class is often initialized further, e.g. for
| |
| setAllowPrivateNetwork | back to summary |
|---|---|
| public void setAllowPrivateNetwork(Boolean allowPrivateNetwork) Whether private network access is supported for user-agents restricting such access by default. Private network requests are requests whose target server's IP address is more private than that from which the request initiator was fetched. For example, a request from a public website (https://example.com) to a private website (https://router.local), or a request from a private website to localhost. Setting this property has an impact on how By default this is not set (i.e. private network access is not supported).
| |
| setExposedHeaders | back to summary |
|---|---|
| public void setExposedHeaders(List<String> exposedHeaders) Set the list of response headers that an actual response might have
and can be exposed to the client. The special value
A header name is not required to be listed if it is one of:
By default this is not set. | |
| setMaxAge | back to summary |
|---|---|
| public void setMaxAge(Duration maxAge) Configure how long, as a duration, the response from a pre-flight request can be cached by clients.
| |
| setMaxAge | back to summary |
|---|---|
| public void setMaxAge(Long maxAge) Configure how long, in seconds, the response from a pre-flight request can be cached by clients. By default this is not set. | |
| trimTrailingSlash | back to summary |
|---|---|
| private String trimTrailingSlash(String origin) | |
| validateAllowCredentials | back to summary |
|---|---|
| public void validateAllowCredentials() Validate that when
| |
| validateAllowPrivateNetwork | back to summary |
|---|---|
| public void validateAllowPrivateNetwork() Validate that when
| |
Pattern derived from it.
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private final Pattern | |
| private static final Pattern |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. other)Overrides java. Indicates whether some other object is "equal to" this one. |
| public String | |
| public Pattern | |
| public int | |
| private static Pattern | |
| public String |
| declaredPattern | back to summary |
|---|---|
| private final String declaredPattern | |
| pattern | back to summary |
|---|---|
| private final Pattern pattern | |
| PORTS_PATTERN | back to summary |
|---|---|
| private static final Pattern PORTS_PATTERN | |
| OriginPattern | back to summary |
|---|---|
| pack-priv OriginPattern(String declaredPattern) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| getDeclaredPattern | back to summary |
|---|---|
| public String getDeclaredPattern() | |
| getPattern | back to summary |
|---|---|
| public Pattern getPattern() | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| initPattern | back to summary |
|---|---|
| private static Pattern initPattern(String patternValue) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |