In Cloud Foundry I have it configured so that a client certificate is forwarded to my spring boot application.
The certificate is placed in a x-forwarded-client-cert
header, the spring boot application reads this?, and checks if the CN is whitelisted and sends the appropriate response. Unfortunately I am unable to replicate this behavior via a test. I keep on getting (in debug output):
"no client certificate found in request"
I'm using REST Assured and my test looks like this:
String cert = StreamUtils.copyToString(
new ClassPathResource("certs/client/client_mod.crt").getInputStream(), Charset.defaultCharset());
cert = cert.replace("\r\n", "").replace("\n", "");
given()
.spec(spec)
.header("x-forwarded-client-cert", cert)
.when()
.get(HealthResource.BASE_URL + "/ip-reverse-lookup")
.then()
.statusCode(HttpStatus.OK.value());
The base uri for this is http://localhost
. The client certificate "-----BEGIN CERTIFICATE-----"
and "-----END CERTIFICATE-----"
has been removed and the newlines are removed (as you can see in the code above).
In my application.yml I have this:
server:
ssl:
enabled: false
key-store:
key-store-password:
trust-store:
trust-store-password:
client-auth: need
The configure
method of the class that extends WebSecurityConfigurerAdapter
looks like this:
http
.x509()
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(customUserDetailsService)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.csrf().disable();
Any help/suggestions would be appreciated.
Thanks.