本文整理汇总了Java中org.apache.http.impl.auth.SPNegoSchemeFactory类的典型用法代码示例。如果您正苦于以下问题:Java SPNegoSchemeFactory类的具体用法?Java SPNegoSchemeFactory怎么用?Java SPNegoSchemeFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SPNegoSchemeFactory类属于org.apache.http.impl.auth包,在下文中一共展示了SPNegoSchemeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProxyClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
public ProxyClient(final HttpParams params) {
super();
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
new RequestContent(),
new RequestTargetHost(),
new RequestClientConnControl(),
new RequestUserAgent(),
new RequestProxyAuthentication()
} );
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthState();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
this.reuseStrategy = new DefaultConnectionReuseStrategy();
this.params = params;
}
示例2: createAuthSchemeRegistry
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
protected AuthSchemeRegistry createAuthSchemeRegistry() {
AuthSchemeRegistry registry = new AuthSchemeRegistry();
registry.register(
AuthPolicy.BASIC,
new BasicSchemeFactory());
registry.register(
AuthPolicy.DIGEST,
new DigestSchemeFactory());
registry.register(
AuthPolicy.NTLM,
new NTLMSchemeFactory());
registry.register(
AuthPolicy.SPNEGO,
new SPNegoSchemeFactory());
registry.register(
AuthPolicy.KERBEROS,
new KerberosSchemeFactory());
return registry;
}
示例3: getHttpClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
private SystemDefaultHttpClient getHttpClient() {
final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
Credentials use_jaas_creds = new Credentials() {
public String getPassword() {
return null;
}
public Principal getUserPrincipal() {
return null;
}
};
httpClient.getCredentialsProvider().setCredentials(
AuthScope.ANY, use_jaas_creds);
return httpClient;
}
示例4: getHttpClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
private SystemDefaultHttpClient getHttpClient() {
final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
Credentials use_jaas_creds = new Credentials() {
public String getPassword() {
return null;
}
public Principal getUserPrincipal() {
return null;
}
};
httpClient.getCredentialsProvider().setCredentials(
AuthScope.ANY, use_jaas_creds);
return httpClient;
}
示例5: createAuthSchemeRegistry
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
protected AuthSchemeRegistry createAuthSchemeRegistry() {
final AuthSchemeRegistry registry = new AuthSchemeRegistry();
registry.register(
AuthPolicy.BASIC,
new BasicSchemeFactory());
registry.register(
AuthPolicy.DIGEST,
new DigestSchemeFactory());
registry.register(
AuthPolicy.NTLM,
new NTLMSchemeFactory());
registry.register(
AuthPolicy.SPNEGO,
new SPNegoSchemeFactory());
registry.register(
AuthPolicy.KERBEROS,
new KerberosSchemeFactory());
return registry;
}
示例6: ProxyClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
/**
* @since 4.3
*/
public ProxyClient(
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
final ConnectionConfig connectionConfig,
final RequestConfig requestConfig) {
super();
this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
this.httpProcessor = new ImmutableHttpProcessor(
new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthState();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
this.authSchemeRegistry.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory());
this.reuseStrategy = new DefaultConnectionReuseStrategy();
}
示例7: getHttpClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的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;
}
示例8: getHttpClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的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;
}
示例9: addSpnego
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的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);
}
示例10: AvaticaCommonsHttpClientSpnegoImpl
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的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();
}
示例11: KerberosHttpClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
private KerberosHttpClient(String user, String password, String domain, String kdc) {
try {
File krb5Config = createKrb5Configuration(domain, kdc);
File loginConfig = createLoginConfiguration();
System.setProperty("java.security.auth.login.config", loginConfig.toURI().toString());
System.setProperty("java.security.krb5.conf", krb5Config.toURI().toString());
System.setProperty("sun.security.krb5.debug", "false");
//Change this property to true, if you want debug output.
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
RegistryBuilder<AuthSchemeProvider> registryBuilder = RegistryBuilder.create();
String id = AuthSchemes.SPNEGO;
SPNegoSchemeFactory schemeFactory = new SPNegoSchemeFactory(SKIP_PORT_AT_KERBEROS_DATABASE_LOOKUP);
Lookup<AuthSchemeProvider> authSchemeRegistry = registryBuilder.register(id, schemeFactory).build();
client = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry)
.setConnectionManager(createConnectionManager()).build();
httpContext = getHttpContext();
loginContext = getLoginContext(user, password);
//without it, authentication will be failed.
final Subject subject = loginContext.getSubject();
final HttpGet get = new HttpGet(KerberosBpmClient.this.rootUri);
Subject.doAs(subject, this.privilegedExecute(get, httpContext));
} catch (Exception e) {
logger.error("Can't create Kerberos client!");
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例12: httpClientFactory
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
protected CloseableHttpClient httpClientFactory() throws CannotInitializeDataAdapterException {
try {
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(
createSslCustomContext(),
null,
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
RegistryBuilder<AuthSchemeProvider> schemeProviderBuilder = RegistryBuilder.create();
schemeProviderBuilder.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(null, -1, null),
new Credentials() {
@Override
public Principal getUserPrincipal() {
return null;
}
@Override
public String getPassword() {
return null;
}
});
return HttpClients.custom()
.setDefaultAuthSchemeRegistry(schemeProviderBuilder.build())
.setDefaultCredentialsProvider(credsProvider)
.setSSLSocketFactory(csf)
.build();
} catch (IOException | UnrecoverableKeyException | CertificateException | NoSuchAlgorithmException | KeyStoreException | NoSuchProviderException | KeyManagementException e) {
throw new CannotInitializeDataAdapterException("Could not initialize adapter to source '" + this.getSourceName() + "': " + e.getMessage(), e);
}
}
示例13: main
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
System.setProperty("java.security.auth.login.config", ClientKerberosAuthentication.class.getResource("/jaas_login.conf").toExternalForm());
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
String targetUrl;
if (args.length < 1) {
throw new IllegalArgumentException("Please specify a target URL");
}
targetUrl = args[0];
/* ***********************************************************************************************/
RegistryBuilder<AuthSchemeProvider> schemeProviderBuilder = RegistryBuilder.create();
schemeProviderBuilder.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
new Credentials() {
@Override
public Principal getUserPrincipal() {
System.out.print("Get principal!");
return null;
}
@Override
public String getPassword() {
System.out.print("Get pwd!");
return null;
}
});
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(schemeProviderBuilder.build())
.setDefaultCredentialsProvider(credsProvider)
.build();
doGet(httpClient, targetUrl);
httpClient.close();
}
示例14: createSpnegoAwareHttpContext
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
private HttpContext createSpnegoAwareHttpContext()
{
HttpClientContext httpContext = HttpClientContext.create();
Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, useCanonicalHostname)).build();
httpContext.setAuthSchemeRegistry(authSchemeRegistry);
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(null, -1, null), new NullCredentials());
httpContext.setCredentialsProvider(credentialsProvider);
return httpContext;
}
示例15: getHttpClient
import org.apache.http.impl.auth.SPNegoSchemeFactory; //导入依赖的package包/类
private static HttpClient getHttpClient()
{
Credentials use_jaas_creds = new Credentials()
{
public String getPassword()
{
return null;
}
public Principal getUserPrincipal()
{
return null;
}
};
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
Registry<AuthSchemeProvider> authSchemeRegistry
= RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build();
return HttpClients.custom()
.setDefaultAuthSchemeRegistry(authSchemeRegistry)
.setDefaultCredentialsProvider(credentialsProvider)
.build();
}