|
@@ -19,6 +19,7 @@ package org.springframework.security.config.web.servlet
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
|
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer
|
|
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer
|
|
import org.springframework.security.config.web.servlet.headers.*
|
|
import org.springframework.security.config.web.servlet.headers.*
|
|
|
|
+import org.springframework.security.web.header.HeaderWriter
|
|
import org.springframework.security.web.header.writers.*
|
|
import org.springframework.security.web.header.writers.*
|
|
import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter
|
|
import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter
|
|
|
|
|
|
@@ -41,6 +42,7 @@ class HeadersDsl {
|
|
private var referrerPolicy: ((HeadersConfigurer<HttpSecurity>.ReferrerPolicyConfig) -> Unit)? = null
|
|
private var referrerPolicy: ((HeadersConfigurer<HttpSecurity>.ReferrerPolicyConfig) -> Unit)? = null
|
|
private var featurePolicyDirectives: String? = null
|
|
private var featurePolicyDirectives: String? = null
|
|
private var disabled = false
|
|
private var disabled = false
|
|
|
|
+ private var headerWriters = mutableListOf<HeaderWriter>()
|
|
|
|
|
|
var defaultsDisabled: Boolean? = null
|
|
var defaultsDisabled: Boolean? = null
|
|
|
|
|
|
@@ -162,6 +164,16 @@ class HeadersDsl {
|
|
this.featurePolicyDirectives = policyDirectives
|
|
this.featurePolicyDirectives = policyDirectives
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Adds a [HeaderWriter] instance.
|
|
|
|
+ *
|
|
|
|
+ * @param headerWriter the [HeaderWriter] instance to add
|
|
|
|
+ * @since 5.4
|
|
|
|
+ */
|
|
|
|
+ fun addHeaderWriter(headerWriter: HeaderWriter) {
|
|
|
|
+ this.headerWriters.add(headerWriter)
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Disable all HTTP security headers.
|
|
* Disable all HTTP security headers.
|
|
*
|
|
*
|
|
@@ -205,6 +217,9 @@ class HeadersDsl {
|
|
featurePolicyDirectives?.also {
|
|
featurePolicyDirectives?.also {
|
|
headers.featurePolicy(featurePolicyDirectives)
|
|
headers.featurePolicy(featurePolicyDirectives)
|
|
}
|
|
}
|
|
|
|
+ headerWriters.forEach { headerWriter ->
|
|
|
|
+ headers.addHeaderWriter(headerWriter)
|
|
|
|
+ }
|
|
if (disabled) {
|
|
if (disabled) {
|
|
headers.disable()
|
|
headers.disable()
|
|
}
|
|
}
|