昨天配置了jwt,结果打开swagger的doc.html时一直显示需要用户名和密码。原来是jwt拦截了,只需要在配置shiro时加上以下内容:
/**
* 定义拦截器链,所有请求都经过自定义的jwt过滤器
*
* @return
*/
@Bean
public ShiroFilterChainDefinition shiroFilterChainDefinition(){
DefaultShiroFilterChainDefinition definition = new DefaultShiroFilterChainDefinition();
Map<String,String> map = new LinkedHashMap<>();
map.put("/login","anon");
map.put("/swagger-ui.html","anon");
map.put("/doc.html","anon");
map.put("/webjars/**","anon");
map.put("/swagger-resources","anon");
map.put("/v2/api-docs","anon");
map.put("/swagger-resources/**","anon");
map.put("/**","jwt");
definition.addPathDefinitions(map);
return definition;
}
之前自己只写了 map.put("/doc.html",“anon”);,难怪会被拦截,原来还拦截了那么多访问路径,所以其他的路径也需要设置anon权限(即可以匿名访问)