国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Shiro

2019-11-14 21:42:06
字體:
來源:轉載
供稿:網友
Shiro - 與SPRing集成

本文是針對web應用web.xml:

<filter>  <filter-name>shiroFilter</filter-name>  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  <init-param>    <param-name>targetFilterLifecycle</param-name>    <param-value>true</param-value>  </init-param></filter>                          <filter-mapping><!-- Make sure any request you want accessible to Shiro is filtered. /* catches all --><!-- requests.  Usually this filter mapping is defined first (before all others) to --><!-- ensure that Shiro works in subsequent filters in the filter chain:             -->  <filter-name>shiroFilter</filter-name>  <url-pattern>/*</url-pattern>  <dispatcher>REQUEST</dispatcher>  <dispatcher>FORWARD</dispatcher>  <dispatcher>INCLUDE</dispatcher>  <dispatcher>ERROR</dispatcher></filter-mapping>

參數TargetFilterLifecycle:缺省值為false,即生命周期由Spring app context管理。設置為true時由servlet container管理。

配置applicationContext.xml:

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">    <property name="securityManager" ref="securityManager"/>                                                                                                                                                    <!-- 配置要跳轉的URL -->    <property name="loginUrl" value="/login.jsp"/>    <property name="successUrl" value="/main.jsp"/>    <property name="unauthorizedUrl" value="/err404.jsp"/>                                                                                                                                                    <!-- 配置過濾策略 切記這是FIRST MATCH WINS -->    <property name="filterChainDefinitions">        <value>            /download/** = user            /images/** = anon            /admin/** = authc, roles[admin]            /docs/** = authc, perms[document:read]            /** = authc            /logout.html = logout        </value>    </property></bean>                                                                                                                                                <bean id="myRealm" class="king.common.security.MyRealm"></bean><bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">    <property name="realm" ref="myRealm" /></bean><bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

另外,DefaultSecurityManager繼承RealmSecurityManager。因此,當需要多個realm時可以使用"realms"property。ShiroFilterFactoryBean提供了Filters屬性,關于Filters:This property is optional: this {@code FactoryBean} implementation will discover all beans in the web application context that implement the {@link Filter} interface and automatically add them to this filter map under their bean name.

如果需要的話可以配置一下,如:

<property name="filters">    <util:map>        <entry key="myAlias1" value-ref="myFilter1"/>    </util:map></property>

filterChainDefinitions這一property的set方法是這樣定義的:

public void setFilterChainDefinitions(String definitions) {    Ini ini = new Ini();    ini.load(definitions);    //did they explicitly state a 'urls' section?  Not necessary, but just in case:    Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS);    if (CollectionUtils.isEmpty(section)) {        //no urls section.  Since this _is_ a urls chain definition property, just assume the        //default section contains only the definitions:        section = ini.getSection(Ini.DEFAULT_SECTION_NAME);    }    setFilterChainDefinitionMap(section);}

于是我們便可以使用filterChainDefinitionMap這一property。我們可以寫一個繼承FactoryBean<Section>的類動態構成一個filterChainDefinitionMap。(Ps:Section是實現Map<String,String>的Ini的靜態內部類。)

另外,如果希望使用注解:

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>                                                                                                <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">    <property name="securityManager" ref="securityManager"/></bean>


上一篇:java的軟件包

下一篇:Shiro

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 慈利县| 松潘县| 商水县| 西充县| 汽车| 乐亭县| 依兰县| 保康县| 汾西县| 板桥市| 巧家县| 广饶县| 阿克苏市| 江达县| 从江县| 睢宁县| 南江县| 台南县| 环江| 大厂| 渭源县| 昔阳县| 泊头市| 河北区| 江华| 巩义市| 吉林市| 和硕县| 壶关县| 体育| 长春市| 台前县| 凌海市| 田东县| 宁河县| 库车县| 沙湾县| 东兴市| 阳新县| 阳高县| 辛集市|