Search in sources :

Example 1 with UnknownURISchemeException

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);
    }
}
Also used : ListenerRegistry(io.undertow.server.ListenerRegistry) ExternalConnectionProvider(org.jboss.remoting3.spi.ExternalConnectionProvider) UnknownURISchemeException(org.jboss.remoting3.UnknownURISchemeException) IOException(java.io.IOException) StreamConnection(org.xnio.StreamConnection) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) SaslAuthenticationFactory(org.wildfly.security.auth.server.SaslAuthenticationFactory) Endpoint(org.jboss.remoting3.Endpoint) AnonymousServerFactory(org.wildfly.security.sasl.anonymous.AnonymousServerFactory) OptionMap(org.xnio.OptionMap) StartException(org.jboss.msc.service.StartException)

Example 2 with UnknownURISchemeException

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)");
            }
        }
    }
}
Also used : FailedIoFuture(org.xnio.FailedIoFuture) SSLContext(javax.net.ssl.SSLContext) SocketAddress(java.net.SocketAddress) AbstractHandleableCloseable(org.jboss.remoting3.spi.AbstractHandleableCloseable) URISyntaxException(java.net.URISyntaxException) AccessController.doPrivileged(java.security.AccessController.doPrivileged) UnaryOperator(java.util.function.UnaryOperator) OptionMap(org.xnio.OptionMap) GeneralSecurityException(java.security.GeneralSecurityException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemotingPermission(org.jboss.remoting3.security.RemotingPermission) IoUtils.safeClose(org.xnio.IoUtils.safeClose) Map(java.util.Map) URI(java.net.URI) ConnectionProvider(org.jboss.remoting3.spi.ConnectionProvider) ServerNameSaslClientFactory(org.wildfly.security.sasl.util.ServerNameSaslClientFactory) Assert(org.wildfly.common.Assert) IoFuture(org.xnio.IoFuture) IdentityHashMap(java.util.IdentityHashMap) Predicate(java.util.function.Predicate) SpiUtils(org.jboss.remoting3.spi.SpiUtils) ConnectionHandlerFactory(org.jboss.remoting3.spi.ConnectionHandlerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) ObjectName(javax.management.ObjectName) PrivilegedAction(java.security.PrivilegedAction) InetSocketAddress(java.net.InetSocketAddress) AuthenticationContextConfigurationClient(org.wildfly.security.auth.client.AuthenticationContextConfigurationClient) SaslAuthenticationFactory(org.wildfly.security.auth.server.sasl.SaslAuthenticationFactory) Options(org.xnio.Options) List(java.util.List) ProtocolSaslClientFactory(org.wildfly.security.sasl.util.ProtocolSaslClientFactory) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) Messages(org.jboss.remoting3._private.Messages) AuthenticationException(org.wildfly.security.auth.AuthenticationException) Pattern(java.util.regex.Pattern) SaslClientFactory(javax.security.sasl.SaslClientFactory) ConnectionHandlerContext(org.jboss.remoting3.spi.ConnectionHandlerContext) AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) Xnio(org.xnio.Xnio) Logger(org.jboss.logging.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Result(org.xnio.Result) MBeanServer(javax.management.MBeanServer) Bits(org.xnio.Bits) ManagementFactory(java.lang.management.ManagementFactory) RegisteredService(org.jboss.remoting3.spi.RegisteredService) ConnectionProviderFactory(org.jboss.remoting3.spi.ConnectionProviderFactory) Executor(java.util.concurrent.Executor) XnioWorker(org.xnio.XnioWorker) IOException(java.io.IOException) HttpUpgradeConnectionProviderFactory(org.jboss.remoting3.remote.HttpUpgradeConnectionProviderFactory) Cancellable(org.xnio.Cancellable) ConnectionProviderContext(org.jboss.remoting3.spi.ConnectionProviderContext) FutureResult(org.xnio.FutureResult) RemoteConnectionProviderFactory(org.jboss.remoting3.remote.RemoteConnectionProviderFactory) Collections(java.util.Collections) ConnectionHandlerFactory(org.jboss.remoting3.spi.ConnectionHandlerFactory) Cancellable(org.xnio.Cancellable) ProtocolSaslClientFactory(org.wildfly.security.sasl.util.ProtocolSaslClientFactory) ConnectionProvider(org.jboss.remoting3.spi.ConnectionProvider) Result(org.xnio.Result) FutureResult(org.xnio.FutureResult) FutureResult(org.xnio.FutureResult) ServerNameSaslClientFactory(org.wildfly.security.sasl.util.ServerNameSaslClientFactory) ServerNameSaslClientFactory(org.wildfly.security.sasl.util.ServerNameSaslClientFactory) ProtocolSaslClientFactory(org.wildfly.security.sasl.util.ProtocolSaslClientFactory) SaslClientFactory(javax.security.sasl.SaslClientFactory) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FailedIoFuture(org.xnio.FailedIoFuture)

Aggregations

IOException (java.io.IOException)2 OptionMap (org.xnio.OptionMap)2 ListenerRegistry (io.undertow.server.ListenerRegistry)1 ManagementFactory (java.lang.management.ManagementFactory)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 AccessController.doPrivileged (java.security.AccessController.doPrivileged)1 GeneralSecurityException (java.security.GeneralSecurityException)1 PrivilegedAction (java.security.PrivilegedAction)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1