public class SpincastFilters<R extends IRequestContext<?>> extends Object implements ISpincastFilters<R>
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_CACHE_BUSTER |
static String |
DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_LANG_ABREV |
static String |
DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_SPINCAST_CURRENT_VERSION |
static String |
DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_SPINCAST_CURRENT_VERSION_IS_SNAPSHOT |
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastFilters(ICorsFilter corsFilter,
ISpincastConfig spincastConfig,
IServer server,
ISpincastUtils spincastUtils)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDefaultGlobalTemplateVariables(R context)
Adds some default variables so they are available
by default to the templating engine (in a request scope).
|
void |
addSecurityHeaders(R context)
Adds some recommended security headers.
|
void |
cache(R context) |
void |
cache(R context,
int seconds) |
void |
cache(R context,
int seconds,
boolean isPrivate) |
void |
cache(R context,
int seconds,
boolean isPrivate,
Integer cdnSeconds) |
void |
cors(R context)
Cross-Origin Resource Sharing (Cors) handling.
|
void |
cors(R context,
Set<String> allowedOrigins)
Cross-Origin Resource Sharing (Cors) handling.
|
void |
cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead)
Cross-Origin Resource Sharing (Cors) handling.
|
void |
cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent)
Cross-Origin Resource Sharing (Cors) handling.
|
void |
cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies)
Cross-Origin Resource Sharing (Cors) handling.
|
void |
cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
Set<HttpMethod> allowedMethods)
Cross-Origin Resource Sharing (Cors) handling.
|
void |
cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
Set<HttpMethod> allowedMethods,
int maxAgeInSeconds)
Cross-Origin Resource Sharing (Cors) handling.
|
protected ICorsFilterClient |
createCorsFilterClient(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
Set<HttpMethod> allowedMethods,
int maxAgeInSeconds)
Creates a client for the cors filter.
|
protected Integer |
getCacheCdnSecondsByDefault() |
protected int |
getCacheSecondsByDefault() |
protected Set<HttpMethod> |
getCorsDefaultAllowedMethods()
The HTTP methods allowed by default.
|
protected Set<String> |
getCorsDefaultAllowedOrigins()
The origins allowed, by default.
|
protected Set<String> |
getCorsDefaultExtraHeadersAllowedToBeRead()
The extra headers allowed to be read, by default,
|
protected Set<String> |
getCorsDefaultExtraHeadersAllowedToBeSent()
The extra headers allowed to be sent, by default,
|
protected boolean |
getCorsDefaultIsCookiesAllowed()
Are cookies allowed by default?
|
protected int |
getCorsDefaultMaxAgeInSeconds()
If <= 0, the "Access-Control-Max-Age" header
won't be sent.
|
protected ICorsFilter |
getCorsFilter() |
protected IServer |
getServer() |
protected ISpincastConfig |
getSpincastConfig() |
protected ISpincastUtils |
getSpincastUtils() |
protected boolean |
isCachePrivateByDefault() |
boolean |
saveGeneratedResource(R context,
String pathForGeneratedResource)
Used by Spincast to save a "dynamic resource" once it is
generated.
|
protected final org.slf4j.Logger logger
public static final String DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_LANG_ABREV
public static final String DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_SPINCAST_CURRENT_VERSION
public static final String DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_SPINCAST_CURRENT_VERSION_IS_SNAPSHOT
public static final String DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_CACHE_BUSTER
@Inject public SpincastFilters(ICorsFilter corsFilter, ISpincastConfig spincastConfig, IServer server, ISpincastUtils spincastUtils)
protected ICorsFilter getCorsFilter()
protected ISpincastConfig getSpincastConfig()
protected IServer getServer()
protected ISpincastUtils getSpincastUtils()
public boolean saveGeneratedResource(R context, String pathForGeneratedResource)
ISpincastFilterssaveGeneratedResource in interface ISpincastFilters<R extends IRequestContext<?>>public void addSecurityHeaders(R context)
ISpincastFiltersaddSecurityHeaders in interface ISpincastFilters<R extends IRequestContext<?>>https://www.owasp.org/index.php/List_of_useful_HTTP_headerspublic void cors(R context)
ISpincastFiltersThis overload allows all origins, allows cookies, allows all HTTP methods, all headers will be allowed to be sent by the browser, but no extra headers will be available to be read by the browser.
By default, only those headers are available to be read :
Send a Max-Age of 24h. The Max-Age is the maximum number of seconds a preflight response can be cached without querying again.
If you want to allow everything AND to add extra headers to be read, use :
cors(context, Sets.newHashSet("*"), Sets.newHashSet("extra-header-to-read1", "extra-header-to-read2"));
cors in interface ISpincastFilters<R extends IRequestContext<?>>public void cors(R context, Set<String> allowedOrigins)
ISpincastFiltersThis overload allows allows cookies, allows all HTTP methods for the specified origins, all headers will be allowed to be sent by the browser, but no extra headers will be available to be read by the browser.
By default, only those headers are available to be read :
Send a Max-Age of 24h. The Max-Age is the maximum number of seconds a preflight response can be cached without querying again.
If you want to allow everything for those origins AND to add extra headers to be read, use : cors(context, allowedOrigins, Sets.newHashSet("extra-header-to-read1", "extra-header-to-read2"));cors in interface ISpincastFilters<R extends IRequestContext<?>>allowedOrigins - The origins to allow ("http://api.bob.com"
for example). If one of the origins is "*", then all origins
will be allowed!public void cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
ISpincastFiltersThis overload allows cookies, allows all HTTP methods and all headers will be allowed to be sent by the browser, for the specified origins.
Send a Max-Age of 24h. The Max-Age is the maximum number of seconds a preflight response can be cached without querying again.
cors in interface ISpincastFilters<R extends IRequestContext<?>>allowedOrigins - The origins to allow ("http://api.bob.com"
for example). If one of the origins is "*", then all origins
will be allowed!extraHeadersAllowedToBeRead - The extra headers the browser will
have permission to read from the response.
By default, only those headers are available :
Cache-Control
Content-Language
Content-Type
Expires
Last-Modified
Pragmapublic void cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
ISpincastFiltersThis overload allows all cookies and all HTTP methods, for the specified origins.
Send a Max-Age of 24h. The Max-Age is the maximum number of seconds a preflight response can be cached without querying again.
cors in interface ISpincastFilters<R extends IRequestContext<?>>allowedOrigins - The origins to allow ("http://api.bob.com"
for example). If one of the origins is "*", then all origins
will be allowed!extraHeadersAllowedToBeRead - The extra headers the browser will
have permission to read from the response.
By default, only those headers are exposed :
Cache-Control
Content-Language
Content-Type
Expires
Last-Modified
PragmaextraHeadersAllowedToBeSent - The extra headers the
browser will be allowed to send with the actual
(post preflight) request.public void cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
ISpincastFiltersThis overload allows all HTTP methods, for the specified origins.
Send a Max-Age of 24h. The Max-Age is the maximum number of seconds a preflight response can be cached without querying again.
cors in interface ISpincastFilters<R extends IRequestContext<?>>allowedOrigins - The origins to allow ("http://api.bob.com"
for example). If one of the origins is "*", then all origins
will be allowed!extraHeadersAllowedToBeRead - The extra headers the browser will
have permission to read from the response.
By default, only those headers are exposed :
Cache-Control
Content-Language
Content-Type
Expires
Last-Modified
PragmaextraHeadersAllowedToBeSent - The extra headers the
browser will be allowed to send with the actual
(post preflight) request.allowCookies - Should cookies be allowed?public void cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
ISpincastFiltersSend a Max-Age of 24h. The Max-Age is the maximum number of seconds a preflight response can be cached without querying again.
cors in interface ISpincastFilters<R extends IRequestContext<?>>allowedOrigins - The origins to allow ("http://api.bob.com"
for example). If one of the origins is "*", then all origins
are allowed!extraHeadersAllowedToBeRead - The extra headers the browser will
have permission to read from the response.
By default, only those headers are available :
Cache-Control
Content-Language
Content-Type
Expires
Last-Modified
PragmaextraHeadersAllowedToBeSent - The extra headers the
browser will be allowed to send with the actual
(post preflight) request. If one of the headers is "*",
then all headers are allowed to be sent!allowCookies - Should cookies be allowed?allowedMethods - The HTTP method allowed. "OPTIONS" will
be addded if not specified, as it should always be
allowed.public void cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
ISpincastFilterscors in interface ISpincastFilters<R extends IRequestContext<?>>allowedOrigins - The origins to allow ("http://api.bob.com"
for example). If one of the origins is "*", then all origins
are allowed!extraHeadersAllowedToBeRead - The extra headers the browser will
have permission to read from the response.
By default, only those headers are available :
Cache-Control
Content-Language
Content-Type
Expires
Last-Modified
PragmaextraHeadersAllowedToBeSent - The extra headers the
browser will be allowed to send with the actual
(post preflight) request. If one of the headers is "*",
then all headers are allowed to be sent!allowCookies - Should cookies be allowed?allowedMethods - The HTTP method allowed. "OPTIONS" will
be addded if not specified, as it should always be
allowed.maxAgeInSeconds - The maximum number of seconds a
preflight response can be cached without querying
again. If <= 0, the "Access-Control-Max-Age" header
won't be sent.protected ICorsFilterClient createCorsFilterClient(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
protected int getCorsDefaultMaxAgeInSeconds()
protected Set<String> getCorsDefaultAllowedOrigins()
protected Set<String> getCorsDefaultExtraHeadersAllowedToBeRead()
protected Set<String> getCorsDefaultExtraHeadersAllowedToBeSent()
protected boolean getCorsDefaultIsCookiesAllowed()
protected Set<HttpMethod> getCorsDefaultAllowedMethods()
public void cache(R context)
cache in interface ISpincastFilters<R extends IRequestContext<?>>public void cache(R context, int seconds)
cache in interface ISpincastFilters<R extends IRequestContext<?>>public void cache(R context, int seconds, boolean isPrivate)
cache in interface ISpincastFilters<R extends IRequestContext<?>>public void cache(R context, int seconds, boolean isPrivate, Integer cdnSeconds)
cache in interface ISpincastFilters<R extends IRequestContext<?>>protected int getCacheSecondsByDefault()
protected boolean isCachePrivateByDefault()
protected Integer getCacheCdnSecondsByDefault()
public void addDefaultGlobalTemplateVariables(R context)
ISpincastFiltersaddDefaultGlobalTemplateVariables in interface ISpincastFilters<R extends IRequestContext<?>>Copyright © 2016. All rights reserved.