简体   繁体   English

Spring MVC安全性permitAll / /但拒绝所有/ / **不起作用

[英]Spring MVC Security permitAll to / but denyAll to /** not working

I have a Spring4 MVC application that is deployed on Wildfly10 and is configured using xml. 我有一个Spring4 MVC应用程序,该应用程序部署在Wildfly10上并使用xml配置。

I have the following controller defined: 我定义了以下控制器:

<mvc:view-controller path="/" view-name="/index" />
<mvc:view-controller path="/index" view-name="/index" />

And in Spring security define access: 在Spring安全性中定义访问权限:

<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/" access="permitAll" />
    <intercept-url pattern="/index" access="permitAll" />
    ...
    <intercept-url pattern="/**" access="denyAll" />
    <form-login login-page="/login" default-target-url="/dashboard"
        always-use-default-target="true" authentication-failure-url="/loginfailed"
        authentication-failure-handler-ref="authenticationFailureHandler" />
    <logout logout-success-url="/index" />
    <access-denied-handler ref="customAccessDeniedHandler"/> 
</http>

If I remove the denyAll to /** intercept-url the application works as intended however adding it causes security to redirect root calls to the login page and not the index page! 如果我将denyAll删除到/ **拦截URL,则应用程序将按预期工作,但是添加它会导致安全性将根调用重定向到登录页面而不是索引页面!

Is there a way I can have permitAll access to the root (Redirects to /index) of my application and still denyAll to /** thus covering anything else that is not defined? 有没有一种方法可以使我的应用程序的根目录(重定向到/ index)具有permitAll的访问权,而仍然可以将/ **的所有访问权限拒绝,从而覆盖未定义的其他内容?

By Changing the pattern to <intercept-url pattern="/.+" access="denyAll" /> as commented by Vasan got it working. 通过将模式更改为<intercept-url pattern="/.+" access="denyAll" />如Vasan所说),它可以正常工作。 below is an example of the change 以下是变更示例

<http auto-config="true" use-expressions="true">
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/index" access="permitAll" />
...
<intercept-url pattern="/.+" access="denyAll" />
<form-login login-page="/login" default-target-url="/dashboard"
    always-use-default-target="true" authentication-failure-url="/loginfailed"
    authentication-failure-handler-ref="authenticationFailureHandler" />
<logout logout-success-url="/index" />
<access-denied-handler ref="customAccessDeniedHandler"/> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM