Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring安全认证用户专用_Spring_Spring Security - Fatal编程技术网

Spring安全认证用户专用

Spring安全认证用户专用,spring,spring-security,Spring,Spring Security,我刚刚开始阅读SpringSecurity3.1,我想知道如何在访问系统上的任何页面之前,通过登录页面强制用户进行身份验证。在教程中,我看到了以下代码 <http use-e xpressions="true"> <intercept-url pattern="/index.jsp" access="permitAll" /> <intercept-url pattern="/secure/extreme/**" access="hasRole('s

我刚刚开始阅读SpringSecurity3.1,我想知道如何在访问系统上的任何页面之前,通过登录页面强制用户进行身份验证。在教程中,我看到了以下代码

<http use-e xpressions="true">
    <intercept-url pattern="/index.jsp" access="permitAll" />
    <intercept-url pattern="/secure/extreme/**" access="hasRole('supervisor')" />
    <intercept-url pattern="/secure/**" access="isAuthenticated()" />
    <intercept-url pattern="/listAccounts.html" access="isAuthenticated()" />
    <intercept-url pattern="/post.html" access="hasAnyRole('supervisor','teller')" />
    <intercept-url pattern="/**" access="denyAll" />
    <form-login />
</http>

从上面的配置可以看出,我必须维护url模式列表。是否有一种方法可以简化此过程,即每个用户都必须通过“/login”登录才能访问任何其他页面

编辑:

我已按如下所示编辑了我的配置,其工作方式与我预期的一致

<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/login" access="permitAll" />
    <intercept-url pattern="/loginfailed" access="permitAll" />
    <intercept-url pattern="/logout" access="permitAll" />
    <form-login login-page="/login" default-target-url="/welcome"
        authentication-failure-url="/loginfailed" />
    <logout logout-success-url="/login" />
    <intercept-url pattern="/**" access="isAuthenticated()" />
</http>

url规则按从上到下的顺序进行检查。第一个匹配的是所使用的

在本例中,最后一行

<intercept-url pattern="/**" access="denyAll" />

这是“一网打尽”的规则。它适用于所有不符合上面任何规则的请求(“/**”)

在它的当前形式中,它拒绝所有人的访问,不管是谁。如果你把它改成

<intercept-url pattern="/**" access="isAuthenticated()" />


相反,除非另有规定,否则它将要求对所有页面进行身份验证,这将导致spring security将未经身份验证的用户重定向到登录过程。

url规则是按从上到下的顺序检查的。第一个匹配的是所使用的

在本例中,最后一行

<intercept-url pattern="/**" access="denyAll" />

这是“一网打尽”的规则。它适用于所有不符合上面任何规则的请求(“/**”)

在它的当前形式中,它拒绝所有人的访问,不管是谁。如果你把它改成

<intercept-url pattern="/**" access="isAuthenticated()" />


相反,除非另有规定,否则需要对所有页面进行身份验证,这将导致spring security将未经身份验证的用户重定向到登录过程。

我已在帖子中更新了配置。谢谢你的帮助。我已经在我的帖子上更新了我的配置。谢谢你的帮助。