首页 > 解决方案 > 特定 API 春季启动的基本身份验证 - 返回 200 ok 但意外正文

问题描述

我正在使用 spring boot 和 java 构建 Web 应用程序。在实现外部 API 的过程中,所有请求都返回相同的响应 - 200 ok 但奇怪的 Json 主体甚至不存在于 API 响应中。

邮递员测试 java 调用。

这是我的控制器: 我的控制器:

还有我的 webConfigure :

`

@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
public void configure(WebSecurity web) throws Exception {

    web.ignoring().antMatchers("/readJson/**" , "/auth/**" , "/ratehawk/**");

}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.cors().and().csrf().disable().exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
            .antMatchers("/readJson/**").permitAll().anyRequest().authenticated();
    

    http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
}

} `

如果有人知道为什么会这样?谢谢你最好的问候伊丹

标签: javaspringspring-bootweb-applicationsbasic-authentication

解决方案


推荐阅读