这只是关于配置。它说这些元素将在配置文件的标记中从上到下进行评估:<intercept-url>
<http />
<http auto-config="true">
<intercept-url pattern="/**" access="isAuthenticated" />
<intercept-url pattern="/login.jsp" access="permitAll" />
</http>
在上面的示例中,我们尝试仅允许经过身份验证的用户访问所有内容,当然,除了登录页面(用户必须首先登录,对吧?!但是,根据文档,这不起作用,因为不太具体的匹配位于顶部。因此,(其中一个)完成此示例目标的正确配置是:
<http auto-config="true">
<intercept-url pattern="/login.jsp" access="permitAll" />
<intercept-url pattern="/**" access="isAuthenticated" />
</http>
将更具体的匹配放在顶部。
引用的最后一件事是关于HTTP方法的。您可以使用它来指定匹配项,因此:
<http auto-config="true">
<intercept-url pattern="/client/edit" access="isAuthenticated" method="GET" />
<intercept-url pattern="/client/edit" access="hasRole('EDITOR')" method="POST" />
</http>
在第二个示例中,要通过 GET 进行访问,用户只需要进行身份验证,但要通过 POST 进行访问(例如,提交编辑表单),用户需要具有该角色。在某些地方可能不鼓励这种URL模式,但这只是一个例子。/client/edit
/client/edit
EDITOR