本文整理汇总了Java中org.wildfly.security.auth.client.AuthenticationContext.captureCurrent方法的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationContext.captureCurrent方法的具体用法?Java AuthenticationContext.captureCurrent怎么用?Java AuthenticationContext.captureCurrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wildfly.security.auth.client.AuthenticationContext
的用法示例。
在下文中一共展示了AuthenticationContext.captureCurrent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openConnection
import org.wildfly.security.auth.client.AuthenticationContext; //导入方法依赖的package包/类
/**
* Connect and register at the remote domain controller.
*
* @return connection the established connection
* @throws IOException
*/
protected Connection openConnection() throws IOException {
// Perhaps this can just be done once?
CallbackHandler callbackHandler = null;
SSLContext sslContext = null;
if (realm != null) {
sslContext = realm.getSSLContext();
CallbackHandlerFactory handlerFactory = realm.getSecretCallbackHandlerFactory();
if (handlerFactory != null) {
String username = this.username != null ? this.username : localHostName;
callbackHandler = handlerFactory.getCallbackHandler(username);
}
}
final ProtocolConnectionConfiguration config = ProtocolConnectionConfiguration.copy(configuration);
config.setCallbackHandler(callbackHandler);
config.setSslContext(sslContext);
config.setUri(uri);
AuthenticationContext authenticationContext = this.authenticationContext != null ? this.authenticationContext : AuthenticationContext.captureCurrent();
// Connect
try {
return authenticationContext.run((PrivilegedExceptionAction<Connection>) () -> ProtocolConnectionUtils.connectSync(config));
} catch (PrivilegedActionException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
}
throw new IOException(e);
}
}
示例2: connect
import org.wildfly.security.auth.client.AuthenticationContext; //导入方法依赖的package包/类
private static IoFuture<Connection> connect(final CallbackHandler handler, final ProtocolConnectionConfiguration configuration) throws IOException {
configuration.validate();
final Endpoint endpoint = configuration.getEndpoint();
final URI uri = configuration.getUri();
String clientBindAddress = configuration.getClientBindAddress();
AuthenticationContext captured = AuthenticationContext.captureCurrent();
AuthenticationConfiguration mergedConfiguration = AUTH_CONFIGURATION_CLIENT.getAuthenticationConfiguration(uri, captured);
if (handler != null) {
mergedConfiguration = mergedConfiguration.useCallbackHandler(handler, DEFAULT_CALLBACK_KINDS);
}
Map<String, String> saslOptions = configuration.getSaslOptions();
mergedConfiguration = configureSaslMechanisms(saslOptions, isLocal(uri), mergedConfiguration);
// Pass through any other SASL options from the ProtocolConnectionConfiguration
// When we merge these, any pre-existing options already associated with the
// AuthenticationConfiguration will take precedence.
if (saslOptions != null) {
saslOptions = new HashMap<>(saslOptions);
// Drop SASL_DISALLOWED_MECHANISMS which we already handled
saslOptions.remove(Options.SASL_DISALLOWED_MECHANISMS.getName());
mergedConfiguration = mergedConfiguration.useMechanismProperties(saslOptions);
}
SSLContext sslContext = configuration.getSslContext();
if (sslContext == null) {
try {
sslContext = AUTH_CONFIGURATION_CLIENT.getSSLContext(uri, captured);
} catch (GeneralSecurityException e) {
throw ProtocolLogger.ROOT_LOGGER.failedToConnect(uri, e);
}
}
// WFCORE-2342 check for default SSL / TLS options
final OptionMap.Builder builder = OptionMap.builder();
OptionMap optionMap = configuration.getOptionMap();
for (Option option : optionMap) {
builder.set(option, optionMap.get(option));
}
if (optionMap.get(Options.SSL_ENABLED) == null)
builder.set(Options.SSL_ENABLED, configuration.isSslEnabled());
if (optionMap.get(Options.SSL_STARTTLS) == null)
builder.set(Options.SSL_STARTTLS, configuration.isUseStartTLS());
AuthenticationContext authenticationContext = AuthenticationContext.empty();
authenticationContext = authenticationContext.with(MatchRule.ALL, mergedConfiguration);
final SSLContext finalSslContext = sslContext;
authenticationContext = authenticationContext.withSsl(MatchRule.ALL, () -> finalSslContext);
if (clientBindAddress == null) {
return endpoint.connect(uri, builder.getMap(), authenticationContext);
} else {
InetSocketAddress bindAddr = new InetSocketAddress(clientBindAddress, 0);
return endpoint.connect(uri, bindAddr, builder.getMap(), authenticationContext);
}
}