【发布时间】:2018-11-15 09:09:39
【问题描述】:
在 Cloud Foundry 中,我对其进行了配置,以便将客户端证书转发到我的 Spring Boot 应用程序。
证书放在x-forwarded-client-cert 标头中,spring boot 应用程序读取这个?,并检查 CN 是否被列入白名单并发送适当的响应。不幸的是,我无法通过测试复制这种行为。我不断得到(在调试输出中):
“请求中未找到客户端证书”
我正在使用 REST Assured,我的测试如下所示:
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-----" 和 "-----END CERTIFICATE-----" 已被删除,换行符也被删除(如您在上面的代码中所见)。
在我的 application.yml 我有这个:
server:
ssl:
enabled: false
key-store:
key-store-password:
trust-store:
trust-store-password:
client-auth: need
扩展WebSecurityConfigurerAdapter 的类的configure 方法如下所示:
http
.x509()
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(customUserDetailsService)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.csrf().disable();
任何帮助/建议将不胜感激。
谢谢。
【问题讨论】:
标签: spring-boot spring-security cloud-foundry mutual-authentication