css - 如何让spring security允许访问静态资源?
问题描述
我决定在我的应用程序中添加一些 CSS,但由于 Spring 安全性,它无法正常工作。这是我试图解决的问题。1)添加到mvcConfig
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
2)将此添加到 webSecurityConfig
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**");
}
3)我也有这个方法
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/","/registration","/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
- 我也将此添加到 application.properties 文件中:
spring.mvc.static-path-pattern=/resources/**
这些方法都不适合我。如果有人处理过这个问题,请帮忙
如果对我的项目有帮助,您可以查看整个项目
ps 我只是春天的初学者,所以不要评判我
解决方案
您也必须忽略 css 目录。
@Component
public class SecurityConfig implements WebSecurityConfigurer {
@Override
public void configure(WebSecurity web) {
web
.ignoring()
.antMatchers("/css/**")
.antMatchers("/js/**")
.antMatchers("/images/**")
.antMatchers("/resources/**");
}
}
推荐阅读
- kubernetes - 通过 Kubernetes 上的 IPVS 负载均衡器公开多个服务(或服务实例)
- php - Envelope':在 php 中验证 SOAP 响应时,没有可用于验证根错误的匹配全局声明
- sql - 如何从父字符串中分离结果?
- javascript - 在javascript中使用while循环重新提示用户输入
- git - 恢复由于 Head 分离而意外丢失的提交
- mysql - 如何删除基于 2 列的旧重复行但保留最新行?
- ios - 如何将用户选择的颜色设置为整个 IOS App 的背景颜色?
- akka-stream - 有没有办法使用 akka-http 从查询参数中获取流?
- laravel - 结果的分页未按预期工作
- c - fread 似乎正在从右到左读取文件