Implementation of the CORS protocol defined by the fetch standard.
This Handler should be present in the Handler tree to prevent
cross site request forgery attacks.
A typical case is a web page containing a script downloaded from the origin server at
domain.com, where the script makes requests to the cross server at cross.domain.com.
The cross server at cross.domain.com has the CrossOriginHandler installed and will
see requests such as:
GET / HTTP/1.1
Host: cross.domain.com
Origin: http://domain.com
The cross server at cross.domain.com must decide whether these cross-origin requests
are allowed or not, and it may easily do so by configuring the CrossOriginHandler,
for example configuring the allowed origins to contain only
the origin server with origin http://domain.com.
| Modifier and Type | Field and Description |
|---|---|
| private static final PreEncodedHttpField | |
| private PreEncodedHttpField | |
| private PreEncodedHttpField | |
| private PreEncodedHttpField | |
| private PreEncodedHttpField | |
| private boolean | |
| private Set | |
| private Set | |
| private final Set | |
| private Set | |
| private final Set | |
| private Set | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private Set | |
| private static final Logger | |
| private Duration | |
| private static final PreEncodedHttpField |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | doStart()
Overrides org. |
| public Set | |
| public Set | |
| public Set | Returns: the immutable set of allowed origin regex strings in a cross-origin request
|
| public Set | Returns: the immutable set of allowed timing origin regex strings in a cross-origin request
|
| public Set | |
| public Duration | |
| public boolean | handle(Request
the HTTP request to handle request, Response the HTTP response to handle response, Callback the callback to complete when the handling is complete callback)Overrides org. Implements org. Invoked to handle the passed HTTP request and response. |
| private void | |
| private void | |
| public boolean | Returns: whether the cross server allows cross-origin requests to include credentials
|
| public boolean | Returns: whether requests whose origin is not allowed are delivered to the child Handler
|
| public boolean | Returns: whether WebSocket upgrade requests whose origin is not allowed are delivered to the child Handler
|
| public boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private void | |
| private void | |
| public void | setAllowCredentials(boolean
whether the cross server allows cross-origin requests to include credentials allow)Sets whether the cross server allows cross-origin requests to include credentials such as cookies or authentication headers. |
| public void | setAllowedHeaders(Set<String>
the set of allowed headers in a cross-origin request headers)Sets the set of allowed headers in a cross-origin request. |
| public void | setAllowedMethods(Set<String>
the set of allowed methods in a cross-origin request methods)Sets the set of allowed methods in a cross-origin request. |
| public void | setAllowedOriginPatterns(Set<String>
the set of allowed origin regex strings in a cross-origin request origins)Sets the set of allowed origin regex strings in a cross-origin request. |
| public void | setAllowedTimingOriginPatterns(Set<String>
the set of allowed timing origin regex strings in a cross-origin request origins)Sets the set of allowed timing origin regex strings in a cross-origin request. |
| public void | setDeliverNonAllowedOriginRequests(boolean
whether requests whose origin is not allowed are delivered to the child Handler deliverNonAllowedOrigin)Sets whether requests whose origin is not allowed are delivered to the child Handler. |
| public void | setDeliverNonAllowedOriginWebSocketUpgradeRequests(boolean
whether WebSocket upgrade requests whose origin is not allowed are delivered to the child Handler deliverNonAllowedOriginWebSocketUpgrade)Sets whether WebSocket upgrade requests whose origin is not allowed are delivered to the child Handler. |
| public void | setDeliverPreflightRequests(boolean
whether preflight requests are delivered to the child Handler deliver)Sets whether preflight requests are delivered to the child |
| public void | setExposedHeaders(Set<String>
the set of headers exposed in a cross-origin response headers)Sets the set of headers exposed in a cross-origin response. |
| public void | |
| private void | |
| private boolean |
| ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE | back to summary |
|---|---|
| private static final PreEncodedHttpField ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE | |
| accessControlAllowHeadersField | back to summary |
|---|---|
| private PreEncodedHttpField accessControlAllowHeadersField | |
| accessControlAllowMethodsField | back to summary |
|---|---|
| private PreEncodedHttpField accessControlAllowMethodsField | |
| accessControlExposeHeadersField | back to summary |
|---|---|
| private PreEncodedHttpField accessControlExposeHeadersField | |
| accessControlMaxAge | back to summary |
|---|---|
| private PreEncodedHttpField accessControlMaxAge | |
| allowCredentials | back to summary |
|---|---|
| private boolean allowCredentials | |
| allowedHeaders | back to summary |
|---|---|
| private Set<String> allowedHeaders | |
| allowedMethods | back to summary |
|---|---|
| private Set<String> allowedMethods | |
| allowedOriginPatterns | back to summary |
|---|---|
| private final Set<Pattern> allowedOriginPatterns | |
| allowedOrigins | back to summary |
|---|---|
| private Set<String> allowedOrigins | |
| allowedTimingOriginPatterns | back to summary |
|---|---|
| private final Set<Pattern> allowedTimingOriginPatterns | |
| allowedTimingOrigins | back to summary |
|---|---|
| private Set<String> allowedTimingOrigins | |
| anyOriginAllowed | back to summary |
|---|---|
| private boolean anyOriginAllowed | |
| anyTimingOriginAllowed | back to summary |
|---|---|
| private boolean anyTimingOriginAllowed | |
| deliverNonAllowedOrigin | back to summary |
|---|---|
| private boolean deliverNonAllowedOrigin | |
| deliverNonAllowedOriginWebSocketUpgrade | back to summary |
|---|---|
| private boolean deliverNonAllowedOriginWebSocketUpgrade | |
| deliverPreflight | back to summary |
|---|---|
| private boolean deliverPreflight | |
| exposedHeaders | back to summary |
|---|---|
| private Set<String> exposedHeaders | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| preflightMaxAge | back to summary |
|---|---|
| private Duration preflightMaxAge | |
| VARY_ORIGIN | back to summary |
|---|---|
| private static final PreEncodedHttpField VARY_ORIGIN | |
| CrossOriginHandler | back to summary |
|---|---|
| public CrossOriginHandler() | |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception Overrides org. Doc from org. Starts the managed lifecycle beans in the order they were added.
| |
| getAllowedHeaders | back to summary |
|---|---|
public Set
| |
| getAllowedMethods | back to summary |
|---|---|
public Set
| |
| getAllowedOriginPatterns | back to summary |
|---|---|
public Set
| |
| getAllowedTimingOriginPatterns | back to summary |
|---|---|
public Set
| |
| getExposedHeaders | back to summary |
|---|---|
public Set
| |
| getPreflightMaxAge | back to summary |
|---|---|
public Duration getPreflightMaxAge()
| |
| handle | back to summary |
|---|---|
| public boolean handle(Request request, Response response, Callback callback) throws Exception Overrides org. Implements org. Doc from org. Invoked to handle the passed HTTP request and response. The request is accepted by returning true, then handling must be concluded by completing the passed callback. The handling may be asynchronous, i.e. this method may return true and complete the given callback later, possibly from a different thread. If this method returns false, then the callback must not be invoked and any mutation on the response reversed. Exceptions thrown by this method may be subsequently handled by an error The simplest implementation is:
public boolean handle(Request request, Response response, Callback callback)
{
callback.succeeded();
return true;
}
A HelloWorld implementation is:
public boolean handle(Request request, Response response, Callback callback)
{
response.write(true, ByteBuffer.wrap("Hello World\n".getBytes(StandardCharsets.UTF_8)), callback);
return true;
}
| |
| handlePreflightResponse | back to summary |
|---|---|
| private void handlePreflightResponse(String origins, Response response) | |
| handleSimpleResponse | back to summary |
|---|---|
| private void handleSimpleResponse(String origin, Response response) | |
| isAllowCredentials | back to summary |
|---|---|
public boolean isAllowCredentials()
| |
| isDeliverNonAllowedOriginRequests | back to summary |
|---|---|
public boolean isDeliverNonAllowedOriginRequests()
| |
| isDeliverNonAllowedOriginWebSocketUpgradeRequests | back to summary |
|---|---|
public boolean isDeliverNonAllowedOriginWebSocketUpgradeRequests()
| |
| isDeliverPreflightRequests | back to summary |
|---|---|
public boolean isDeliverPreflightRequests()
| |
| isPreflight | back to summary |
|---|---|
| private boolean isPreflight(Request request) | |
| isWebSocketUpgrade | back to summary |
|---|---|
| private boolean isWebSocketUpgrade(Request request) | |
| originMatches | back to summary |
|---|---|
| private boolean originMatches(String origins) | |
| originMatches | back to summary |
|---|---|
| private boolean originMatches(String origins, Set<Pattern> allowedOriginPatterns) | |
| resolveAllowedOrigins | back to summary |
|---|---|
| private void resolveAllowedOrigins() | |
| resolveAllowedTimingOrigins | back to summary |
|---|---|
| private void resolveAllowedTimingOrigins() | |
| setAllowCredentials | back to summary |
|---|---|
| public void setAllowCredentials(boolean allow) Sets whether the cross server allows cross-origin requests to include credentials such as cookies or authentication headers. For example, when the cross server allows credentials to be included, cross-origin requests will contain cookies, otherwise they will not. The default is
| |
| setAllowedHeaders | back to summary |
|---|---|
| public void setAllowedHeaders(Set<String> headers) Sets the set of allowed headers in a cross-origin request. The cross server receives a preflight request that specifies the headers of the cross-origin request, and the cross server replies to the preflight request with the set of allowed headers. Browsers are responsible to check whether the headers of the cross-origin request are allowed, and if they are not produce an error. The headers can be either the character | |
| setAllowedMethods | back to summary |
|---|---|
| public void setAllowedMethods(Set<String> methods) Sets the set of allowed methods in a cross-origin request. The cross server receives a preflight request that specifies the method of the cross-origin request, and the cross server replies to the preflight request with the set of allowed methods. Browsers are responsible to check whether the method of the cross-origin request is allowed, and if it is not produce an error. | |
| setAllowedOriginPatterns | back to summary |
|---|---|
| public void setAllowedOriginPatterns(Set<String> origins) Sets the set of allowed origin regex strings in a cross-origin request. The cross server receives a preflight or a cross-origin request
specifying the The origins are either the character
The default value is | |
| setAllowedTimingOriginPatterns | back to summary |
|---|---|
| public void setAllowedTimingOriginPatterns(Set<String> origins) Sets the set of allowed timing origin regex strings in a cross-origin request. | |
| setDeliverNonAllowedOriginRequests | back to summary |
|---|---|
| public void setDeliverNonAllowedOriginRequests(boolean deliverNonAllowedOrigin) Sets whether requests whose origin is not allowed are delivered to the child Handler. Default value is
| |
| setDeliverNonAllowedOriginWebSocketUpgradeRequests | back to summary |
|---|---|
| public void setDeliverNonAllowedOriginWebSocketUpgradeRequests(boolean deliverNonAllowedOriginWebSocketUpgrade) Sets whether WebSocket upgrade requests whose origin is not allowed are delivered to the child Handler. Default value is
| |
| setDeliverPreflightRequests | back to summary |
|---|---|
| public void setDeliverPreflightRequests(boolean deliver) Sets whether preflight requests are delivered to the child Default value is
| |
| setExposedHeaders | back to summary |
|---|---|
| public void setExposedHeaders(Set<String> headers) Sets the set of headers exposed in a cross-origin response. The cross server receives a cross-origin request and indicates which response headers are exposed to scripts running in the browser. | |
| setPreflightMaxAge | back to summary |
|---|---|
public void setPreflightMaxAge(Duration duration)
| |
| throwIfStarted | back to summary |
|---|---|
| private void throwIfStarted() | |
| timingOriginMatches | back to summary |
|---|---|
| private boolean timingOriginMatches(String origins) | |