java - 没有使用 Spring Security 进行身份验证和授权

标签 java spring authentication spring-security authorization

我的项目要求我使用 Spring Security 进行 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();
    }
}

关于java - 没有使用 Spring Security 进行身份验证和授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29138483/

相关文章:

java - 将操作保存在for循环内

java - 如何在 ComboBox 上使用 ActionListener 为变量赋值

java - Jersey Web 服务发送 415 状态代码

java - 如何在不增加文件限制的情况下用 Java 打开 20000 个客户端?

java - 无法执行目标 org.springframework.boot :spring-boot-maven-plugin:1. 5.8.RELEASE:run

java - src/main/resources 中的文件不在类路径中

authentication - 具有基本身份验证的 Solr 4

php - 使用 simplesamlphp 1.10 和 cakePHP 2.3 不起作用

c# - AuthenticationManager.SignIn() 不存在于 AuthenticationManager 类中

java - 使用 .pem 文件在 java 中发送 https 请求