這只是關於配置。上面說的是<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>
在第二個例子中,訪問/client/edit
通過獲取用戶只需要進行身份驗證,但通過POST訪問/client/edit
(可以說,提交編輯表單)用戶需要具有EDITOR
角色。有些地方可能不鼓勵這種網址模式,但它只是一個例子。