Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

@Retention(CLASS) @Target({TYPE, METHOD})

public @interface 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) { ... }

Methods

public abstract String[] origins() default {"*"}The origins allowed, each scheme://host[:port], or * for any.
public abstract String[] value() default {}The same as origins, as Spring spells it on its value attribute.
public abstract String[] methods() default {}The methods a preflight may ask for; empty allows the route’s own.
public abstract String[] allowedHeaders() default {"*"}The request headers a preflight may ask for; * allows any.
public abstract String[] exposedHeaders() default {}Response headers a script may read beyond the safelisted ones.
public abstract boolean allowCredentials() default falseWhether the browser may send cookies and read the response with them.
public abstract int maxAge() default 1800How long, in seconds, a browser may cache the preflight answer.

Method details

origins

public abstract String[] origins() default {"*"}
The origins allowed, each scheme://host[:port], or * for any.

value

public abstract String[] value() default {}
The same as origins, as Spring spells it on its value attribute.

methods

public abstract String[] methods() default {}
The methods a preflight may ask for; empty allows the route’s own.

allowedHeaders

public abstract String[] allowedHeaders() default {"*"}
The request headers a preflight may ask for; * allows any.

exposedHeaders

public abstract String[] exposedHeaders() default {}
Response headers a script may read beyond the safelisted ones.

allowCredentials

public abstract boolean allowCredentials() default false
Whether the browser may send cookies and read the response with them. Needs origins to list the origins: a browser refuses * with credentials.

maxAge

public abstract int maxAge() default 1800
How long, in seconds, a browser may cache the preflight answer.