In 云铸造厂我已对其进行配置,以便将客户端证书转发到我的 Spring Boot 应用程序。
该证书被放置在x-forwarded-client-cert
header 中,spring boot 应用程序读取 this?,并检查 CN 是否已列入白名单并发送适当的响应。不幸的是,我无法通过测试复制这种行为。我不断得到(在调试输出中):
“请求中找不到客户端证书”
我在用着放心我的测试如下所示:
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());
其基本 uri 是http://localhost
。客户证书“-----BEGIN CERTIFICATE-----"
and "-----END CERTIFICATE-----"
已被删除并且换行符也被删除(如您在上面的代码中看到的)。
在我的 application.yml 中我有这个:
server:
ssl:
enabled: false
key-store:
key-store-password:
trust-store:
trust-store-password:
client-auth: need
The configure
扩展类的方法WebSecurityConfigurerAdapter
看起来像这样:
http
.x509()
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(customUserDetailsService)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.csrf().disable();
任何帮助/建议将不胜感激。
Thanks.