Search in sources :

Example 1 with Channel

use of org.jboss.remoting3.Channel in project wildfly by wildfly.

the class EJBRemoteConnectorService method start.

@Override
public void start(StartContext context) throws StartException {
    final AssociationService associationService = associationServiceInjectedValue.getValue();
    final Endpoint endpoint = endpointValue.getValue();
    Executor executor = executorService.getOptionalValue();
    if (executor != null) {
        associationService.setExecutor(executor);
    }
    RemoteEJBService remoteEJBService = RemoteEJBService.create(associationService.getAssociation(), remotingTransactionServiceInjectedValue.getValue());
    final ControlledProcessStateService processStateService = controlledProcessStateServiceInjectedValue.getValue();
    if (processStateService.getCurrentState() == ControlledProcessState.State.STARTING) {
        final PropertyChangeListener listener = new PropertyChangeListener() {

            public void propertyChange(final PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("currentState") && evt.getOldValue() == ControlledProcessState.State.STARTING) {
                    remoteEJBService.serverUp();
                    // can't use a lambda because of this line...
                    processStateService.removePropertyChangeListener(this);
                }
            }
        };
        processStateService.addPropertyChangeListener(listener);
        // this is actually racy, so we have to double-check the state afterwards just to be sure it didn't transition before we got here.
        if (processStateService.getCurrentState() != ControlledProcessState.State.STARTING) {
            // this method is idempotent so it's OK if the listener got fired
            remoteEJBService.serverUp();
            // this one too
            processStateService.removePropertyChangeListener(listener);
        }
    } else {
        remoteEJBService.serverUp();
    }
    // Register an EJB channel open listener
    OpenListener channelOpenListener = remoteEJBService.getOpenListener();
    try {
        registration = endpoint.registerService(EJB_CHANNEL_NAME, channelOpenListener, this.channelCreationOptions);
    } catch (ServiceRegistrationException e) {
        throw new StartException(e);
    }
}
Also used : RemoteEJBService(org.jboss.ejb.protocol.remote.RemoteEJBService) ControlledProcessStateService(org.jboss.as.controller.ControlledProcessStateService) PropertyChangeEvent(java.beans.PropertyChangeEvent) Executor(java.util.concurrent.Executor) Endpoint(org.jboss.remoting3.Endpoint) PropertyChangeListener(java.beans.PropertyChangeListener) OpenListener(org.jboss.remoting3.OpenListener) ServiceRegistrationException(org.jboss.remoting3.ServiceRegistrationException) StartException(org.jboss.msc.service.StartException)

Example 2 with Channel

use of org.jboss.remoting3.Channel in project ysoserial by frohoff.

the class JBoss method getChannel.

private static Channel getChannel(ConnectionProviderContextImpl context, ConnectionHandler ch, OptionMap options) throws IOException {
    Channel c;
    FutureResult<Channel> chResult = new FutureResult<Channel>(context.getExecutor());
    ch.open("jmx", chResult, options);
    IoFuture<Channel> cFuture = chResult.getIoFuture();
    Status s2 = cFuture.await();
    if (s2 == Status.FAILED) {
        System.err.println("Cannot connect");
        if (cFuture.getException() != null) {
            throw new IOException("Connect failed", cFuture.getException());
        }
    } else if (s2 != Status.DONE) {
        cFuture.cancel();
        throw new IOException("Connect timeout");
    }
    c = cFuture.get();
    return c;
}
Also used : Status(org.xnio.IoFuture.Status) FutureResult(org.xnio.FutureResult) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException)

Example 3 with Channel

use of org.jboss.remoting3.Channel in project wildfly by wildfly.

the class EJB3RemoteServiceAdd method installRuntimeServices.

void installRuntimeServices(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final String clientMappingsClusterName = EJB3RemoteResourceDefinition.CLIENT_MAPPINGS_CLUSTER_NAME.resolveModelAttribute(context, model).asString();
    final String connectorName = EJB3RemoteResourceDefinition.CONNECTOR_REF.resolveModelAttribute(context, model).asString();
    final ServiceName remotingServerInfoServiceName = RemotingConnectorBindingInfoService.serviceName(connectorName);
    final String threadPoolName = EJB3RemoteResourceDefinition.THREAD_POOL_NAME.resolveModelAttribute(context, model).asString();
    final boolean executeInWorker = EJB3RemoteResourceDefinition.EXECUTE_IN_WORKER.resolveModelAttribute(context, model).asBoolean();
    final ServiceTarget target = context.getServiceTarget();
    // Install the client-mapping service for the remoting connector
    new EJBRemotingConnectorClientMappingsEntryProviderService(clientMappingsClusterName, remotingServerInfoServiceName).configure(context).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    new RegistryInstallerService(clientMappingsClusterName).configure(context).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    // Handle case where no infinispan subsystem exists or does not define an ejb cache-container
    Resource rootResource = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
    PathElement infinispanPath = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "infinispan");
    if (!rootResource.hasChild(infinispanPath) || !rootResource.getChild(infinispanPath).hasChild(PathElement.pathElement("cache-container", clientMappingsClusterName))) {
        // Install services that would normally be installed by this container/cache
        CapabilityServiceSupport support = context.getCapabilityServiceSupport();
        for (GroupBuilderProvider provider : ServiceLoader.load(LocalGroupBuilderProvider.class, LocalGroupBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> requirement.getServiceName(support, clientMappingsClusterName), clientMappingsClusterName)) {
                builder.configure(support).build(target).install();
            }
        }
        for (CacheBuilderProvider provider : ServiceLoader.load(LocalCacheBuilderProvider.class, LocalCacheBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> requirement.getServiceName(support, clientMappingsClusterName, null), clientMappingsClusterName, null)) {
                builder.configure(support).build(target).install();
            }
        }
    }
    final OptionMap channelCreationOptions = this.getChannelCreationOptions(context);
    // Install the EJB remoting connector service which will listen for client connections on the remoting channel
    // TODO: Externalize (expose via management API if needed) the version and the marshalling strategy
    final EJBRemoteConnectorService ejbRemoteConnectorService = new EJBRemoteConnectorService(channelCreationOptions);
    ServiceBuilder<EJBRemoteConnectorService> builder = target.addService(EJBRemoteConnectorService.SERVICE_NAME, ejbRemoteConnectorService);
    builder.addDependency(RemotingServices.SUBSYSTEM_ENDPOINT, Endpoint.class, ejbRemoteConnectorService.getEndpointInjector()).addDependency(remotingServerInfoServiceName, RemotingConnectorBindingInfoService.RemotingConnectorInfo.class, ejbRemoteConnectorService.getRemotingConnectorInfoInjectedValue()).addDependency(AssociationService.SERVICE_NAME, AssociationService.class, ejbRemoteConnectorService.getAssociationServiceInjector()).addDependency(TxnServices.JBOSS_TXN_REMOTE_TRANSACTION_SERVICE, RemotingTransactionService.class, ejbRemoteConnectorService.getRemotingTransactionServiceInjector()).addDependency(ControlledProcessStateService.SERVICE_NAME, ControlledProcessStateService.class, ejbRemoteConnectorService.getControlledProcessStateServiceInjector()).setInitialMode(ServiceController.Mode.ACTIVE);
    if (!executeInWorker) {
        builder.addDependency(EJB3SubsystemModel.BASE_THREAD_POOL_SERVICE_NAME.append(threadPoolName), ExecutorService.class, ejbRemoteConnectorService.getExecutorService());
    }
    builder.install();
}
Also used : LocalCacheBuilderProvider(org.wildfly.clustering.spi.LocalCacheBuilderProvider) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) ControlledProcessStateService(org.jboss.as.controller.ControlledProcessStateService) EJBRemotingConnectorClientMappingsEntryProviderService(org.jboss.as.ejb3.remote.EJBRemotingConnectorClientMappingsEntryProviderService) ServiceTarget(org.jboss.msc.service.ServiceTarget) RegistryInstallerService(org.jboss.as.ejb3.remote.RegistryInstallerService) RemotingConnectorBindingInfoService(org.jboss.as.remoting.RemotingConnectorBindingInfoService) Resource(org.jboss.as.controller.registry.Resource) AssociationService(org.jboss.as.ejb3.remote.AssociationService) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) PathElement(org.jboss.as.controller.PathElement) Endpoint(org.jboss.remoting3.Endpoint) ServiceName(org.jboss.msc.service.ServiceName) EJBRemoteConnectorService(org.jboss.as.ejb3.remote.EJBRemoteConnectorService) GroupBuilderProvider(org.wildfly.clustering.spi.GroupBuilderProvider) LocalGroupBuilderProvider(org.wildfly.clustering.spi.LocalGroupBuilderProvider) OptionMap(org.xnio.OptionMap) LocalCacheBuilderProvider(org.wildfly.clustering.spi.LocalCacheBuilderProvider) LocalGroupBuilderProvider(org.wildfly.clustering.spi.LocalGroupBuilderProvider)

Example 4 with Channel

use of org.jboss.remoting3.Channel in project ysoserial by frohoff.

the class JBoss method doRun.

private static void doRun(URI u, final Object payloadObject, String username, String password) {
    ConnectionProvider instance = null;
    ConnectionProviderContextImpl context = null;
    ConnectionHandler ch = null;
    Channel c = null;
    VersionedConnection vc = null;
    try {
        Logger logger = LogManager.getLogManager().getLogger("");
        logger.addHandler(new ConsoleLogHandler());
        logger.setLevel(Level.INFO);
        OptionMap options = OptionMap.builder().set(Options.SSL_ENABLED, u.getScheme().equals("https")).getMap();
        context = new ConnectionProviderContextImpl(options, "endpoint");
        instance = new HttpUpgradeConnectionProviderFactory().createInstance(context, options);
        String host = u.getHost();
        int port = u.getPort() > 0 ? u.getPort() : 9990;
        SocketAddress destination = new InetSocketAddress(host, port);
        ConnectionHandlerFactory chf = getConnection(destination, username, password, context, instance, options);
        ch = chf.createInstance(new ConnectionHandlerContextImpl(context));
        c = getChannel(context, ch, options);
        System.err.println("Connected");
        vc = makeVersionedConnection(c);
        MBeanServerConnection mbc = vc.getMBeanServerConnection(null);
        doExploit(payloadObject, mbc);
        System.err.println("DONE");
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        cleanup(instance, context, ch, c, vc);
    }
}
Also used : ConnectionHandlerFactory(org.jboss.remoting3.spi.ConnectionHandlerFactory) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.remoting3.Channel) Logger(java.util.logging.Logger) Endpoint(org.jboss.remoting3.Endpoint) ConnectionProvider(org.jboss.remoting3.spi.ConnectionProvider) ConnectionHandler(org.jboss.remoting3.spi.ConnectionHandler) OptionMap(org.xnio.OptionMap) HttpUpgradeConnectionProviderFactory(org.jboss.remoting3.remote.HttpUpgradeConnectionProviderFactory) VersionedConnection(org.jboss.remotingjmx.VersionedConnection) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) MBeanServerConnection(javax.management.MBeanServerConnection)

Aggregations

Endpoint (org.jboss.remoting3.Endpoint)3 ControlledProcessStateService (org.jboss.as.controller.ControlledProcessStateService)2 Channel (org.jboss.remoting3.Channel)2 OptionMap (org.xnio.OptionMap)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 Executor (java.util.concurrent.Executor)1 Logger (java.util.logging.Logger)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 PathElement (org.jboss.as.controller.PathElement)1 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)1 Resource (org.jboss.as.controller.registry.Resource)1 AssociationService (org.jboss.as.ejb3.remote.AssociationService)1 EJBRemoteConnectorService (org.jboss.as.ejb3.remote.EJBRemoteConnectorService)1 EJBRemotingConnectorClientMappingsEntryProviderService (org.jboss.as.ejb3.remote.EJBRemotingConnectorClientMappingsEntryProviderService)1 RegistryInstallerService (org.jboss.as.ejb3.remote.RegistryInstallerService)1 RemotingConnectorBindingInfoService (org.jboss.as.remoting.RemotingConnectorBindingInfoService)1