【发布时间】:2018-04-08 03:29:24
【问题描述】:
我被要求在对 REST API 的所有响应中设置 Content-Security-Policy 标头,而无需单独配置它们。
接口本身是由 saml 保护的,而我添加 WebSecurityConfigurerAdapter 类的努力产生了干扰 spring-security-saml2-core 库的不幸效果。 (结果是我的配置器的配置方法从未被调用过)。由于这个库实际上是一个黑匣子,我宁愿不理会它
我能看到的唯一替代方法是使用 XML 配置来添加标题。但是怎么做呢?
我看到很多文档建议添加:
<http>
<!-- ... -->
<headers>
<content-security-policy policy-directives="script-src 'self'" />
</headers>
</http>
但是去哪里?我知道http 是 Spring 安全名称空间的一部分,但是当我收到错误时,标头似乎不是有效的子元素:
ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 35 in XML document from ServletContext resource [/WEB-INF/security-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 13; cvc-complex-type.2.4.a: Invalid content was found starting with element 'headers'. One of '{"http://www.springframework.org/schema/security":intercept-url, "http://www.springframework.org/schema/security":access-denied-handler, "http://www.springframework.org/schema/security":form-login, "http://www.springframework.org/schema/security":openid-login, "http://www.springframework.org/schema/security":x509, "http://www.springframework.org/schema/security":jee, "http://www.springframework.org/schema/security":http-basic, "http://www.springframework.org/schema/security":logout, "http://www.springframework.org/schema/security":session-management, "http://www.springframework.org/schema/security":remember-me, "http://www.springframework.org/schema/security":anonymous, "http://www.springframework.org/schema/security":port-mappings, "http://www.springframework.org/schema/security":custom-filter, "http://www.springframework.org/schema/security":request-cache, "http://www.springframework.org/schema/security":expression-handler, "http://www.springframework.org/schema/security":headers, "http://www.springframework.org/schema/security":csrf, "http://www.springframework.org/schema/security":cors}' is expected.
【问题讨论】:
-
解决这个问题有好运吗?
-
@tk_ 不走运。我最终放弃了。如果你知道我还有什么兴趣
标签: spring security spring-security