问题1:权限受限无法访问
由于采用的Shiro安全框架,需要在配置类ShiroConfig
下的Shiro 的过滤器链放行该页面:【添加:filterChainDefinitionMap.put("/swagger-ui.html", "anon");
】
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
//整个shiro执行过程: 过滤器、认证、授权
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//设置安全管理器
shiroFilterFactoryBean.setSecurityManager(securityManager);
LinkedHashMap<String, Filter> filtersMap = new LinkedHashMap<>();
//用来校验token
filtersMap.put("token", new CustomAccessControlFilter());
shiroFilterFactoryBean.setFilters(filtersMap);
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
// 配置不会被拦截的链接 顺序判断
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
shiroFilterFactoryBean.setLoginUrl("/login_page");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
问题2:报错
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback
在WebInterceptorConfig
类中定义注册的资源处理器对外暴露资源.
public class WebInterceptorConfig extends WebMvcConfigurationSupport {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
"classpath:/static/");
registry.addResourceHandler("doc.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler("/swagger-ui.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
}