@ConfigurationProperties(value="micronaut.views.csp")
public class CspConfiguration
extends java.lang.Object
implements io.micronaut.core.util.Toggleable
Modifier and Type | Field and Description |
---|---|
static java.util.Base64.Encoder |
BASE64_ENCODER
Default Base64 encoder.
|
static boolean |
DEFAULT_ENABLE_NONCE |
static boolean |
DEFAULT_ENABLED |
static java.lang.String |
DEFAULT_FILTER_PATH |
static boolean |
DEFAULT_FORCE_SECURE_RANDOM |
static boolean |
DEFAULT_REPORT_ONLY |
static java.lang.String |
FILTER_PATH
The path for endpoints settings.
|
static int |
NONCE_LENGTH
Length of generated CSP nonce values.
|
static java.lang.String |
PREFIX
The prefix for csp configuration.
|
Constructor and Description |
---|
CspConfiguration() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
generateNonce()
Generate a nonce value for use in a Content-Security-Policy header, which
is usable for one request/response cycle.
|
java.lang.String |
getFilterPath() |
java.util.Optional<java.lang.String> |
getPolicyDirectives() |
java.util.Random |
getRandomEngine() |
boolean |
isEnabled() |
boolean |
isForceSecureRandomEnabled() |
boolean |
isNonceEnabled() |
boolean |
isReportOnly() |
void |
setEnabled(boolean enabled)
Sets whether CSP is enabled.
|
void |
setFilterPath(java.lang.String filterPath)
Sets the path the CSP filter should apply to.
|
void |
setForceSecureRandom(boolean forceSecureRandom)
Sets whether `SecureRandom` is forced for use in generated nonce values.
|
void |
setGenerateNonce(boolean generateNonce)
If true, the CSP header will contain a generated nonce that is made available
to view renderers.
|
void |
setPolicyDirectives(java.lang.String policyDirectives)
Sets the policy directives.
|
void |
setRandomEngine(java.util.Random randomEngine)
Sets the `Random` data engine used to generate nonce values.
|
void |
setReportOnly(boolean reportOnly)
If true, the Content-Security-Policy-Report-Only header will be sent instead
of Content-Security-Policy.
|
public static final int NONCE_LENGTH
public static final java.util.Base64.Encoder BASE64_ENCODER
public static final java.lang.String PREFIX
public static final java.lang.String FILTER_PATH
public static final boolean DEFAULT_ENABLED
public static final boolean DEFAULT_REPORT_ONLY
public static final boolean DEFAULT_ENABLE_NONCE
public static final boolean DEFAULT_FORCE_SECURE_RANDOM
public static final java.lang.String DEFAULT_FILTER_PATH
public boolean isEnabled()
isEnabled
in interface io.micronaut.core.util.Toggleable
public java.util.Optional<java.lang.String> getPolicyDirectives()
public boolean isReportOnly()
public boolean isNonceEnabled()
public boolean isForceSecureRandomEnabled()
SecureRandom
is forced for nonce generation.public java.util.Random getRandomEngine()
public void setEnabled(boolean enabled)
enabled
- True if CSP is enabledpublic void setPolicyDirectives(@Nullable java.lang.String policyDirectives)
policyDirectives
- CSP policy directivespublic void setReportOnly(boolean reportOnly)
reportOnly
- set to true for reporting purpose onlypublic void setGenerateNonce(boolean generateNonce)
generateNonce
- set to true to enable generation of noncespublic void setForceSecureRandom(boolean forceSecureRandom)
forceSecureRandom
- set to true to force SecureRandom
use for nonce values.public void setRandomEngine(java.util.Random randomEngine)
randomEngine
- Random data engine to use.public java.lang.String getFilterPath()
public void setFilterPath(java.lang.String filterPath)
filterPath
- The filter pathpublic java.lang.String generateNonce()