I have a Spring Boot application which has some endpoints:
/.wellknownwhich does not require any authentication and open to public/callbackwhich requires mTLS (only cert authentication).
For the above requirement, I cannot find a exact implementation. Most of the implementation
- find enables mTLS at server level - meaning all APIs are mTLS enabled.
- with X.509 Certificate check which checks for certificate and user data (In my case there is no user data involved - its only server to server mTLS).
Found below code:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
/*
* Enables x509 client authentication.
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.x509()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.csrf()
.disable();
// @formatter:on
}
/*
* Create an in-memory authentication manager. We create 1 user (localhost which
* is the CN of the client certificate) which has a role of USER.
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("localhost").password("none").roles("USER");
}
}
Please help on how to implement the same
/callback- check if the client gives the cert and is available in trust-store/.well-known/No mTLS check respond without any check
/.well-known/, so you could enable mTLS in server configuration.