Annotation Type CrossOrigin
A cross-origin policy for one controller or one handler, as Spring's
@CrossOrigin is. On a class it covers every route of the controller; on a
method it replaces the class's for that route.
The route's policy replaces the global cn1.cors.* policy for requests to
that route -- the preflight, the reject of an origin it does not list and the
response headers alike -- rather than being merged with it, so what a route
allows is read off its annotation alone. A preflight for such a route is
answered before the security chain, as the global policy's is, because a
browser sends no credentials with one.
@CrossOrigin(origins = "https://app.example.com", allowCredentials = true)
@GetMapping("/api/me")
public Profile me(@AuthenticationPrincipal User user) { ... }
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether the browser may send cookies and read the response with them.String[]The request headers a preflight may ask for;*allows any.String[]Response headers a script may read beyond the safelisted ones.intHow long, in seconds, a browser may cache the preflight answer.String[]The methods a preflight may ask for; empty allows the route's own.String[]The origins allowed, eachscheme://host[:port], or*for any.String[]The same asorigins(), as Spring spells it on itsvalueattribute.
-
Element Details
-
origins
-
value
-
methods
-
allowedHeaders
-
exposedHeaders
-
allowCredentials
boolean allowCredentialsWhether the browser may send cookies and read the response with them. Needsorigins()to list the origins: a browser refuses*with credentials.- Default:
false
-
maxAge
int maxAgeHow long, in seconds, a browser may cache the preflight answer.- Default:
1800
-