|
aerogear-controller 1.0.0.M1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jboss.aerogear.controller.router.decorators.cors.Cors
public class Cors
Cors is a helper class for handling Cross-Origin Resource Sharing (CORS) in AeroGear Controller.
| Nested Class Summary | |
|---|---|
static class |
Cors.RequestHeader
|
static class |
Cors.ResponseHeader
|
| Field Summary | |
|---|---|
private CorsConfiguration |
corsConfig
|
private javax.servlet.http.HttpServletRequest |
request
|
| Constructor Summary | |
|---|---|
Cors(CorsConfiguration corsConfig,
javax.servlet.http.HttpServletRequest request)
Sole constructor. |
|
| Method Summary | |
|---|---|
boolean |
areRequestHeadersValid()
Checks that the configured preflight request headers ( Cors.RequestHeader.HEADERS) are supported
according to the underlying CorsConfiguration settings. |
boolean |
areRequestHeadersValid(Set<String> validHeaders)
Checks that the preflight request headers ( Cors.RequestHeader.HEADERS) are supported. |
boolean |
canHandleRequest()
Determines if this instance can handle CORS requests. |
Set<String> |
getAllowedRequestHeaders()
Returns the allowed set of Request Headers. |
Set<String> |
getAllowedRequestMethods()
Returns the allowed set of Request Methods. |
String |
getRequestHeaders()
Returns the Cors.RequestHeader.HEADERS request header. |
String |
getRequestMethod()
Returns the Cors.RequestHeader.METHOD request header. |
private boolean |
hasHeader(String name)
|
boolean |
hasOriginHeader()
Determines if the current HttpServletRequest has an 'Origin' request header. |
boolean |
hasRequestHeaders()
Determines if the current HttpServletRequest has a Cors.RequestHeader.HEADERS request header. |
boolean |
isCorsRequest()
Determines if the current HttpServletRequest is a CORS request. |
boolean |
isCorsSupportEnabled()
Determines if core support has been enabled by the CorsConfig instance. |
boolean |
isOptionsMethod()
Determines if the the current HttpServletRequest's http method is 'OPTIONS'. |
boolean |
isPreflightRequest()
Determines if the current HttpServletRequest qualifies as a 'Preflight' request. |
boolean |
isRequestMethodValid()
Checks that the preflight request method ( Cors.RequestHeader.METHOD) is supported according
to the CorsConfiguration settings. |
boolean |
isRequestMethodValid(Set<String> validMethods)
Checks that the preflight request method ( Cors.RequestHeader.METHOD) is supported. |
Cors |
setAllowCredentials(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.ALLOW_CREDENTIALS to 'true' if allowCookies was set set to true in the underlying
CorsConfiguration. |
Cors |
setAllowHeaders(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.ALLOW_HEADERS to configured values. |
Cors |
setAllowMethods(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.ALLOW_METHODS to the the configured comma separated list of http methods. |
Cors |
setAnyOrigin(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.ALLOW_ORIGIN to '*'. |
Cors |
setEchoOrigin(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.ALLOW_ORIGIN to be the same value that was passed in the 'Origin' request header. |
Cors |
setExposeHeaders(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.EXPOSE_HEADERS to the the configured comma separated list of headers. |
Cors |
setMaxAge(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.MAX_AGE to the configured max age value. |
Cors |
setOrigin(javax.servlet.http.HttpServletResponse response)
Set the Cors.ResponseHeader.ALLOW_ORIGIN to either echo the 'Origin' or to support '*' depending on the underlying
CorsConfiguration setting. |
Cors |
setOrigin(javax.servlet.http.HttpServletResponse response,
String origin)
Set the Cors.ResponseHeader.ALLOW_ORIGIN to the passed in value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final javax.servlet.http.HttpServletRequest request
private final CorsConfiguration corsConfig
| Constructor Detail |
|---|
public Cors(CorsConfiguration corsConfig,
javax.servlet.http.HttpServletRequest request)
corsConfig - The CorsConfig containing configuration options.request - The HttpServletRequest that this instance will use.| Method Detail |
|---|
public boolean isCorsRequest()
HttpServletRequest is a CORS request.
See http-origin section of the specification.
true if the current request has an 'Origin' request header, otherwise false.public boolean canHandleRequest()
isCorsSupportEnabled() && isCorsRequest()
true is CORS support has been enabled and if the current request is a CORS request.public boolean isCorsSupportEnabled()
CorsConfig instance.
true if support for CORS is enabled.public boolean hasOriginHeader()
HttpServletRequest has an 'Origin' request header.
true if the current request has an 'Origin' request header, otherwise false.public boolean isOptionsMethod()
HttpServletRequest's http method is 'OPTIONS'.
true if the current request' http method is 'OPTIONS', otherwise false.public boolean isPreflightRequest()
HttpServletRequest qualifies as a 'Preflight' request.
See preflight-request section of the specification.
true if the current request qualifies as a preflight, otherwise false.public boolean isRequestMethodValid(Set<String> validMethods)
Cors.RequestHeader.METHOD) is supported.
validMethods - a set of methods that are allowed.
true if the current request method is one of the allowed http methods.public boolean isRequestMethodValid()
Cors.RequestHeader.METHOD) is supported according
to the CorsConfiguration settings.
true if the current request method is one of the allowed http methods.public boolean hasRequestHeaders()
HttpServletRequest has a Cors.RequestHeader.HEADERS request header.
true if the current request methods has a RequestHeader.HEADERS header.public String getRequestHeaders()
Cors.RequestHeader.HEADERS request header.
String if the current request methods has a RequestHeader.HEADERS header.public String getRequestMethod()
Cors.RequestHeader.METHOD request header.
true if the current request methods has a RequestHeader.HEADERS header.public Set<String> getAllowedRequestMethods()
Set of allowed Request Methods.public Set<String> getAllowedRequestHeaders()
Set of allowed Request Headers.public Cors setEchoOrigin(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_ORIGIN to be the same value that was passed in the 'Origin' request header.
response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.
Cors to support methods chaining.public Cors setOrigin(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_ORIGIN to either echo the 'Origin' or to support '*' depending on the underlying
CorsConfiguration setting.
response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.
Cors to support methods chaining.
public Cors setOrigin(javax.servlet.http.HttpServletResponse response,
String origin)
Cors.ResponseHeader.ALLOW_ORIGIN to the passed in value.
response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.
Cors to support methods chaining.public Cors setAnyOrigin(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_ORIGIN to '*'.
response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.
Cors to support methods chaining.public Cors setAllowCredentials(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_CREDENTIALS to 'true' if allowCookies was set set to true in the underlying
CorsConfiguration.
By default cookies are not included in CORS requests but by setting this header cookies will be added to CORS request.
response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_CREDENTIALS should be set.
Cors to support methods chaining.public Cors setExposeHeaders(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.EXPOSE_HEADERS to the the configured comma separated list of headers.
During a simple CORS request only certain response headers are made available to a calling client:
response - the HttpServletResponse for which the response header ResponseHeader#EXPOSE_HEADERS should be set.
Cors to support methods chaining.public Cors setAllowMethods(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_METHODS to the the configured comma separated list of http methods.
response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_METHODS should be set.
Cors to support methods chaining.public Cors setMaxAge(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.MAX_AGE to the configured max age value.
When making a preflight request the client has to perform two request with can be inefficient. This
setting enables the caching of the preflight response for the specified time. During this time no
preflight request will be made.
response - the HttpServletResponse for which the response header ResponseHeader.MAX_AGE should be set.
Cors to support methods chaining.public boolean areRequestHeadersValid(Set<String> validHeaders)
Cors.RequestHeader.HEADERS) are supported.
validHeaders - a set of headers that are allowed.
true if the current request headers are supported.public boolean areRequestHeadersValid()
Cors.RequestHeader.HEADERS) are supported
according to the underlying CorsConfiguration settings.
true if the current request headers are not supported.public Cors setAllowHeaders(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_HEADERS to configured values.
Cors to support methods chaining.private boolean hasHeader(String name)
|
aerogear-controller 1.0.0.M1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||