shiro與spring結合配置時,首先在web.xml中配置一個filter: <!-- Shiro Security filter --> <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> <filter-name>shiroFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> filter-class使用的是spring的代理,使用它時需要filter-name與spring的配置中的bean名字相同。 targetFilterLifecycle 為true即讓spring管理這個filter的init, destory方法 然后在applicationContext-shiro.xml中加入相應的設置與屬性 <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager" /> <property name="loginUrl" value="/login.do" /> <property name="successUrl" value="/welcome" /> <property name="unauthorizedUrl" value="/403.html"/> <property name="filterChainDefinitions"> <value> /user/* = authc, perms[user:view] /user/* = authc, perms[admin:view] /admin/addAdmain* = authc, perms["admin:view,admin:add"] /admin/* == authc,perms[admin:view] /kaptcha* = anon /static/* = anon /login.html = anon /* = authc </value> </property> </bean> |
|
來自: 昵稱11608230 > 《java》