javaspringwebclientspring-webclientsslcontext

Can we use same webclient for diff ssl contexts?


I have a need to call different services with different ssl contexts. Do I need to use diff webclients for this or is there a way I can use just one?


Solution

  • Your question depends on how you want to or need to set up the client for each of the sites that you want to connect to. In talking with you in the comments, I now understand that:

    1. You want to connect to HTTPS protected sites that are using self-signed SSL certificates

    2. You don't want to authenticate those certificates, but rather just want to ignore all certificate checking by the client.

    Since you just want to create a client that ignores the SSL certificates of the sites your connecting to, then you can follow the instructions in the link you provided, this one, and you should be able to use just one client configured this way to connect to any number of sites.

    Even if you wanted to check and trust the self-signed certificates from these sites you want to access, you could probably do it with a single client. All you'd need to do is register each cert with the client so that it would trust that cert. You can have a client trust multiple certs by putting them each into the same trust store that is being used by the client.

    So the short answer here is No, you shouldn't need to create more than one client.