禁用特定URL上的标头

时间:2017-09-06 19:41:28

标签: java spring-security

Spring相当新,所以这可能是基本的。 我们最近从第3季度过渡到第4期,并遇到了与我们的合作伙伴业务逻辑相关的新defaults的一些标题问题

我们希望保留默认值,除了特定的网址" /stg/strategem/strg/drammin.syg"

目前我们有:

<http use-expressions="true" entry-point-ref="web.AuthenticaionEntryPoint">
   <intercept-url pattern="/admin/**" access = "hasAnyRole('GKR_ADMIN', 'GKR_ADMIN_ADV')"/>
   <intercept-url pattern="/**" access = "hasAnyRole('GKR_USER')"/>
</http>

如何配置此项以便[&#34; /stg/strategem/strg/drammin.syg"]仍然受到保护,但是下面的标头配置适用的唯一地方?

<headers defaults-disabled="true">
    <content-type-options />
    <hsts include-subdomains="true" max-age-seconds="31536000"/>
    <frame-options policy="SAMEORIGIN"/>
    <xss-protection block="false"/>
</headers>

更新1:能够使我需要无头的URL更具体

更新2: 我只是尝试添加另一个http块,但我不断收到Spring Error

  

通用匹配模式(&#39; / **&#39;)   在过滤器链中的其他模式之前定义,导致它们被忽略。

无论我把这些块放在什么顺序,我甚至尝试删除&#34; / **&#34;模式,这个错误仍然出现。

我的尝试:

<http use-expressions="true" entry-point-ref="web.AuthenticaionEntryPoint">
   <intercept-url pattern="/admin/**" access = "hasAnyRole('GKR_ADMIN', 'GKR_ADMIN_ADV')"/>
   <intercept-url pattern="/**" access = "hasAnyRole('GKR_USER')"/>
</http>

<http use-expressions="true" entry-point-ref="web.AuthenticaionEntryPoint">       
    <headers defaults-disabled="true">
        <content-type-options />
        <hsts include-subdomains="true" max-age-seconds="31536000"/>
        <frame-options policy="SAMEORIGIN"/>
        <xss-protection block="false"/>
    </headers>

    <intercept-url pattern="/stg/strategem/strg/drammin.syg" access = "hasAnyRole('GKR_ADMIN', 'GKR_ADMIN_ADV', 'GKR_USER')"/>
</http>

更新3:能够找到解决方案,请在答案中查看

2 个答案:

答案 0 :(得分:1)

您应该能够拥有多个<http>块,每个块具有不同的配置。见Spring Security Reference - Multiple Security

答案 1 :(得分:0)

好的伙计们,我能够通过使用具有模式但没有拦截URL的单独HTTP块来实现这一点。试图让两者都具有安全配置是造成这个问题的原因。

感谢Zilvinas指出我正确的道路。

第一个块将标头配置应用于特定网址。其他一切都得到了Spring的默认值。 第二个块应用安全措施。 (包括特定网址,因为我有/ **通配符)

<http pattern="/stg/strategem/strg/drammin.syg">       
    <headers defaults-disabled="true">
        <content-type-options />
        <hsts include-subdomains="true" max-age-seconds="31536000"/>
        <frame-options policy="SAMEORIGIN"/>
        <xss-protection block="false"/>
    </headers>
</http>

<http use-expressions="true" entry-point-ref="web.AuthenticaionEntryPoint">
   <intercept-url pattern="/admin/**" access = "hasAnyRole('GKR_ADMIN', 'GKR_ADMIN_ADV')"/>
   <intercept-url pattern="/**" access = "hasAnyRole('GKR_USER')"/>
</http>
相关问题