shiro setFilterChainDefinitionMap 多个路径不生效问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/woaiqianzhige/article/details/84662546

shiro setFilterChainDefinitionMap 多个路径不生效问题


		Map<String, String> map = new HashMap<>();
		
		map.put("/cms/admin/**", "perms[admin]");
		
		map.put("/cms/appeal/**", "perms[appeal]");
	
		map.put("/cms/broadcast/**", "perms[broadcast]");
	
		map.put("/cms/notice/**", "perms[notice]");
	
		map.put("/cms/auth/premier/**", "perms[premier]");

		map.put("/cms/auth/merchant/**", "perms[merchant]");

		map.put("/cms/appupdate/**", "perms[appupdate]");
	
		map.put("/cms/bb_order/**", "perms[bb_order]");
	
		map.put("/cms/otc_order/**", "perms[otc_order]");
	
		map.put("/cms/user/**", "perms[user]");

		map.put("/cms/permission/**", "authc");

		map.put("/cms/tt/**", "authc");
	
		map.put("/cms/loginOut", "authc"); 
	
		map.put("/cms/login", "anon");

		map.put("/**", "anon"); 

		//没登录访问controller页面
		shiroFilterFactoryBean.setLoginUrl("/cms/notLogin");
		shiroFilterFactoryBean.setUnauthorizedUrl("/cms/notAuth");

		shiroFilterFactoryBean.setFilterChainDefinitionMap(map);


上面拦截了十几个路径,每个路径需要有不同的权限才能访问,最后还有其他接口 用 /**表示,不进行拦截,但是,遇到的问题是,总有几个路径无法进行拦截,
后来找到了原因,我们将路径加入到map中,在setFilterChainDefinitionMap,可hashmap是无序的,到filter里面顺序就变了,可能最后一个/**会先遍历到
所以直接不需要权限了,拦截失败。这里将hashmap换成LinkedHashMap,解决问题

猜你喜欢

转载自blog.csdn.net/woaiqianzhige/article/details/84662546