小编lxn*_*xnx的帖子

Spring 安全 - 自定义 ExceptionTranslationFilter

这个问题其实是和这个issue相关的问题

根据@harsh-poddar 的建议,我相应地添加了过滤器。

但是,在添加之后,即使使用有效凭据,我似乎也无法登录。

以下是相关代码:

安全配置

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

//  @Bean
//  public CustomAuthenticationEntryPoint customAuthenticationEntryPoint() {
//      return new CustomAuthenticationEntryPoint();
//  }

@Bean
public CustomExceptionTranslationFilter customExceptionTranslationFilter() {
    return new CustomExceptionTranslationFilter(new CustomAuthenticationEntryPoint());
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        //Note : Able to login without this filter, but after adding this, valid credential also fails
        .addFilterAfter(customExceptionTranslationFilter(), ExceptionTranslationFilter.class)
//      .exceptionHandling()
//          .authenticationEntryPoint(new customAuthenticationEntryPoint())
//          .and()
        .authorizeRequests()
            .anyRequest().authenticated()
            .and()
        .requestCache()
            .requestCache(new NullRequestCache())
            .and()
        .httpBasic() …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security

3
推荐指数
1
解决办法
5611
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1

spring-security ×1