spring-cloud / spring-cloud/spring-cloud-commons

Provided custom ssl context gets overriden when using autoconfiguration for apache httpclient

Open
#945 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Java
Stars
751
Forks
744
Avg merge
1d 14h
Merged PRs (30d)
9

Description

Describe the bug
Spring Cloud version: 3.0.1
In our project I had to provide our own keystore/truststore for spring-cloud-openfeign with apache httpclient. I wanted to leave as much as I could for autoconfig and I also saw that RegistryBuilder is available 👇

https://github.com/spring-cloud/spring-cloud-openfeign/blob/96268d16dafcabb38e9829b0b42d9f783d862852/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java#L165-L171

But it looks like the SSLConnectionSocketFactory gets overriden when invoking DefaultApacheHttpClientConnectionManagerFactory.newConnectionManager(...). What looks suspicious to me are lines:
https://github.com/spring-cloud/spring-cloud-commons/blob/087b94a905c5428c89e4db22a6a284999d5d0a7d/spring-cloud-commons/src/main/java/org/springframework/cloud/commons/httpclient/DefaultApacheHttpClientConnectionManagerFactory.java#L77-L80
RegistryBuilder contains a map underneath, so when I would try to provide my own SSLConnectionSocketFactory then it gets overriden.

Not sure if this should be posted as a bug, but it gave me a bit of a head scratch. For now I've decided to extend the DefaultApacheHttpClientConnectionManagerFactory bean and pass to connection manager our own SSLContext. Maybe someone comes here and finds this helpful.

Sample
I've created a test case for this issue here 👇 Hope the sample gives clear information about what happens.
https://github.com/krasowskiM/spring-cloud-commons/commit/c986b81f918e736c0fdf7a7df6b7a85bc0faa2fe

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with spring-cloud-commons/src/main/java/org/springframework/cloud/commons/httpclient/DefaultApacheHttpClientConnectionManagerFactory.java around lines 77-80, then compare it with the RegistryBuilder setup in FeignAutoConfiguration.java around lines 165-171. Reproduce the behavior using the sample commit and verify that a caller-provided SSLConnectionSocketFactory is not overridden when creating the connection manager.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.