本文共 1415 字,大约阅读时间需要 4 分钟。
一、shiro路径拦截配置
// TODO 重中之重啊,过滤顺序一定要根据自己需要排序 MapfilterChainDefinitionMap = new LinkedHashMap<>(); // 需要验证的写 authc 不需要的写 anon filterChainDefinitionMap.put("/resources/**", "anon"); //static开头的url可以匿名访问 filterChainDefinitionMap.put("/static/**", "anon"); filterChainDefinitionMap.put("/install", "anon"); filterChainDefinitionMap.put("/hello", "anon"); // anon:它对应的过滤器里面是空的,什么都没做 log.info("##################从数据库读取权限规则,加载到shiroFilter中##################"); // 不用注解也可以通过 API 方式加载权限规则 Map permissions = new LinkedHashMap<>(); permissions.put("/users/find", "perms[user:find]"); filterChainDefinitionMap.putAll(permissions); //所有url都必须认证通过才可以访问 filterChainDefinitionMap.put("/**", "authc");
二、设置url默认访问的静态资源路径
@Configurationpublic class WebMvcConfig implements WebMvcConfigurer { /** * @author xiaobu * @date 2019/1/18 13:51 * @param registry registry * @descprition 等价于 http://localhost:9001/1.txt 依次在static upload目录下找1.txt文件 * @version 1.0 */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); }}
由于/**被shiro拦截只有通过static开头的url来访问static如:下的静态资源文件
转载地址:http://cfgai.baihongyu.com/