Package io.micronaut.views.csp
Class CspConfiguration
java.lang.Object
io.micronaut.views.csp.CspConfiguration
- All Implemented Interfaces:
- io.micronaut.core.util.Toggleable
@ConfigurationProperties("micronaut.views.csp")
public class CspConfiguration
extends Object
implements io.micronaut.core.util.Toggleable
Defines CSP configuration properties.
- Since:
- 1.1
- Author:
- Arul Dhesiaseelan
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final Base64.EncoderDefault Base64 encoder.static final booleanstatic final booleanstatic final Stringstatic final booleanstatic final booleanstatic final StringThe path for endpoints settings.static final intLength of generated CSP nonce values.static final StringThe prefix for csp configuration.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionGenerate a nonce value for use in a Content-Security-Policy header, which is usable for one request/response cycle.The path the CSP filter should apply to.Sets the policy directives.The `Random` data engine used to generate nonce values.booleanbooleanbooleanbooleanIf true, the Content-Security-Policy-Report-Only header will be sent instead of Content-Security-Policy.voidsetEnabled(boolean enabled) Sets whether CSP is enabled.voidsetFilterPath(String filterPath) Sets the path the CSP filter should apply to.voidsetForceSecureRandom(boolean forceSecureRandom) Sets whether `SecureRandom` is forced for use in generated nonce values.voidsetGenerateNonce(boolean generateNonce) If true, the CSP header will contain a generated nonce that is made available to view renderers.voidsetPolicyDirectives(@Nullable String policyDirectives) Sets the policy directives.voidsetRandomEngine(Random randomEngine) Sets the `Random` data engine used to generate nonce values.voidsetReportOnly(boolean reportOnly) If true, the Content-Security-Policy-Report-Only header will be sent instead of Content-Security-Policy.
- 
Field Details- 
NONCE_LENGTHpublic static final int NONCE_LENGTHLength of generated CSP nonce values. Must be a multiple of 8.- See Also:
 
- 
BASE64_ENCODERDefault Base64 encoder.
- 
PREFIXThe prefix for csp configuration.- See Also:
 
- 
FILTER_PATHThe path for endpoints settings.- See Also:
 
- 
DEFAULT_ENABLEDpublic static final boolean DEFAULT_ENABLED- See Also:
 
- 
DEFAULT_REPORT_ONLYpublic static final boolean DEFAULT_REPORT_ONLY- See Also:
 
- 
DEFAULT_ENABLE_NONCEpublic static final boolean DEFAULT_ENABLE_NONCE- See Also:
 
- 
DEFAULT_FORCE_SECURE_RANDOMpublic static final boolean DEFAULT_FORCE_SECURE_RANDOM- See Also:
 
- 
DEFAULT_FILTER_PATH- See Also:
 
 
- 
- 
Constructor Details- 
CspConfigurationpublic CspConfiguration()
 
- 
- 
Method Details- 
isEnabledpublic boolean isEnabled()- Specified by:
- isEnabledin interface- io.micronaut.core.util.Toggleable
 
- 
getPolicyDirectivesSets the policy directives.- Returns:
- The policy directives
 
- 
isReportOnlypublic boolean isReportOnly()If true, the Content-Security-Policy-Report-Only header will be sent instead of Content-Security-Policy. Default value (false).- Returns:
- Whether the report only header should be set
 
- 
isNonceEnabledpublic boolean isNonceEnabled()- Returns:
- Whether nonce generation is enabled for each request/response cycle
 
- 
isForceSecureRandomEnabledpublic boolean isForceSecureRandomEnabled()- Returns:
- Whether use of SecureRandomis forced for nonce generation.
 
- 
getRandomEngineThe `Random` data engine used to generate nonce values. Ignored if `forceSecureRandom` is set to `true`.- Returns:
- Random data engine currently in use to generate nonce values.
 
- 
setEnabledpublic void setEnabled(boolean enabled) Sets whether CSP is enabled. Default value (false).- Parameters:
- enabled- True if CSP is enabled
 
- 
setPolicyDirectivesSets the policy directives.- Parameters:
- policyDirectives- CSP policy directives
 
- 
setReportOnlypublic void setReportOnly(boolean reportOnly) If true, the Content-Security-Policy-Report-Only header will be sent instead of Content-Security-Policy. Default value (false).- Parameters:
- reportOnly- set to true for reporting purpose only
 
- 
setGenerateNoncepublic void setGenerateNonce(boolean generateNonce) If true, the CSP header will contain a generated nonce that is made available to view renderers. The nonce should change for each request/response cycle and can be used by views to authorize inlined script blocks.- Parameters:
- generateNonce- set to true to enable generation of nonces
 
- 
setForceSecureRandompublic void setForceSecureRandom(boolean forceSecureRandom) Sets whether `SecureRandom` is forced for use in generated nonce values. Defaults to (false). Enabling this requires careful consideration, because `SecureRandom` will block infinitely without enough entropy.- Parameters:
- forceSecureRandom- set to true to force- SecureRandomuse for nonce values.
 
- 
setRandomEngineSets the `Random` data engine used to generate nonce values. Ignored if `forceSecureRandom` is set to `true`.- Parameters:
- randomEngine- Random data engine to use.
 
- 
getFilterPathThe path the CSP filter should apply to. Default value ("/**").- Returns:
- The path the CSP filter should apply to
 
- 
setFilterPathSets the path the CSP filter should apply to. Default value ("/**").- Parameters:
- filterPath- The filter path
 
- 
generateNonceGenerate a nonce value for use in a Content-Security-Policy header, which is usable for one request/response cycle.- Returns:
- Base64-encoded random nonce value.
 
 
-