问题描述
升级Shiro版本后,请求URL带中文,返回400错误,如图:
解决方案
①重写ShiroFilterFactoryBean.createFilterChainManager,设置blockNonAscii为false:
public class PlugShiroFilterFactoryBean extends org.apache.shiro.spring.web.ShiroFilterFactoryBean {
@Override
protected FilterChainManager createFilterChainManager() {
FilterChainManager manager = super.createFilterChainManager();
Map<String, Filter> filterMap = manager.getFilters();
Filter invalidRequestFilter = filterMap.get( DefaultFilter.invalidRequest.name() );
if (invalidRequestFilter instanceof InvalidRequestFilter) {
((InvalidRequestFilter)invalidRequestFilter).setBlockNonAscii(false); // 跳过校验
}
return manager;
}
}
②ShiroFilterFactoryBean替换为PlugShiroFilterFactoryBean:
@Bean("shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean(BeanFactory beanFactory) {
ShiroFilterFactoryBean factoryBean = new PlugShiroFilterFactoryBean();
// ......
return factoryBean;
}