@Target(value={TYPE,METHOD}) @Retention(value=RUNTIME) @Documented public @interface CrossOrigin
HandlerMapping
is configured.
Both Spring Web MVC and Spring WebFlux support this annotation through the
RequestMappingHandlerMapping
in their respective modules. The values
from each type and method level pair of annotations are added to a
CorsConfiguration
and then default values are applied via
CorsConfiguration.applyPermitDefaultValues()
.
The rules for combining global and local configuration are generally
additive -- e.g. all global and all local origins. For those attributes
where only a single value can be accepted such as allowCredentials
and maxAge
, the local overrides the global value.
See CorsConfiguration.combine(CorsConfiguration)
for more details.
Modifier and Type | Fields and Description |
---|---|
static boolean |
DEFAULT_ALLOW_CREDENTIALS
Deprecated.
as of Spring 5.0, in favor of
CorsConfiguration.applyPermitDefaultValues() |
static String[] |
DEFAULT_ALLOWED_HEADERS
Deprecated.
as of Spring 5.0, in favor of
CorsConfiguration.applyPermitDefaultValues() |
static long |
DEFAULT_MAX_AGE
Deprecated.
as of Spring 5.0, in favor of
CorsConfiguration.applyPermitDefaultValues() |
static String[] |
DEFAULT_ORIGINS
Deprecated.
as of Spring 5.0, in favor of
CorsConfiguration.applyPermitDefaultValues() |
Modifier and Type | Optional Element and Description |
---|---|
String |
allowCredentials
Whether the browser should send credentials, such as cookies along with
cross domain requests, to the annotated endpoint.
|
String[] |
allowedHeaders
The list of request headers that are permitted in actual requests,
possibly
"*" to allow all headers. |
String |
allowPrivateNetwork
Whether private network access is supported.
|
String[] |
exposedHeaders
The List of response headers that the user-agent will allow the client
to access on an actual response, possibly
"*" to expose all headers. |
long |
maxAge
The maximum age (in seconds) of the cache duration for preflight responses.
|
RequestMethod[] |
methods
The list of supported HTTP request methods.
|
String[] |
originPatterns
Alternative to
origins() that supports more flexible origin
patterns. |
String[] |
origins
A list of origins for which cross-origin requests are allowed.
|
String[] |
value
Alias for
origins() . |
@Deprecated public static final String[] DEFAULT_ORIGINS
CorsConfiguration.applyPermitDefaultValues()
@Deprecated public static final String[] DEFAULT_ALLOWED_HEADERS
CorsConfiguration.applyPermitDefaultValues()
@Deprecated public static final boolean DEFAULT_ALLOW_CREDENTIALS
CorsConfiguration.applyPermitDefaultValues()
@Deprecated public static final long DEFAULT_MAX_AGE
CorsConfiguration.applyPermitDefaultValues()
@AliasFor(value="value") public abstract String[] origins
CorsConfiguration.setAllowedOrigins(List)
for details.
By default all origins are allowed unless originPatterns()
is
also set in which case originPatterns
is used instead.
public abstract String[] originPatterns
origins()
that supports more flexible origin
patterns. Please, see CorsConfiguration.setAllowedOriginPatterns(List)
for details.
By default this is not set.
public abstract String[] allowedHeaders
"*"
to allow all headers. Please, see
CorsConfiguration.setAllowedHeaders(List)
for details.
By default all requested headers are allowed.
public abstract String[] exposedHeaders
"*"
to expose all headers.
Please, see CorsConfiguration.setExposedHeaders(List)
for details.
By default no headers are listed as exposed.
public abstract RequestMethod[] methods
CorsConfiguration.setAllowedMethods(List)
for details.
By default the supported methods are the same as the ones to which a controller method is mapped.
public abstract String allowCredentials
CorsConfiguration.setAllowCredentials(Boolean)
for details.
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 in which case the
Access-Control-Allow-Credentials
header is also not set and
credentials are therefore not allowed.
public abstract String allowPrivateNetwork
CorsConfiguration.setAllowPrivateNetwork(Boolean)
for details.
By default this is not set (i.e. private network access is not supported).
public abstract long maxAge
This property controls the value of the Access-Control-Max-Age
response header of preflight requests.
Setting this to a reasonable value can reduce the number of preflight request/response interactions required by the browser. A negative value means undefined.
By default this is set to 1800
seconds (30 minutes).