shiro中anon配置不生效
再配置shiro的时候,如下代码要注意:
1、下述代码中必须是LinkedHashMap 而不能是HashMap。
2、anon定义必须在authc之前
否则anon定义不生效
@Bean public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager){ ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean(); factoryBean.setSecurityManager(securityManager); // 设置登录跳转 factoryBean.setLoginUrl("/admin"); factoryBean.setSuccessUrl("/admin/index"); //必须为LinkedHashMap 否则anon不生效 Map<String,String> map = new LinkedHashMap<>(); //退出 map.put("/admin/logout","logout"); //登录页面和登录验证不要拦截 map.put("/admin/login.html","anon"); map.put("/admin/tologin","anon"); //设置需要过滤的链接 map.put("/admin/**","authc"); factoryBean.setFilterChainDefinitionMap(map); return factoryBean; }