1. 新建能够从数据库中读取资源权限并构建FilterChainDefinitionMap的工程类
public class FilterChainDefinitionMapFactory { public LinkedHashMap<String,String> build(){ LinkedHashMap<String,String> map = new LinkedHashMap<>() ; /* <property name="filterChainDefinitions"> <!–anon表示可不需要登录态–> <!–authc表示需要登录态–> <!–前面的优先被匹配–> <value> /test/hello.do = anon /user/login.do = anon /page/admin.do = roles[admin] /page/*.do = roles[user] /** = authc </value> </property> */ map.put("/test/hello.do","anon") ; map.put("/user/login.do","anon") ; map.put("/page/admin.do","roles[admin]") ; map.put("/page/*.do","roles[user]") ; map.put("/**","authc") ; return map ; } }
2. 在spring-context-shiro.xml文件中进行如下配置