Need to trust all the certificates during the development using Spring

后端 未结 1 510
野的像风
野的像风 2021-01-03 13:17

I read this very useful article about disabling all the https certificates programmatically. I need such approach only in the development. And I\'m using Spring. So does any

相关标签:
1条回答
  • 2021-01-03 13:58

    Yes - you can use init-method attribute. Look at Initialization callbacks. But this interface is not enough. I suggest simply placing this code

    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    

    In your custom class which will know that you are in dev mode or wchich will have such init-method. BTW calling getSocketFactory is simple - this is simply getting socketFactory property.

    0 讨论(0)
提交回复
热议问题