use of org.jboss.remoting3.UnknownURISchemeException in project wildfly-core by wildfly.
the class RemotingHttpUpgradeService method start.
@Override
public synchronized void start(final StartContext context) throws StartException {
final Endpoint endpoint = endpointSupplier.get();
OptionMap.Builder builder = OptionMap.builder();
ListenerRegistry.Listener listenerInfo = listenerRegistrySupplier.get().getListener(httpConnectorName);
assert listenerInfo != null;
listenerInfo.addHttpUpgradeMetadata(httpUpgradeMetadata = new ListenerRegistry.HttpUpgradeMetadata("jboss-remoting", endpointName));
RemotingConnectorBindingInfoService.install(context.getChildTarget(), context.getController().getName().getSimpleName(), (SocketBinding) listenerInfo.getContextInformation("socket-binding"), listenerInfo.getProtocol().equals("https") ? REMOTE_HTTPS : REMOTE_HTTP);
if (connectorPropertiesOptionMap != null) {
builder.addAll(connectorPropertiesOptionMap);
}
OptionMap resultingMap = builder.getMap();
try {
final ExternalConnectionProvider provider = endpoint.getConnectionProviderInterface(Protocol.HTTP_REMOTING.toString(), ExternalConnectionProvider.class);
SaslAuthenticationFactory saslAuthenticationFactory = saslAuthenticationFactorySupplier != null ? saslAuthenticationFactorySupplier.get() : null;
if (saslAuthenticationFactory == null) {
// TODO Elytron Inject the sasl server factory.
RemotingLogger.ROOT_LOGGER.warn("****** All authentication is ANONYMOUS for " + getClass().getName());
final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
domainBuilder.addRealm("default", SecurityRealm.EMPTY_REALM).build();
domainBuilder.setDefaultRealmName("default");
domainBuilder.setPermissionMapper((permissionMappable, roles) -> createPermissionVerifier());
final SaslAuthenticationFactory.Builder authBuilder = SaslAuthenticationFactory.builder();
authBuilder.setSecurityDomain(domainBuilder.build());
authBuilder.setFactory(new AnonymousServerFactory());
authBuilder.setMechanismConfigurationSelector(mechanismInformation -> MechanismConfiguration.EMPTY);
saslAuthenticationFactory = authBuilder.build();
}
final Consumer<StreamConnection> adaptor = provider.createConnectionAdaptor(resultingMap, saslAuthenticationFactory);
upgradeRegistrySupplier.get().addProtocol(JBOSS_REMOTING, new ChannelListener<StreamConnection>() {
@Override
public void handleEvent(final StreamConnection channel) {
adaptor.accept(channel);
/*if (channel instanceof SslConnection) {
adaptor.accept(new AssembledConnectedSslStreamChannel((SslConnection) channel, channel.getSourceChannel(), channel.getSinkChannel()));
} else {
adaptor.adapt(new AssembledConnectedStreamChannel(channel, channel.getSourceChannel(), channel.getSinkChannel()));
}*/
}
}, new SimpleHttpUpgradeHandshake(MAGIC_NUMBER, SEC_JBOSS_REMOTING_KEY, SEC_JBOSS_REMOTING_ACCEPT));
serviceConsumer.accept(this);
} catch (UnknownURISchemeException e) {
throw new StartException(e);
} catch (IOException e) {
throw new StartException(e);
}
}
use of org.jboss.remoting3.UnknownURISchemeException in project jboss-remoting by jboss-remoting.
the class EndpointImpl method connect.
IoFuture<Connection> connect(final URI destination, final SocketAddress bindAddress, final OptionMap connectOptions, final AuthenticationConfiguration configuration, final SSLContext sslContext) {
Assert.checkNotNullParam("destination", destination);
Assert.checkNotNullParam("connectOptions", connectOptions);
final String protocol = AUTH_CONFIGURATION_CLIENT.getSaslProtocol(configuration) != null ? AUTH_CONFIGURATION_CLIENT.getSaslProtocol(configuration) : connectOptions.contains(RemotingOptions.SASL_PROTOCOL) ? connectOptions.get(RemotingOptions.SASL_PROTOCOL) : RemotingOptions.DEFAULT_SASL_PROTOCOL;
UnaryOperator<SaslClientFactory> factoryOperator = factory -> new ProtocolSaslClientFactory(factory, protocol);
if (connectOptions.contains(RemotingOptions.SERVER_NAME)) {
final String serverName = connectOptions.get(RemotingOptions.SERVER_NAME);
factoryOperator = and(factoryOperator, factory -> new ServerNameSaslClientFactory(factory, serverName));
}
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(RemotingPermission.CONNECT);
}
final String scheme = AUTH_CONFIGURATION_CLIENT.getRealProtocol(destination, configuration);
synchronized (connectionLock) {
boolean ok = false;
try {
resourceUntick("Connection to " + destination);
} catch (NotOpenException e) {
return new FailedIoFuture<>(e);
}
try {
final ProtocolRegistration protocolRegistration = connectionProviders.get(scheme);
if (protocolRegistration == null) {
return new FailedIoFuture<>(new UnknownURISchemeException("No connection provider for URI scheme \"" + scheme + "\" is installed"));
}
final ConnectionProvider connectionProvider = protocolRegistration.getProvider();
final FutureResult<Connection> futureResult = new FutureResult<Connection>(getExecutor());
// Mark the stack because otherwise debugging connect problems can be incredibly tough
final StackTraceElement[] mark = Thread.currentThread().getStackTrace();
final UnaryOperator<SaslClientFactory> finalFactoryOperator = factoryOperator;
final Result<ConnectionHandlerFactory> result = new Result<ConnectionHandlerFactory>() {
private final AtomicBoolean flag = new AtomicBoolean();
public boolean setCancelled() {
if (!flag.compareAndSet(false, true)) {
return false;
}
log.logf(getClass().getName(), Logger.Level.TRACE, null, "Registered cancellation result");
closeTick1("a cancelled connection");
futureResult.setCancelled();
return true;
}
public boolean setException(final IOException exception) {
if (!flag.compareAndSet(false, true)) {
return false;
}
log.logf(getClass().getName(), Logger.Level.TRACE, exception, "Registered exception result");
closeTick1("a failed connection (2)");
SpiUtils.glueStackTraces(exception, mark, 1, "asynchronous invocation");
futureResult.setException(exception);
return true;
}
public boolean setResult(final ConnectionHandlerFactory connHandlerFactory) {
if (!flag.compareAndSet(false, true)) {
return false;
}
synchronized (connectionLock) {
log.logf(getClass().getName(), Logger.Level.TRACE, null, "Registered successful result %s", connHandlerFactory);
final ConnectionImpl connection = new ConnectionImpl(EndpointImpl.this, connHandlerFactory, protocolRegistration.getContext(), destination, null, configuration, protocol);
connections.add(connection);
connection.getConnectionHandler().addCloseHandler(SpiUtils.asyncClosingCloseHandler(connection));
connection.addCloseHandler(resourceCloseHandler);
connection.addCloseHandler(connectionCloseHandler);
// see if we were closed in the meantime
if (EndpointImpl.this.isCloseFlagSet()) {
connection.closeAsync();
futureResult.setCancelled();
} else {
futureResult.setResult(connection);
}
}
return true;
}
};
final Cancellable connect;
if (System.getSecurityManager() == null)
connect = connectionProvider.connect(destination, bindAddress, connectOptions, result, configuration, sslContext, finalFactoryOperator, Collections.emptyList());
else
connect = doPrivileged((PrivilegedAction<Cancellable>) () -> connectionProvider.connect(destination, bindAddress, connectOptions, result, configuration, sslContext, finalFactoryOperator, Collections.emptyList()));
ok = true;
futureResult.addCancelHandler(connect);
return futureResult.getIoFuture();
} finally {
if (!ok) {
closeTick1("a failed connection (1)");
}
}
}
}
Aggregations