Search in sources :

Example 1 with ControlPoint

use of org.wildfly.extension.requestcontroller.ControlPoint in project wildfly by wildfly.

the class UndertowDeploymentInfoService method start.

@Override
public synchronized void start(final StartContext startContext) throws StartException {
    ClassLoader oldTccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(module.getClassLoader());
        DeploymentInfo deploymentInfo = createServletConfig();
        deploymentInfo.setConfidentialPortManager(getConfidentialPortManager());
        handleDistributable(deploymentInfo);
        if (securityFunction.getOptionalValue() == null) {
            handleIdentityManager(deploymentInfo);
            handleJASPIMechanism(deploymentInfo);
            handleJACCAuthorization(deploymentInfo);
            handleAuthManagerLogout(deploymentInfo, mergedMetaData);
            if (mergedMetaData.isUseJBossAuthorization()) {
                deploymentInfo.setAuthorizationManager(new JbossAuthorizationManager(deploymentInfo.getAuthorizationManager()));
            }
        }
        handleAdditionalAuthenticationMechanisms(deploymentInfo);
        SessionConfigMetaData sessionConfig = mergedMetaData.getSessionConfig();
        if (sharedSessionManagerConfig != null && sharedSessionManagerConfig.getSessionConfig() != null) {
            sessionConfig = sharedSessionManagerConfig.getSessionConfig();
        }
        ServletSessionConfig config = null;
        //default session config
        SessionCookieConfig defaultSessionConfig = container.getValue().getSessionCookieConfig();
        if (defaultSessionConfig != null) {
            config = new ServletSessionConfig();
            if (defaultSessionConfig.getName() != null) {
                config.setName(defaultSessionConfig.getName());
            }
            if (defaultSessionConfig.getDomain() != null) {
                config.setDomain(defaultSessionConfig.getDomain());
            }
            if (defaultSessionConfig.getHttpOnly() != null) {
                config.setHttpOnly(defaultSessionConfig.getHttpOnly());
            }
            if (defaultSessionConfig.getSecure() != null) {
                config.setSecure(defaultSessionConfig.getSecure());
            }
            if (defaultSessionConfig.getMaxAge() != null) {
                config.setMaxAge(defaultSessionConfig.getMaxAge());
            }
            if (defaultSessionConfig.getComment() != null) {
                config.setComment(defaultSessionConfig.getComment());
            }
        }
        SecureRandomSessionIdGenerator sessionIdGenerator = new SecureRandomSessionIdGenerator();
        sessionIdGenerator.setLength(container.getValue().getSessionIdLength());
        deploymentInfo.setSessionIdGenerator(sessionIdGenerator);
        boolean sessionTimeoutSet = false;
        if (sessionConfig != null) {
            if (sessionConfig.getSessionTimeoutSet()) {
                deploymentInfo.setDefaultSessionTimeout(sessionConfig.getSessionTimeout() * 60);
                sessionTimeoutSet = true;
            }
            CookieConfigMetaData cookieConfig = sessionConfig.getCookieConfig();
            if (config == null) {
                config = new ServletSessionConfig();
            }
            if (cookieConfig != null) {
                if (cookieConfig.getName() != null) {
                    config.setName(cookieConfig.getName());
                }
                if (cookieConfig.getDomain() != null) {
                    config.setDomain(cookieConfig.getDomain());
                }
                if (cookieConfig.getComment() != null) {
                    config.setComment(cookieConfig.getComment());
                }
                config.setSecure(cookieConfig.getSecure());
                config.setPath(cookieConfig.getPath());
                config.setMaxAge(cookieConfig.getMaxAge());
                config.setHttpOnly(cookieConfig.getHttpOnly());
            }
            List<SessionTrackingModeType> modes = sessionConfig.getSessionTrackingModes();
            if (modes != null && !modes.isEmpty()) {
                final Set<SessionTrackingMode> trackingModes = new HashSet<>();
                for (SessionTrackingModeType mode : modes) {
                    switch(mode) {
                        case COOKIE:
                            trackingModes.add(SessionTrackingMode.COOKIE);
                            break;
                        case SSL:
                            trackingModes.add(SessionTrackingMode.SSL);
                            break;
                        case URL:
                            trackingModes.add(SessionTrackingMode.URL);
                            break;
                    }
                }
                config.setSessionTrackingModes(trackingModes);
            }
        }
        if (!sessionTimeoutSet) {
            deploymentInfo.setDefaultSessionTimeout(container.getValue().getDefaultSessionTimeout() * 60);
        }
        if (config != null) {
            deploymentInfo.setServletSessionConfig(config);
        }
        for (final SetupAction action : setupActions) {
            deploymentInfo.addThreadSetupAction(new UndertowThreadSetupAction(action));
        }
        if (initialHandlerChainWrappers != null) {
            for (HandlerWrapper handlerWrapper : initialHandlerChainWrappers) {
                deploymentInfo.addInitialHandlerChainWrapper(handlerWrapper);
            }
        }
        if (innerHandlerChainWrappers != null) {
            for (HandlerWrapper handlerWrapper : innerHandlerChainWrappers) {
                deploymentInfo.addInnerHandlerChainWrapper(handlerWrapper);
            }
        }
        if (outerHandlerChainWrappers != null) {
            for (HandlerWrapper handlerWrapper : outerHandlerChainWrappers) {
                deploymentInfo.addOuterHandlerChainWrapper(handlerWrapper);
            }
        }
        if (threadSetupActions != null) {
            for (ThreadSetupHandler threadSetupAction : threadSetupActions) {
                deploymentInfo.addThreadSetupAction(threadSetupAction);
            }
        }
        deploymentInfo.setServerName(serverEnvironmentInjectedValue.getValue().getProductConfig().getPrettyVersionString());
        if (undertowService.getValue().isStatisticsEnabled()) {
            deploymentInfo.setMetricsCollector(new UndertowMetricsCollector());
        }
        ControlPoint controlPoint = controlPointInjectedValue.getOptionalValue();
        if (controlPoint != null) {
            deploymentInfo.addOuterHandlerChainWrapper(GlobalRequestControllerHandler.wrapper(controlPoint, allowSuspendedRequests));
        }
        container.getValue().getAuthenticationMechanisms().entrySet().forEach(e -> deploymentInfo.addAuthenticationMechanism(e.getKey(), e.getValue()));
        deploymentInfo.setUseCachedAuthenticationMechanism(!deploymentInfo.getAuthenticationMechanisms().containsKey(SingleSignOnService.AUTHENTICATION_MECHANISM_NAME));
        this.deploymentInfo = deploymentInfo;
    } finally {
        Thread.currentThread().setContextClassLoader(oldTccl);
    }
}
Also used : SessionConfigMetaData(org.jboss.metadata.web.spec.SessionConfigMetaData) JbossAuthorizationManager(org.wildfly.extension.undertow.security.JbossAuthorizationManager) SessionTrackingMode(javax.servlet.SessionTrackingMode) CookieConfigMetaData(org.jboss.metadata.web.spec.CookieConfigMetaData) SetupAction(org.jboss.as.server.deployment.SetupAction) SecurityContextThreadSetupAction(org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) ServletSessionConfig(io.undertow.servlet.api.ServletSessionConfig) HandlerWrapper(io.undertow.server.HandlerWrapper) ThreadSetupHandler(io.undertow.servlet.api.ThreadSetupHandler) SecureRandomSessionIdGenerator(io.undertow.server.session.SecureRandomSessionIdGenerator) SessionCookieConfig(org.wildfly.extension.undertow.SessionCookieConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) SessionTrackingModeType(org.jboss.metadata.web.spec.SessionTrackingModeType) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 2 with ControlPoint

use of org.wildfly.extension.requestcontroller.ControlPoint in project wildfly by wildfly.

the class EjbSuspendInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    InvocationType invocation = context.getPrivateData(InvocationType.class);
    if (invocation != InvocationType.REMOTE && invocation != InvocationType.MESSAGE_DELIVERY) {
        return context.proceed();
    }
    // see if control point accepts or rejects this invocation
    EJBComponent component = getComponent(context, EJBComponent.class);
    ControlPoint entryPoint = component.getControlPoint();
    RunResult result = entryPoint.beginRequest();
    if (result == RunResult.REJECTED) {
        // if control point rejected, check with suspend handler
        if (!component.getEjbSuspendHandlerService().acceptInvocation(context))
            throw EjbLogger.ROOT_LOGGER.containerSuspended();
    }
    try {
        return context.proceed();
    } finally {
        if (result == RunResult.REJECTED)
            component.getEjbSuspendHandlerService().invocationComplete();
        else
            entryPoint.requestComplete();
    }
}
Also used : InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) RunResult(org.wildfly.extension.requestcontroller.RunResult)

Example 3 with ControlPoint

use of org.wildfly.extension.requestcontroller.ControlPoint in project wildfly by wildfly.

the class EjbJndiBindingsDeploymentUnitProcessor method registerControlPointBinding.

private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
    final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
    final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
    final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
    final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
    final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
    componentDescription.getConfigurators().add((context, description, configuration) -> {
        viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
        configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
    });
    //we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
    //as it will also reject local lookups as well, although in general local code should never be looking up the
    //exported bindings
    //the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
    final InjectionSource is = new InjectionSource() {

        @Override
        public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
            final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
            delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
            injector.inject(new ManagedReferenceFactory() {

                @Override
                public ManagedReference getReference() {
                    ControlPoint cp = controlPointInjectedValue.getValue();
                    try {
                        RunResult res = cp.beginRequest();
                        if (res != RunResult.RUN) {
                            throw EjbLogger.ROOT_LOGGER.containerSuspended();
                        }
                        try {
                            return delegateInjection.getValue().getReference();
                        } finally {
                            cp.requestComplete();
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
    };
    moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) ManagedReference(org.jboss.as.naming.ManagedReference) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) InjectionSource(org.jboss.as.ee.component.InjectionSource) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) RunResult(org.wildfly.extension.requestcontroller.RunResult) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Aggregations

ControlPoint (org.wildfly.extension.requestcontroller.ControlPoint)3 RunResult (org.wildfly.extension.requestcontroller.RunResult)2 HandlerWrapper (io.undertow.server.HandlerWrapper)1 SecureRandomSessionIdGenerator (io.undertow.server.session.SecureRandomSessionIdGenerator)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ServletSessionConfig (io.undertow.servlet.api.ServletSessionConfig)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 SessionTrackingMode (javax.servlet.SessionTrackingMode)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 InjectionSource (org.jboss.as.ee.component.InjectionSource)1 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1 RemoteViewInjectionSource (org.jboss.as.ejb3.remote.RemoteViewInjectionSource)1 ManagedReference (org.jboss.as.naming.ManagedReference)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)1