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


Java AuthSchemeProvider类代码示例

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


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

示例1: setUsernamePassword

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
@Override public void setUsernamePassword(AuthenticationType authType, String username,
    String password) {
  this.credentials = new UsernamePasswordCredentials(
      Objects.requireNonNull(username), Objects.requireNonNull(password));

  this.credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY, credentials);

  RegistryBuilder<AuthSchemeProvider> authRegistryBuilder = RegistryBuilder.create();
  switch (authType) {
  case BASIC:
    authRegistryBuilder.register(AuthSchemes.BASIC, new BasicSchemeFactory());
    break;
  case DIGEST:
    authRegistryBuilder.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
    break;
  default:
    throw new IllegalArgumentException("Unsupported authentiation type: " + authType);
  }
  this.authRegistry = authRegistryBuilder.build();
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:22,代码来源:AvaticaCommonsHttpClientImpl.java

示例2: build

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
public static HttpClient build(byte[] token) {
    HttpClientBuilder builder = HttpClientBuilder.create();
    Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
            .register(AuthSchemes.SPNEGO, new CollaredSPNegoSchemeFactory(token)).build();
    builder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(null, -1, null), new Credentials() {
        @Override
        public Principal getUserPrincipal() {
            return null;
        }

        @Override
        public String getPassword() {
            return null;
        }
    });
    builder.setDefaultCredentialsProvider(credentialsProvider);
    return builder.build();
}
 
开发者ID:tellisnz,项目名称:collared-kerberos,代码行数:21,代码来源:CollaredHttpClientFactory.java

示例3: InternalHttpClient

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
public InternalHttpClient(
        final ClientExecChain execChain,
        final HttpClientConnectionManager connManager,
        final HttpRoutePlanner routePlanner,
        final Lookup<CookieSpecProvider> cookieSpecRegistry,
        final Lookup<AuthSchemeProvider> authSchemeRegistry,
        final CookieStore cookieStore,
        final CredentialsProvider credentialsProvider,
        final RequestConfig defaultConfig,
        final List<Closeable> closeables) {
    super();
    Args.notNull(execChain, "HTTP client exec chain");
    Args.notNull(connManager, "HTTP connection manager");
    Args.notNull(routePlanner, "HTTP route planner");
    this.execChain = execChain;
    this.connManager = connManager;
    this.routePlanner = routePlanner;
    this.cookieSpecRegistry = cookieSpecRegistry;
    this.authSchemeRegistry = authSchemeRegistry;
    this.cookieStore = cookieStore;
    this.credentialsProvider = credentialsProvider;
    this.defaultConfig = defaultConfig;
    this.closeables = closeables;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:25,代码来源:InternalHttpClient.java

示例4: setUp

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    this.defltAuthStrategy = Mockito.mock(AuthenticationStrategy.class);
    this.authState = new AuthState();
    this.authScheme = Mockito.mock(ContextAwareAuthScheme.class);
    Mockito.when(this.authScheme.getSchemeName()).thenReturn("Basic");
    Mockito.when(this.authScheme.isComplete()).thenReturn(Boolean.TRUE);
    this.context = new BasicHttpContext();
    this.defaultHost = new HttpHost("localhost", 80);
    this.context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.defaultHost);
    this.credentials = Mockito.mock(Credentials.class);
    this.credentialsProvider = new BasicCredentialsProvider();
    this.credentialsProvider.setCredentials(AuthScope.ANY, this.credentials);
    this.context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
    this.authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register("basic", new BasicSchemeFactory())
        .register("digest", new DigestSchemeFactory())
        .register("ntlm", new NTLMSchemeFactory()).build();
    this.context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
    this.authCache = Mockito.mock(AuthCache.class);
    this.context.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache);
    this.httpAuthenticator = new HttpAuthenticator();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestHttpAuthenticator.java

示例5: testDontTryToAuthenticateEndlessly

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
/**
 * Tests that the client will stop connecting to the server if
 * the server still keep asking for a valid ticket.
 */
@Test
public void testDontTryToAuthenticateEndlessly() throws Exception {
    this.serverBootstrap.registerHandler("*", new PleaseNegotiateService());
    final HttpHost target = start();

    final AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager();
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    final Credentials use_jaas_creds = new UseJaasCredentials();
    credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);

    final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register(AuthSchemes.SPNEGO, nsf)
        .build();
    this.httpclient = HttpClients.custom()
        .setDefaultAuthSchemeRegistry(authSchemeRegistry)
        .setDefaultCredentialsProvider(credentialsProvider)
        .build();

    final String s = "/path";
    final HttpGet httpget = new HttpGet(s);
    final HttpResponse response = this.httpclient.execute(target, httpget);
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:30,代码来源:TestSPNegoScheme.java

示例6: testSelectNoCredentialsProvider

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
@Test
public void testSelectNoCredentialsProvider() throws Exception {
    final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
    final HttpHost authhost = new HttpHost("locahost", 80);
    final HttpClientContext context = HttpClientContext.create();

    final Map<String, Header> challenges = new HashMap<String, Header>();
    challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
    challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));

    final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register("basic", new BasicSchemeFactory())
        .register("digest", new DigestSchemeFactory()).build();
    context.setAuthSchemeRegistry(authSchemeRegistry);

    final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
    Assert.assertNotNull(options);
    Assert.assertEquals(0, options.size());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestAuthenticationStrategy.java

示例7: testNoCredentials

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
@Test
public void testNoCredentials() throws Exception {
    final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
    final HttpHost authhost = new HttpHost("locahost", 80);
    final HttpClientContext context = HttpClientContext.create();

    final Map<String, Header> challenges = new HashMap<String, Header>();
    challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
    challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));

    final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register("basic", new BasicSchemeFactory())
        .register("digest", new DigestSchemeFactory()).build();
    context.setAuthSchemeRegistry(authSchemeRegistry);

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    context.setCredentialsProvider(credentialsProvider);

    final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
    Assert.assertNotNull(options);
    Assert.assertEquals(0, options.size());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestAuthenticationStrategy.java

示例8: testExecuteLocalContext

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testExecuteLocalContext() throws Exception {
    final HttpGet httpget = new HttpGet("http://somehost/stuff");
    final HttpClientContext context = HttpClientContext.create();

    final Lookup<CookieSpecProvider> localCookieSpecRegistry = Mockito.mock(Lookup.class);
    final Lookup<AuthSchemeProvider> localAuthSchemeRegistry = Mockito.mock(Lookup.class);
    final CookieStore localCookieStore = Mockito.mock(CookieStore.class);
    final CredentialsProvider localCredentialsProvider = Mockito.mock(CredentialsProvider.class);
    final RequestConfig localConfig = RequestConfig.custom().build();

    context.setCookieSpecRegistry(localCookieSpecRegistry);
    context.setAuthSchemeRegistry(localAuthSchemeRegistry);
    context.setCookieStore(localCookieStore);
    context.setCredentialsProvider(localCredentialsProvider);
    context.setRequestConfig(localConfig);

    client.execute(httpget, context);

    Assert.assertSame(localCookieSpecRegistry, context.getCookieSpecRegistry());
    Assert.assertSame(localAuthSchemeRegistry, context.getAuthSchemeRegistry());
    Assert.assertSame(localCookieStore, context.getCookieStore());
    Assert.assertSame(localCredentialsProvider, context.getCredentialsProvider());
    Assert.assertSame(localConfig, context.getRequestConfig());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestInternalHttpClient.java

示例9: createBuilder

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
private static HttpClientBuilder createBuilder() {
    if (isWinAuthAvailable()) {
        final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
                .register(AuthSchemes.BASIC, new BasicSchemeFactory())
                .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
                .register(AuthSchemes.NTLM, new WindowsNTLMSchemeFactory(null))
                .register(AuthSchemes.SPNEGO, new WindowsNegotiateSchemeFactory(null))
                .build();
        final CredentialsProvider credsProvider = new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
        return HttpClientBuilder.create()
                .setDefaultCredentialsProvider(credsProvider)
                .setDefaultAuthSchemeRegistry(authSchemeRegistry);
    } else {
        return HttpClientBuilder.create();
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:WinHttpClients.java

示例10: getHttpClient

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
private HttpClient getHttpClient() {

        Credentials use_jaas_creds = new Credentials() {
            public String getPassword() {
                return null;
            }

            public Principal getUserPrincipal() {
                return null;
            }
        };

        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
        Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build();
        CloseableHttpClient httpclient = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCredentialsProvider(credsProvider).build();

        return httpclient;
    }
 
开发者ID:fthevenet,项目名称:binjr,代码行数:20,代码来源:HttpClientKerberosDoAS.java

示例11: getHttpClient

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
protected final CloseableHttpClient getHttpClient(final boolean useSpnego) throws Exception {

        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        final HttpClientBuilder hcb = HttpClients.custom();

        if (useSpnego) {
            //SPNEGO/Kerberos setup
            log.debug("SPNEGO activated");
            final AuthSchemeProvider nsf = new SPNegoSchemeFactory(true);//  new NegotiateSchemeProvider();
            final Credentials jaasCreds = new JaasCredentials();
            credsProvider.setCredentials(new AuthScope(null, -1, null, AuthSchemes.SPNEGO), jaasCreds);
            credsProvider.setCredentials(new AuthScope(null, -1, null, AuthSchemes.NTLM), new NTCredentials("Guest", "Guest", "Guest",
                    "Guest"));
            final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider> create()
                    .register(AuthSchemes.SPNEGO, nsf).register(AuthSchemes.NTLM, new NTLMSchemeFactory()).build();

            hcb.setDefaultAuthSchemeRegistry(authSchemeRegistry);
        }

        hcb.setDefaultCredentialsProvider(credsProvider);
        hcb.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(10 * 1000).build());
        final CloseableHttpClient httpClient = hcb.build();
        return httpClient;
    }
 
开发者ID:codecentric,项目名称:elasticsearch-shield-kerberos-realm,代码行数:25,代码来源:AbstractUnitTest.java

示例12: setupAuthentication

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
/**
 * Set up authentication for HTTP Basic/HTTP Digest/SPNEGO.
 *
 * @param httpClientBuilder The client builder
 * @return The context
 * @throws HttpException
 */
private void setupAuthentication( HttpClientBuilder httpClientBuilder ) throws HttpException {

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                                 new UsernamePasswordCredentials(username, password));
    httpClientBuilder.setDefaultCredentialsProvider(credsProvider);

    if (authType == AuthType.always) {
        AuthCache authCache = new BasicAuthCache();
        // Generate BASIC scheme object and add it to the local auth cache
        BasicScheme basicAuth = new BasicScheme();

        HttpHost target = new HttpHost(host, port, isOverSsl
                                                             ? "https"
                                                             : "http");
        authCache.put(target, basicAuth);

        // Add AuthCache to the execution context
        httpContext.setAuthCache(authCache);
    } else {
        if (!StringUtils.isNullOrEmpty(kerberosServicePrincipalName)) {
            GssClient gssClient = new GssClient(username, password, kerberosClientKeytab, krb5ConfFile);
            AuthSchemeProvider nsf = new SPNegoSchemeFactory(gssClient, kerberosServicePrincipalName,
                                                             kerberosServicePrincipalType);
            final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider> create()
                                                                                   .register(AuthSchemes.SPNEGO,
                                                                                             nsf)
                                                                                   .build();
            httpClientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:40,代码来源:HttpClient.java

示例13: addSpnego

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
public static void addSpnego(HttpClientBuilder clientBuilder) {
    //Add spnego http header processor
    Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider> create()
            .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build();
    clientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
    //There has to be at least this dummy credentials provider or apache http client gives up
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(null, -1, null), new NullCredentials());
    clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:11,代码来源:SpnegoHelper.java

示例14: select

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
@Override
public Queue<AuthOption> select(final Map<String, Header> challenges, final HttpHost authhost, final HttpResponse response, final HttpContext context) throws MalformedChallengeException {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if(registry == null) {
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = config.getProxyPreferredAuthSchemes();
    if(authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if(log.isDebugEnabled()) {
        log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for(final String id : authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ROOT));
        if(challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if(authSchemeProvider == null) {
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);
            final Credentials saved = keychain.getCredentials(authhost.getHostName());
            if(StringUtils.isEmpty(saved.getPassword())) {
                try {
                    final Credentials input = prompt.prompt(bookmark,
                        StringUtils.EMPTY,
                        String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), authhost.getHostName()),
                        authScheme.getRealm(),
                        new LoginOptions()
                            .icon(bookmark.getProtocol().disk())
                            .usernamePlaceholder(LocaleFactory.localizedString("Username", "Credentials"))
                            .passwordPlaceholder(LocaleFactory.localizedString("Password", "Credentials"))
                            .user(true).password(true)
                    );
                    if(input.isSaved()) {
                        context.setAttribute(PROXY_CREDENTIALS_INPUT_ID, input);
                    }
                    options.add(new AuthOption(authScheme, new NTCredentials(input.getUsername(), input.getPassword(),
                        preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain"))));
                }
                catch(LoginCanceledException ignored) {
                    // Ignore dismiss of prompt
                    throw new MalformedChallengeException(ignored.getMessage(), ignored);
                }
            }
            else {
                options.add(new AuthOption(authScheme, new NTCredentials(saved.getUsername(), saved.getPassword(),
                    preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain"))));
            }
        }
        else {
            if(log.isDebugEnabled()) {
                log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:65,代码来源:CallbackProxyAuthenticationStrategy.java

示例15: AvaticaCommonsHttpClientSpnegoImpl

import org.apache.http.auth.AuthSchemeProvider; //导入依赖的package包/类
/**
 * Constructs an HTTP client with user specified by the given credentials.
 *
 * @param url The URL for the Avatica server
 * @param credential The GSS credentials
 */
public AvaticaCommonsHttpClientSpnegoImpl(URL url, GSSCredential credential) {
  this.url = Objects.requireNonNull(url);

  pool = new PoolingHttpClientConnectionManager();
  // Increase max total connection to 100
  final String maxCnxns =
      System.getProperty(CACHED_CONNECTIONS_MAX_KEY, CACHED_CONNECTIONS_MAX_DEFAULT);
  pool.setMaxTotal(Integer.parseInt(maxCnxns));
  // Increase default max connection per route to 25
  final String maxCnxnsPerRoute = System.getProperty(CACHED_CONNECTIONS_MAX_PER_ROUTE_KEY,
      CACHED_CONNECTIONS_MAX_PER_ROUTE_DEFAULT);
  pool.setDefaultMaxPerRoute(Integer.parseInt(maxCnxnsPerRoute));

  this.host = new HttpHost(url.getHost(), url.getPort());

  this.authRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO,
      new SPNegoSchemeFactory(STRIP_PORT_ON_SERVER_LOOKUP, USE_CANONICAL_HOSTNAME)).build();

  this.credentialsProvider = new BasicCredentialsProvider();
  if (null != credential) {
    // Non-null credential should be used directly with KerberosCredentials.
    this.credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential));
  } else {
    // A null credential implies that the user is logged in via JAAS using the
    // java.security.auth.login.config system property
    this.credentialsProvider.setCredentials(AuthScope.ANY, EmptyCredentials.INSTANCE);
  }

  this.authCache = new BasicAuthCache();

  // A single thread-safe HttpClient, pooling connections via the ConnectionManager
  this.client = HttpClients.custom()
      .setDefaultAuthSchemeRegistry(authRegistry)
      .setConnectionManager(pool).build();
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:42,代码来源:AvaticaCommonsHttpClientSpnegoImpl.java


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