Spring boot 所有请求 未经授权

问题描述 投票:0回答:1

即使加上 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 spring-boot spring-mvc spring-security
1个回答
0
投票

配置类看起来不错。请确保 "建造" 你的项目在运行之前。我复制了你的配置文件,它为我工作。

© www.soinside.com 2019 - 2024. All rights reserved.