"X509AuthenticationFilter : No client certificate found in request" after upgrading app to Spring Boot 3.4.0 a

I am upgrading an application to use Spring Boot 3.4.0 and Java 17 (previously it was on Spring Boot 2.

I am upgrading an application to use Spring Boot 3.4.0 and Java 17 (previously it was on Spring Boot 2.1.5.RELEASE and Java 8). When deploying this app and trying to consume its web services I am getting a 403 response even when sending the Bearer token. After enabling Spring Security logs I am seeing this message:

o.s.s.w.a.p.x.X509AuthenticationFilter : No client certificate found in request.

This is the Spring Security config I am setting:

@Value("${x509.subject.principal.regex:CN=(.*?)(?:,|$)}")
private String subjectPrincipalRegex;

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
                .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.NEVER))
                .csrf(AbstractHttpConfigurer::disable)
                .x509(x509 -> x509.subjectPrincipalRegex(subjectPrincipalRegex).userDetailsService(userDetailsService()));
    return http.build();
}

@Bean
public UserDetailsService userDetailsService() {
    return username -> new User(username,
            "", AuthorityUtilsmaSeparatedStringToAuthorityList("ROLE_SSL_USER"));
}

And this is how it is configured on old Spring Boot and Java version which is working:

@Value("${x509.subject.principal.regex:CN=(.*?)(?:,|$)}")
private String subjectPrincipalRegex;

@Override
protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated().and().x509().subjectPrincipalRegex(subjectPrincipalRegex)
                .userDetailsService(userDetailsService());
        http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
}

@Bean
public UserDetailsService userDetailsService() {
    return username -> new User(username,
            "", AuthorityUtilsmaSeparatedStringToAuthorityList("ROLE_SSL_USER"));
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744028115a4546057.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信