欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Apache Shiro 使用手冊(cè)(五) Shiro 配置說(shuō)明

 更新時(shí)間:2014年06月09日 23:41:56   作者:  
這篇文章主要為大家分享了Apache Shiro 配置說(shuō)明,需要的朋友可以參考下

Apache Shiro的配置主要分為四部分:

對(duì)象和屬性的定義與配置
URL的過(guò)濾器配置
靜態(tài)用戶配置
靜態(tài)角色配置
其中,由于用戶、角色一般由后臺(tái)進(jìn)行操作的動(dòng)態(tài)數(shù)據(jù),因此Shiro配置一般僅包含前兩項(xiàng)的配置。

Apache Shiro的大多數(shù)組件是基于POJO的,因此我們可以使用POJO兼容的任何配置機(jī)制進(jìn)行配置,例如:Java代碼、Sping XML、YAML、JSON、ini文件等等。下面,以Spring XML的配置方式為例,并且對(duì)其中的一些配置參數(shù)進(jìn)行一些簡(jiǎn)單說(shuō)明。

Shiro對(duì)象的配置:
主要是對(duì)Shiro各個(gè)組件的實(shí)現(xiàn)進(jìn)行定義配置,主要組件在前文已做過(guò)簡(jiǎn)單介紹,這里不再一一說(shuō)明。

復(fù)制代碼 代碼如下:

<bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
        <property name="cacheManager" ref="cacheManager"/>
        <property name="sessionMode" value="native"/>
        <!-- Single realm app.  If you have multiple realms, use the 'realms' property instead. -->
        <property name="realm" ref="myRealm"/>
        <property name="sessionManager" ref="sessionManager"/>
</bean>

Shiro過(guò)濾器的配置
Shiro主要是通過(guò)URL過(guò)濾來(lái)進(jìn)行安全管理,這里的配置便是指定具體授權(quán)規(guī)則定義。

復(fù)制代碼 代碼如下:

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager"/>
    <property name="loginUrl" value="/login.jsp"/>
    <property name="successUrl" value="/home.jsp"/>
    <property name="unauthorizedUrl" value="/unauthorized.jsp"/> -->
    <property name="filterChainDefinitions">
        <value>
            # some example chain definitions:
            /admin/** = authc, roles[admin]
            /docs/** = authc, perms[document:read]
            /** = authc
            # more URL-to-FilterChain definitions here
        </value>
    </property>
</bean>

URL過(guò)濾器配置說(shuō)明:

Shiro可以通過(guò)配置文件實(shí)現(xiàn)基于URL的授權(quán)驗(yàn)證。FilterChain定義格式:
URL_Ant_Path_Expression = Path_Specific_Filter_Chain
每個(gè)URL配置,表示匹配該URL的應(yīng)用程序請(qǐng)求將由對(duì)應(yīng)的過(guò)濾器進(jìn)行驗(yàn)證。
例如:
[urls]
/index.html = anon
/user/create = anon
/user/** = authc
/admin/** = authc, roles[administrator]
/rest/** = authc, rest
/remoting/rpc/** = authc, perms["remote:invoke"]

URL表達(dá)式說(shuō)明

1、URL目錄是基于HttpServletRequest.getContextPath()此目錄設(shè)置
2、URL可使用通配符,**代表任意子目錄
3、Shiro驗(yàn)證URL時(shí),URL匹配成功便不再繼續(xù)匹配查找。所以要注意配置文件中的URL順序,尤其在使用通配符時(shí)。

Filter Chain定義說(shuō)明

1、一個(gè)URL可以配置多個(gè)Filter,使用逗號(hào)分隔
2、當(dāng)設(shè)置多個(gè)過(guò)濾器時(shí),全部驗(yàn)證通過(guò),才視為通過(guò)
3、部分過(guò)濾器可指定參數(shù),如perms,roles

Shiro內(nèi)置的FilterChain

Filter Name Class
anon org.apache.shiro.web.filter.authc.AnonymousFilter
authc org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authcBasic org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
perms org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
port org.apache.shiro.web.filter.authz.PortFilter
rest org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
roles org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
ssl org.apache.shiro.web.filter.authz.SslFilter
user org.apache.shiro.web.filter.authc.UserFilter

相關(guān)文章

最新評(píng)論