java - Spring Security — 'Full authentication is required to access this resource' 表示不存在的端点

标签 java spring spring-boot spring-security

当我尝试访问不存在的端点时,即使成功通过授权,AuthenticationEntryPoint 也会触发。如何让它进入 404 页面?

这是我的 Spring Security 配置

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    return http
            .cors().and()
            .csrf().disable()
            .exceptionHandling()
            .authenticationEntryPoint(customAuthenticationEntryPoint()).and()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
            .authorizeHttpRequests()
            .requestMatchers("/api/auth/**").permitAll()
            .anyRequest().authenticated().and()
            .addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class)
            .build();
}

最佳答案

您需要允许对 /error 路径的所有请求。

.requestMatchers("/error").permitAll()

关于java - Spring Security — 'Full authentication is required to access this resource' 表示不存在的端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75858723/

相关文章:

Java Codelab 字母计数器

java - ObjectOutputStream 永远挂起

java - 如果 firebase 数据库没有子值,则开始下一个 Activity

Spring Batch - 读取多行日志消息

Spring @RequestMapping 消耗字符集?

docker - 从一个 Docker 容器连接到另一个 Docker 容器

java - 使用注释将所有返回的元素放入 Spring-Boot 缓存中

java - Spring Singleton VS Singleton 设计模式——类加载器

java - 带有 envers 的应用程序在架构验证 : REV column is of wrong type - found [int8 (Types#BIGINT)], 上失败,但需要 [int4 (Types#INTEGER)]

java - RxJava Observable 在 SpringBoot 项目中运行