当前位置: 首页>>代码示例>>Java>>正文


Java DispatchingAuthenticator类代码示例

本文整理汇总了Java中com.burgstaller.okhttp.DispatchingAuthenticator的典型用法代码示例。如果您正苦于以下问题:Java DispatchingAuthenticator类的具体用法?Java DispatchingAuthenticator怎么用?Java DispatchingAuthenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DispatchingAuthenticator类属于com.burgstaller.okhttp包,在下文中一共展示了DispatchingAuthenticator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getClient

import com.burgstaller.okhttp.DispatchingAuthenticator; //导入依赖的package包/类
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;
    }
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:44,代码来源:WebDavStorage.java

示例2: GerritApiClient

import com.burgstaller.okhttp.DispatchingAuthenticator; //导入依赖的package包/类
GerritApiClient(String endpoint, Authorization authorization,
        PlatformAbstractionLayer abstractionLayer) {
    mAbstractionLayer = abstractionLayer;
    mEndPoint = endpoint;
    mCookieManager = new CookieManager(toUnauthenticatedEndpoint(mEndPoint));

    Authorization auth = authorization;
    if (auth == null) {
        auth = new Authorization();
    }

    DispatchingAuthenticator authenticator = null;
    if (!auth.isAnonymousUser()) {
        final Credentials credentials = new Credentials(auth.mUsername, auth.mPassword);
        final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(credentials);
        final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(credentials);
        authenticator = new DispatchingAuthenticator.Builder()
                .with("digest", digestAuthenticator)
                .with("basic", basicAuthenticator)
                .requireAuthScheme(false)
                .build();
    }

    // OkHttp client
    OkHttpClient.Builder clientBuilder = auth.mTrustAllCertificates
            ? OkHttpHelper.getUnsafeClientBuilder() : OkHttpHelper.getSafeClientBuilder();
    clientBuilder
            .readTimeout(20000, java.util.concurrent.TimeUnit.MILLISECONDS)
            .cookieJar(mCookieManager)
            .followRedirects(true)
            .followSslRedirects(true)
            .addInterceptor(createConnectivityCheckInterceptor())
            .addInterceptor(createLoggingInterceptor())
            .addInterceptor(createHeadersInterceptor(auth));
    if (!auth.isAnonymousUser()) {
        final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
        clientBuilder
                .authenticator(new CachingAuthenticatorDecorator(authenticator, authCache))
                .addInterceptor(new AuthenticationCacheInterceptor(authCache));
    }
    OkHttpClient client = clientBuilder.build();

    // Gson adapter
    GsonConverterFactory gsonFactory = GsonConverterFactory.create(
            GsonHelper.createGerritGsonBuilder(true, mAbstractionLayer).create());

    // RxJava adapter
    RxJava2CallAdapterFactory rxAdapter = RxJava2CallAdapterFactory.create();

    // Retrofit
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpoint)
            .client(client)
            .addConverterFactory(gsonFactory)
            .addCallAdapterFactory(rxAdapter)
            .build();

    // Build the api
    mService = retrofit.create(GerritRestApi.class);
}
 
开发者ID:jruesga,项目名称:rview,代码行数:61,代码来源:GerritApiClient.java


注:本文中的com.burgstaller.okhttp.DispatchingAuthenticator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。