use of com.burgstaller.okhttp.basic.BasicAuthenticator in project keepass2android by PhilippC.
the class WebDavStorage method getClient.
private OkHttpClient getClient(ConnectionInfo ci) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
com.burgstaller.okhttp.digest.Credentials credentials = new com.burgstaller.okhttp.digest.Credentials(ci.username, ci.password);
final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(credentials);
final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(credentials);
// note that all auth schemes should be registered as lowercase!
DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder().with("digest", digestAuthenticator).with("basic", basicAuthenticator).build();
builder = builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache)).addInterceptor(new AuthenticationCacheInterceptor(authCache));
if ((mCertificateErrorHandler != null) && (!mCertificateErrorHandler.alwaysFailOnValidationError())) {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
}
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
trustManager = new DecoratedTrustManager(trustManager, mCertificateErrorHandler);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
builder = builder.sslSocketFactory(sslSocketFactory, trustManager).hostnameVerifier(new DecoratedHostnameVerifier(OkHostnameVerifier.INSTANCE, mCertificateErrorHandler));
}
OkHttpClient client = builder.build();
return client;
}
use of com.burgstaller.okhttp.basic.BasicAuthenticator in project okhttp-digest by rburgst.
the class ProxyAuthenticationManualTest method testConnection_WithProxyBasicAuthWithTunnel_Expect200.
@Test
public void testConnection_WithProxyBasicAuthWithTunnel_Expect200() throws IOException {
final BasicAuthenticator authenticator = givenBasicAuthenticator();
final OkHttpClient client = givenHttpClientWithProxyAuth(authenticator);
final Request request = new Request.Builder().url("https://www.google.com/favicon.ico").build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
}
use of com.burgstaller.okhttp.basic.BasicAuthenticator in project okhttp-digest by rburgst.
the class ProxyAuthenticationManualTest method testConnection_WithProxyBasicAuthWithNotAllowedSites_Expect403.
@Test
public void testConnection_WithProxyBasicAuthWithNotAllowedSites_Expect403() throws IOException {
final BasicAuthenticator authenticator = givenBasicAuthenticator();
final OkHttpClient client = givenHttpClientWithProxyAuth(authenticator);
final Request request = new Request.Builder().url("http://www.youtube.com").build();
Response response = client.newCall(request).execute();
assertEquals(403, response.code());
}
use of com.burgstaller.okhttp.basic.BasicAuthenticator in project okhttp-digest by rburgst.
the class ProxyAuthenticationManualTest method testConnection_WithProxyBasicAuthWithoutTunnel_Expect200.
@Test
public void testConnection_WithProxyBasicAuthWithoutTunnel_Expect200() throws IOException {
final BasicAuthenticator authenticator = givenBasicAuthenticator();
final OkHttpClient client = givenHttpClientWithProxyAuth(authenticator);
final Request request = new Request.Builder().url("http://edition.cnn.com").build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
}
Aggregations