天天看點

shiro(5)-重點研究的urls配置

在shiro.ini 中配置的結點urls可能是shiro中處理web項目比較核心的部分,在這裡邊配置各個過濾器的規則。

如果你想使用需要在web.xml中配置

可以動态的設定shiro.ini的路徑,一種是寫到配置檔案中,一種是使用程式加載。

在web.xml中可以動态配置shiro.ini的位置

示例如下:

還有一種方式是通過應用程式加載

根據示例中的spring-hibernate

配置

設定filterchaindefinitions屬性,就可以将設定中的值動态的加載到對應的ini類中。也可以實作加載配置過濾器的效果。

shiro.ini的[urls]節點

節點下的配置資訊如下格式

url_ant_path_expression = path_specific_filter_chain

指定對應的url執行的過濾器鍊。

如果出現下面的這種過濾情況

則下面的預設永遠都不執行,即通路/account/signup/index.html 的時候,隻執行上面的過濾器,不執行下面的。

如果shiro提供的過濾器不能滿足要求,則可以使用自定義的過濾器,設定的規則如下:

shiro中預設的過濾器

過濾器名稱

過濾器類

描述

anon

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/anonymousfilter.html">org.apache.shiro.web.filter.authc.anonymousfilter</a>

匿名過濾器

authc

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/formauthenticationfilter.html">org.apache.shiro.web.filter.authc.formauthenticationfilter</a>

如果繼續操作,需要做對應的表單驗證否則不能通過

authcbasic

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/basichttpauthenticationfilter.html">org.apache.shiro.web.filter.authc.basichttpauthenticationfilter</a>

基本http驗證過濾,如果不通過,跳轉屋登入頁面

logout

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/logoutfilter.html">org.apache.shiro.web.filter.authc.logoutfilter</a>

登入退出過濾器

nosessioncreation

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/session/nosessioncreationfilter.html">org.apache.shiro.web.filter.session.nosessioncreationfilter</a>

沒有session建立過濾器

perms

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/permissionsauthorizationfilter.html">org.apache.shiro.web.filter.authz.permissionsauthorizationfilter</a>

權限過濾器

port

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/portfilter.html">org.apache.shiro.web.filter.authz.portfilter</a>

端口過濾器,可以設定是否是指定端口如果不是跳轉到登入頁面

rest

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/httpmethodpermissionfilter.html">org.apache.shiro.web.filter.authz.httpmethodpermissionfilter</a>

http方法過濾器,可以指定如post不能進行通路等

roles

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/rolesauthorizationfilter.html">org.apache.shiro.web.filter.authz.rolesauthorizationfilter</a>

角色過濾器,判斷目前使用者是否指定角色

ssl

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/sslfilter.html">org.apache.shiro.web.filter.authz.sslfilter</a>

請求需要通過ssl,如果不是跳轉回登入頁

user

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/userfilter.html">org.apache.shiro.web.filter.authc.userfilter</a>

如果通路一個已知使用者,比如記住我功能,走這個過濾器

當然也可以設定過濾器的使用或者禁用:

對應的設定如下:

基本表單登入

在login.jsp中

在不連接配接資料庫的情況下