Shiro之从数据库初始化角色权限信息
生活随笔
收集整理的這篇文章主要介紹了
Shiro之从数据库初始化角色权限信息
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <!-- Shiro的核心安全接口,這個屬性是必須的 --> <property name="securityManager" ref="securityManager"></property> <!-- 未認證,要跳轉(zhuǎn)的url,非必須的屬性,默認會自動尋找Web工程根目錄下的"/login.jsp"頁面 --> <property name="loginUrl" value="/loginPage"></property> <!-- 未授權,要跳轉(zhuǎn)的url --> <property name="unauthorizedUrl" value="/unauthorizedPage"></property> <property name="filterChainDefinitions"><!-- anon:可以匿名訪問 authc:必須認證登錄后才能訪問 --> <value> /loginPage=anon/doLogin=anon/doLogout=anon/page1 = roles[role1]/page2 = roles[role2] /*=authc </value> </property> </bean>
以上filterChainDefinitions是純手工配置,但實際應從數(shù)據(jù)庫讀取
新建一個FilterChainDefinitionMapBuilder
public class FilterChainDefinitionMapBuilder {public LinkedHashMap<String, String> buildFilterChainDefinitionMap(){LinkedHashMap<String, String> map = new LinkedHashMap<>();//從數(shù)據(jù)庫讀取省略... map.put("/loginPage", "anon");map.put("/doLogin", "anon");map.put("/doLogout", "anon");map.put("/page1", "roles[role1]");map.put("/page2", "roles[role2]");map.put("/**", "authc");return map;}}xml修改如下
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <!-- Shiro的核心安全接口,這個屬性是必須的 --> <property name="securityManager" ref="securityManager"></property> <!-- 未認證,要跳轉(zhuǎn)的url,非必須的屬性,默認會自動尋找Web工程根目錄下的"/login.jsp"頁面 --> <property name="loginUrl" value="/loginPage"></property> <!-- 未授權,要跳轉(zhuǎn)的url --> <property name="unauthorizedUrl" value="/unauthorizedPage"></property> <property name="filterChainDefinitionMap" ref="filterChainDefinitionMap"></property></bean><!-- 配置一個 bean, 該 bean 實際上是一個 Map. 通過實例工廠方法的方式 -->
<bean id="filterChainDefinitionMap" factory-bean="filterChainDefinitionMapBuilder" factory-method="buildFilterChainDefinitionMap"></bean><bean id="filterChainDefinitionMapBuilder" class="com.zns.shiro.FilterChainDefinitionMapBuilder"></bean>轉(zhuǎn)載于:https://www.cnblogs.com/zengnansheng/p/10389596.html
總結
以上是生活随笔為你收集整理的Shiro之从数据库初始化角色权限信息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tomcat之Windows下安装
- 下一篇: ubuntu双系统把win7设置为默认启