spring - 春季启动安全性要求意外授权
问题描述
我正在使用 spring boot 进行身份验证项目。我使用了spring starter security,但我面临的问题是我想允许所有人访问某些页面。但是 spring 也要求在使用这些网页时进行身份验证。
我试过这段代码:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests().antMatchers("/","/signUp").permitAll().anyRequest().authenticated()
.and()
.httpBasic();
}
我也使用了以下代码,但也没有按照我描述的预期方式工作并要求身份验证
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests().antMatchers("/").permitAll()
.and()
.httpBasic();
}
预计无需身份验证即可访问这些页面,但它要求进行身份验证。
解决方案
尝试 .antMatchers(HttpMethod.Method,"/endpoint")
并/**
使用configure(HttpSecurity http)
@Override
protected void configure(HttpSecurity http) throws Exception{
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/**","/signUp").permitAll()
.antMatchers(HttpMethod.POST,"/endpointPOST").permitAll()
.antMatchers(HttpMethod.GET,"/endpointGET").permitAll()
.anyRequest().authenticated();
}
如果您想绕过某些端点的安全过滤器链,请使用configure(WebSecurity web)
.
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/signUp", "**/endpoint/**");
}
推荐阅读
- android - Loading WebView prevents other views from being loaded in the layout
- linux - 看门狗不遵循被监视的过程
- c++ - move semantics and cv::Mat
- php - single array value in multiple array
- gmail - GmailApi 发送中的 RFC822 消息 ID
- node.js - express-handlebars cant find dir or file
- java - java的.Net Socket.Handle等价物是什么
- php - 计算学生排名
- amazon-web-services - How to copy or duplicate an AWS Lambda function
- java - 如果在搜索列表以查看它是否包含值时条件未能评估为真