Java 类org.apache.http.impl.auth.win.WindowsCredentialsProvider 实例源码

项目:purecloud-iot    文件:WinHttpClients.java   
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();
    }
}
项目:geoevent-datastore-proxy    文件:GeoEventDataStoreProxy.java   
private HttpContext createContextForServer(ServerInfo serverInfo)
{
    HttpContext httpContext = null;
    if (serverInfo.credentials != null || serverInfo.ntCredentials != null)
    {
        HttpClientContext context = HttpClientContext.create();
        CredentialsProvider credsProvider = (useBuiltinWindowsAuthentication(serverInfo)) ? credsProvider = new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider()) : 
                                                                                                              new HttpClientCredentialsProvider(serverInfo.credentials, serverInfo.ntCredentials);
        if (serverInfo.credentials != null)
        {
            credsProvider.setCredentials(serverInfo.authscope, serverInfo.credentials);
        }
        if (serverInfo.ntCredentials != null)
        {
            credsProvider.setCredentials(serverInfo.authscope, serverInfo.ntCredentials);
        }
        context.setCredentialsProvider(credsProvider);
        httpContext = context;
    }
    return httpContext;
}
项目:byps    文件:AsfClient.java   
private static HttpClientContext internalCreateSSOContext() {

  if (log.isDebugEnabled()) log.debug("internalCreateSSOContext(");

  //System.setProperty("java.security.krb5.conf", "C:\\Windows\\krb5.ini");
  //System.setProperty("sun.security.krb5.debug", "true");
  System.setProperty("javax.security.auth.useSubjectCredsOnly","false");

  HttpClientContext context = HttpClientContext.create();

  if (isNTLMAuthenticationEnabled()) {
    if (log.isDebugEnabled()) log.debug("set WindowsCredentialsProvider");
    final CredentialsProvider credsProvider = new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
    context.setCredentialsProvider(credsProvider);
  }
  else {

    if (log.isDebugEnabled()) log.debug("set JAAS credential provider");

    // This may seem odd, but specifying 'null' as principal tells java to use the logged in user's credentials
    Credentials useJaasCreds = new Credentials() {
      public String getPassword() { return null; }
      public Principal getUserPrincipal() { return null; }
    };

    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials( new AuthScope(null, -1, null), useJaasCreds );
    context.setCredentialsProvider(credentialsProvider);
  }

  if (log.isDebugEnabled()) log.debug(")internalCreateSSOContext");
  return context;
}