mahesh kamath
mahesh kamath

Reputation: 345

How do we perform trust manager refresh in a Spring boot application?

Spring boot doesn't pick my custom trust manager instance, even though I install it before the tomcat boots up.

SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
SSLContext.setDefault(sslContext);

Does boot shadow the default SSL settings?

Is there a way to overrule this?

Upvotes: 0

Views: 2240

Answers (1)

marioosh
marioosh

Reputation: 28566

Put Your SSL config in @PostConstruct. Method with this annotation will be called by Spring container after bean creation by dependency injection mechanism.

@Component
public class SomeComponent {

    @PostConstruct
    public void sslContextConfiguration() {
        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, new TrustManager[] { trustManager }, null);
           SSLContext.setDefault(sslContext);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Upvotes: 2

Related Questions