Skip to content

Commit

Permalink
SSLUtils, more code factorisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-brandizi committed Oct 23, 2024
1 parent 86271a9 commit d34a978
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/main/java/uk/ac/ebi/utils/opt/net/SSLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void checkServerTrusted ( X509Certificate[] certs, String authType ) {/**
private static final DefaultClientTlsStrategy FAKE_TLS_STRATEGY;
private static final HttpClientConnectionManager FAKE_HTTP_CLIENT_CONNECTION_MANAGER;

private static final AuthScope FAKE_CLIENT_CREDENTIALS = new AuthScope ( null, -1 );

static
{
try
Expand Down Expand Up @@ -152,20 +154,19 @@ public static void trustAllHttpsCertificates ()
* that does basic {@link BasicCredentialsProvider HTTP Auth}.
*/
public static HttpClient noCertClient ( String user, String pwd )
{
BasicCredentialsProvider credsProvider = null;
if ( user != null )
{
credsProvider = new BasicCredentialsProvider ();
Credentials credentials = new UsernamePasswordCredentials ( user, pwd.toCharArray () );
credsProvider.setCredentials ( new AuthScope ( null, -1 ), credentials );
}

{
HttpClientBuilder builder = HttpClients
.custom()
.setConnectionManager ( FAKE_HTTP_CLIENT_CONNECTION_MANAGER );

if ( credsProvider != null ) builder.setDefaultCredentialsProvider ( credsProvider );
if ( user != null )
{
var credsProvider = new BasicCredentialsProvider ();
Credentials credentials = new UsernamePasswordCredentials ( user, pwd.toCharArray () );
credsProvider.setCredentials ( FAKE_CLIENT_CREDENTIALS, credentials );

builder.setDefaultCredentialsProvider ( credsProvider );
}

return builder.build();
}
Expand Down

0 comments on commit d34a978

Please sign in to comment.