当前位置: 首页 > 工具软件 > bootshiro > 使用案例 >

spring boot shiro anno不启作用

宦烈
2023-12-01

在shiro做我的权限控制框架时,经常会自定义权限过滤器,并且给不需要权限控制的url加上anno标记,例如:

@Bean
	public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
		ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
		// Shiro的核心安全接口,这个属性是必须的
		shiroFilterFactoryBean.setSecurityManager(securityManager);
		// Shiro连接约束配置,即过滤链的定义
		LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
		// 对静态资源设置匿名访问
		filterChainDefinitionMap.put("/favicon.ico**", "anon");
		filterChainDefinitionMap.put("/ruoyi.png**", "anon");
		filterChainDefinitionMap.put("/css/**", "anon");
		filterChainDefinitionMap.put("/docs/**", "anon");
		filterChainDefinitionMap.put("/fonts/**", "anon");
		filterChainDefinitionMap.put("/img/**", "anon");
		filterChainDefinitionMap.put("/ajax/**", "anon");
		filterChainDefinitionMap.put("/js/**", "anon");
		filterChainDefinitionMap.put("/ruoyi/**", "anon");
		filterChainDefinitionMap.put("/druid/**", "anon");
		filterChainDefinitionMap.put("/druid/**", "anon");
		filterChainDefinitionMap.put("/configuration/security", "anon");
		filterChainDefinitionMap.put("/configuration/ui", "anon");
		filterChainDefinitionMap.put("/systemlogin/annologin", "anon");
		filterChainDefinitionMap.put("/favicon.ico", "anon");
		Map<String, Filter> filters = new LinkedHashMap<>();
		filters.put("auth", jwtFiler());
		shiroFilterFactoryBean.setFilters(filters);

		// 所有请求需要认证
		filterChainDefinitionMap.put("/**", "auth");
		shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);

		return shiroFilterFactoryBean;
	}
    @Bean
	public BJwtFilter jwtFiler() {
		BJwtFilter jwtFilter = new BJwtFilter();
		return jwtFilter;
	}

项目在运行时发现anno没有起作用,anno过滤的url都走了auth过滤,这是什么原因呢,不清楚,那么怎么解决呢,很简单,不要将过滤器注册到容器中即可,自己手动创建过滤器!!

 类似资料: