2

I'm in the process of setting up a Spring Boot Admin application - although what exactly this application does is irrelevant in this context. What is important is that this application connects to another service using HTTPS.

What I have a problem with is the certificate - both services run in docker containers on more than one environment. This, plus the fact that the service discovery resolves services using IP addresses causes issues when certificate is validated. My plan was to - at least for development purposes - allow hosts to be connected to as long as the IP address is local. To do so I've written a MyHostnameVerifier class which implements HostnameVerifier. Then created a configuration class with a bean that would set this new HostnameVerifier to be a default one like so:

@Configuration
public class SecurityConfiguration {

    private class MyHostnameVerifier implements HostnameVerifier {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            // checks if IP address is local..
            return true;
        }
    }

    @PostConstruct
    public void configureSSL() {
        HttpsURLConnection.setDefaultHostnameVerifier(new MyHostnameVerifier());
    }
}

What I have a problem with is that the implemented MyHostnameVerifier.verify method in the custom class never gets called. What's the reason for this?

configureSSL method does get called.

J_S
  • 2,985
  • 3
  • 15
  • 38
  • https://stackoverflow.com/questions/38957851/run-a-void-setup-method-in-spring-context-configuration The `configureSSL()` method probably never gets called. – Serg Vasylchak Jul 22 '19 at 14:46
  • @SergVasylchak That's not it. I did change `@Bean` to `@PostConstruct` annotation but the behavior doesn't change - `MyHostnameVerifier.verify` is still not called, while `configureSSL()` does get called (and it did before also). What I'm suspecting is that Spring somehow overrides the default HostnameVerified. – J_S Jul 23 '19 at 05:19
  • @JacekŚlimok did you find a solution? – user1123432 Oct 30 '20 at 08:07

0 Answers0