java - Spring boot 所有请求未授权

标签 java spring spring-boot spring-mvc spring-security

即使添加 http.authorizeRequests().anyRequest().permitAll(); 所有请求都是未经授权的。

这是我的WebSecurityConfig:

@Configuration
@EnableWebSecurity 
@EnableGlobalMethodSecurity(
        securedEnabled = true,
        jsr250Enabled = true,
        prePostEnabled = true)   
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
UserDetailsServiceImpl userDetailsService;

@Autowired
private AuthEntryPointJwt unauthorizedHandler;

@Bean
public AuthTokenFilter authenticationJwtTokenFilter() {
    return new AuthTokenFilter();
}

@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
    authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().anyRequest().permitAll();
}

我有什么遗漏吗?

编辑:我还在 application.properties 中添加了此配置

security.basic.enable: false security.ignored=/**

最佳答案

配置类看起来不错。确保在运行项目之前“构建”您的项目。我复制了您的配置文件,它对我有用。

关于java - Spring boot 所有请求未授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62374169/

相关文章:

java - 计算树中的后代

java - 我无法通过 javamelody 监控 spring 应用程序

java - 为什么 Spring 解析我的日期是错误的?

spring-boot - Spring boot 中配置服务器的多个搜索路径

java - 如何在 spring-boot 中完全禁用 swagger-ui?(/swagger-ui.html 应该返回 404)

java - 如何在与用户界面线程分开的服务中使用 Androids 位置包?

java - 读取 anchor JSoup 中的数据

java - AuthenticationEntryPoint 仅有时被称为

spring - 在 spring boot 中使用 pageable 获取和删除对象

java - 如何使用java仅保存zip文件并删除其他文件夹?