没有使用 Spring 安全性的身份验证和授权
No Authentication and authorization using Spring Security
我的项目要求我使用 Spring 安全来保护 CSRF 和 XSS,但不使用它来进行身份验证和授权。我已将 SS 配置到我的应用程序中,但每次我访问页面时,它都会自动将我重定向到它的登录页面。我该如何禁用它?我的 SecurityConfig
文件是:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
}
}
下面给出的 SecurityConfig
将允许所有请求不经过身份验证,但会有 CSRF 和 XSS 守卫:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}
}
如下配置 spring 安全配置以及所需的 spring 安全依赖项。亲自对其进行测试,以确保它具备您需要的一切。
package org.springframework.security.samples.config;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("**").permitAll().and().csrf()
.and().headers().frameOptions().sameOrigin().xssProtection();
}
}
我的项目要求我使用 Spring 安全来保护 CSRF 和 XSS,但不使用它来进行身份验证和授权。我已将 SS 配置到我的应用程序中,但每次我访问页面时,它都会自动将我重定向到它的登录页面。我该如何禁用它?我的 SecurityConfig
文件是:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
}
}
下面给出的 SecurityConfig
将允许所有请求不经过身份验证,但会有 CSRF 和 XSS 守卫:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}
}
如下配置 spring 安全配置以及所需的 spring 安全依赖项。亲自对其进行测试,以确保它具备您需要的一切。
package org.springframework.security.samples.config;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("**").permitAll().and().csrf()
.and().headers().frameOptions().sameOrigin().xssProtection();
}
}