shiro权限不生效原因
记录一次shiro权限不生效原因。
访问权限配置不能是HashMap,必须使用LinkedHashMap。其实根本原因就是顺序的问题。
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//给ShiroFilter配置安全管理器
shiroFilterFactoryBean.setSecurityManager(securityManager());
Map<String, Filter> maps=new HashMap<>();
maps.put("admin", new AdminFilter());
shiroFilterFactoryBean.setFilters(maps);
//配置系统受限资源
//配置系统公共资源
Map<String, String> map = new LinkedHashMap<>();
//登出
map.put("/logout", "logout");
//对所有用户认证
map.put("/mlogin", "anon");
map.put("/index", "anon");
map.put("/register", "anon");
map.put("/static/**", "anon");
map.put("/managesignin", "anon");
map.put("/admin/login", "anon");
map.put("/admin/login.html", "anon");
map.put("/admin/**", "admin");
// 设置认证界面路径
//登录
shiroFilterFactoryBean.setLoginUrl("/admin/login");
//首页
shiroFilterFactoryBean.setSuccessUrl("/admin/index");
//错误页面,认证不通过跳转
///demo/src/main/webapp/error.html
shiroFilterFactoryBean.setUnauthorizedUrl("/error");
shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
return shiroFilterFactoryBean;