Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 弹簧防尘套x509测试-pcf_Spring Boot_Spring Security_Cloud Foundry_Mutual Authentication - Fatal编程技术网

Spring boot 弹簧防尘套x509测试-pcf

Spring boot 弹簧防尘套x509测试-pcf,spring-boot,spring-security,cloud-foundry,mutual-authentication,Spring Boot,Spring Security,Cloud Foundry,Mutual Authentication,在Cloud Foundry中,我对其进行了配置,以便将客户端证书转发给我的spring boot应用程序 证书被放置在x-forwarded-client-cert头中,spring boot应用程序读取此?,并检查CN是否被列入白名单,并发送相应的响应。不幸的是,我无法通过测试复制这种行为。我一直(在调试输出中)得到: “在请求中找不到客户端证书” 我使用的是“放心”,我的测试如下所示: String cert = StreamUtils.copyToString( new ClassP

Cloud Foundry中,我对其进行了配置,以便将客户端证书转发给我的spring boot应用程序

证书被放置在
x-forwarded-client-cert
头中,spring boot应用程序读取此?,并检查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());
http
  .x509()
  .subjectPrincipalRegex("CN=(.*?)(?:,|$)")
  .userDetailsService(customUserDetailsService)
  .and()
  .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
  .and()
  .csrf().disable();
此的基本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
扩展
websecurityConfigureAdapter
的类的
configure
方法如下所示:

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());
http
  .x509()
  .subjectPrincipalRegex("CN=(.*?)(?:,|$)")
  .userDetailsService(customUserDetailsService)
  .and()
  .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
  .and()
  .csrf().disable();
如有任何帮助/建议,将不胜感激


谢谢。

由于集装箱化和网络化体系结构,您需要在实施和测试时考虑以下几点

当您将Cloud Foundry配置为检查客户端证书(如果存在)是否可信时,将根据受信任的CA/证书检查它们。这是在CF环境的一般网络组件的HAProxy上完成的。正如您正确指出的,它(如果包含并受信任)被放入
x-forwarded-client-cert
中,该证书被保护为不可从外部更改

应用程序在较低级别的容器中运行,并通过HAProxy/GoRouter连接到其公共主机名/url。当请求到达应用程序时,此时就不再有TLS级别的证书(确切地说是mTLS)。SSL连接在HAProxy上终止。在内部,应用程序/容器以HTTP的形式接收请求。 有关更多详细信息,请参阅


因此,您的Spring应用程序只在添加到请求的头中接收关于X.509/mTLS证书的信息。因此,向Spring应用程序添加/配置x509支持是没有意义的,因为没有真正的MTL会到达端点。这也是您收到上面发布的日志消息的原因。相反,您需要让您的应用程序读取标题,并根据标题执行逻辑。

谢谢您的回答,我非常感谢。我不太记得我后来(当时)是如何处理这件事的,但上面是一个很好的解释。