Search in sources :

Example 1 with ServletContextAttribute

use of org.jboss.as.web.common.ServletContextAttribute in project wildfly by wildfly.

the class JSFAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        // Can not continue without index
        return;
    }
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        // Can not continue without module
        return;
    }
    final ClassLoader classLoader = module.getClassLoader();
    for (FacesAnnotation annotation : FacesAnnotation.values()) {
        final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName);
        if (annotationInstances == null || annotationInstances.isEmpty()) {
            continue;
        }
        final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
        instances.put(annotation.annotationClass, discoveredClasses);
        for (AnnotationInstance annotationInstance : annotationInstances) {
            final AnnotationTarget target = annotationInstance.target();
            if (target instanceof ClassInfo) {
                final DotName className = ClassInfo.class.cast(target).name();
                final Class<?> annotatedClass;
                try {
                    annotatedClass = classLoader.loadClass(className.toString());
                } catch (ClassNotFoundException e) {
                    throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className));
                }
                discoveredClasses.add(annotatedClass);
            } else {
                throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidAnnotationLocation(annotation, target));
            }
        }
    }
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) Annotation(java.lang.annotation.Annotation) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with ServletContextAttribute

use of org.jboss.as.web.common.ServletContextAttribute in project wildfly by wildfly.

the class UndertowDeploymentInfoService method createServletConfig.

private DeploymentInfo createServletConfig() throws StartException {
    final ComponentRegistry componentRegistry = componentRegistryInjectedValue.getValue();
    try {
        if (!mergedMetaData.isMetadataComplete()) {
            mergedMetaData.resolveAnnotations();
        }
        mergedMetaData.resolveRunAs();
        final DeploymentInfo d = new DeploymentInfo();
        d.setContextPath(resolveContextPath());
        if (mergedMetaData.getDescriptionGroup() != null) {
            d.setDisplayName(mergedMetaData.getDescriptionGroup().getDisplayName());
        }
        d.setDeploymentName(deploymentName);
        d.setHostName(host.getValue().getName());
        final ServletContainerService servletContainer = container.getValue();
        try {
            //TODO: make the caching limits configurable
            List<String> externalOverlays = mergedMetaData.getOverlays();
            ResourceManager resourceManager = new ServletResourceManager(deploymentRoot, overlays, explodedDeployment, mergedMetaData.isSymbolicLinkingEnabled(), servletContainer.isDisableFileWatchService(), externalOverlays);
            resourceManager = new CachingResourceManager(100, 10 * 1024 * 1024, servletContainer.getBufferCache(), resourceManager, explodedDeployment ? 2000 : -1);
            if (externalResources != null && !externalResources.isEmpty()) {
                //TODO: we don't cache external deployments, as they are intended for development use
                //should be make this configurable or something?
                List<ResourceManager> delegates = new ArrayList<>();
                for (File resource : externalResources) {
                    delegates.add(new FileResourceManager(resource.getCanonicalFile(), 1024, true, mergedMetaData.isSymbolicLinkingEnabled(), "/"));
                }
                delegates.add(resourceManager);
                resourceManager = new DelegatingResourceManager(delegates);
            }
            d.setResourceManager(resourceManager);
        } catch (IOException e) {
            throw new StartException(e);
        }
        d.setTempDir(tempDir);
        d.setClassLoader(module.getClassLoader());
        final String servletVersion = mergedMetaData.getServletVersion();
        if (servletVersion != null) {
            d.setMajorVersion(Integer.parseInt(servletVersion.charAt(0) + ""));
            d.setMinorVersion(Integer.parseInt(servletVersion.charAt(2) + ""));
        } else {
            d.setMajorVersion(3);
            d.setMinorVersion(1);
        }
        //in most cases flush just hurts performance for no good reason
        d.setIgnoreFlush(servletContainer.isIgnoreFlush());
        //controls initialization of filters on start of application
        d.setEagerFilterInit(servletContainer.isEagerFilterInit());
        d.setAllowNonStandardWrappers(servletContainer.isAllowNonStandardWrappers());
        d.setServletStackTraces(servletContainer.getStackTraces());
        d.setDisableCachingForSecuredPages(servletContainer.isDisableCachingForSecuredPages());
        if (servletContainer.getSessionPersistenceManager() != null) {
            d.setSessionPersistenceManager(servletContainer.getSessionPersistenceManager());
        }
        //for 2.2 apps we do not require a leading / in path mappings
        boolean is22OrOlder;
        if (d.getMajorVersion() == 1) {
            is22OrOlder = true;
        } else if (d.getMajorVersion() == 2) {
            is22OrOlder = d.getMinorVersion() < 3;
        } else {
            is22OrOlder = false;
        }
        JSPConfig jspConfig = servletContainer.getJspConfig();
        final Set<String> seenMappings = new HashSet<>();
        HashMap<String, TagLibraryInfo> tldInfo = createTldsInfo(tldsMetaData, sharedTlds);
        //default JSP servlet
        final ServletInfo jspServlet = jspConfig != null ? jspConfig.createJSPServletInfo() : null;
        if (jspServlet != null) {
            //this would be null if jsp support is disabled
            HashMap<String, JspPropertyGroup> propertyGroups = createJspConfig(mergedMetaData);
            JspServletBuilder.setupDeployment(d, propertyGroups, tldInfo, new UndertowJSPInstanceManager(new WebInjectionContainer(module.getClassLoader(), componentRegistryInjectedValue.getValue())));
            if (mergedMetaData.getJspConfig() != null) {
                Collection<JspPropertyGroup> values = new LinkedHashSet<>(propertyGroups.values());
                d.setJspConfigDescriptor(new JspConfigDescriptorImpl(tldInfo.values(), values));
            }
            d.addServlet(jspServlet);
            final Set<String> jspPropertyGroupMappings = propertyGroups.keySet();
            for (final String mapping : jspPropertyGroupMappings) {
                if (!jspServlet.getMappings().contains(mapping)) {
                    jspServlet.addMapping(mapping);
                }
            }
            seenMappings.addAll(jspPropertyGroupMappings);
            //setup JSP application context initializing listener
            d.addListener(new ListenerInfo(JspInitializationListener.class));
            d.addServletContextAttribute(JspInitializationListener.CONTEXT_KEY, expressionFactoryWrappers);
        }
        d.setClassIntrospecter(new ComponentClassIntrospector(componentRegistry));
        final Map<String, List<ServletMappingMetaData>> servletMappings = new HashMap<>();
        if (mergedMetaData.getExecutorName() != null) {
            d.setExecutor(executorsByName.get(mergedMetaData.getExecutorName()).getValue());
        }
        Boolean proactiveAuthentication = mergedMetaData.getProactiveAuthentication();
        if (proactiveAuthentication == null) {
            proactiveAuthentication = container.getValue().isProactiveAuth();
        }
        d.setAuthenticationMode(proactiveAuthentication ? AuthenticationMode.PRO_ACTIVE : AuthenticationMode.CONSTRAINT_DRIVEN);
        if (servletExtensions != null) {
            for (ServletExtension extension : servletExtensions) {
                d.addServletExtension(extension);
            }
        }
        if (mergedMetaData.getServletMappings() != null) {
            for (final ServletMappingMetaData mapping : mergedMetaData.getServletMappings()) {
                List<ServletMappingMetaData> list = servletMappings.get(mapping.getServletName());
                if (list == null) {
                    servletMappings.put(mapping.getServletName(), list = new ArrayList<>());
                }
                list.add(mapping);
            }
        }
        if (jspServlet != null) {
            // we need to clear the file attribute if it is set (WFLY-4106)
            jspServlet.addHandlerChainWrapper(JspFileHandler.jspFileHandlerWrapper(null));
            List<ServletMappingMetaData> list = servletMappings.get(jspServlet.getName());
            if (list != null && !list.isEmpty()) {
                for (final ServletMappingMetaData mapping : list) {
                    for (String urlPattern : mapping.getUrlPatterns()) {
                        jspServlet.addMapping(urlPattern);
                    }
                    seenMappings.addAll(mapping.getUrlPatterns());
                }
            }
        }
        final List<JBossServletMetaData> servlets = new ArrayList<JBossServletMetaData>();
        for (JBossServletMetaData servlet : mergedMetaData.getServlets()) {
            servlets.add(servlet);
        }
        for (final JBossServletMetaData servlet : mergedMetaData.getServlets()) {
            final ServletInfo s;
            if (servlet.getJspFile() != null) {
                s = new ServletInfo(servlet.getName(), JspServlet.class);
                s.addHandlerChainWrapper(JspFileHandler.jspFileHandlerWrapper(servlet.getJspFile()));
            } else {
                if (servlet.getServletClass() == null) {
                    if (DEFAULT_SERVLET_NAME.equals(servlet.getName())) {
                        s = new ServletInfo(servlet.getName(), DefaultServlet.class);
                    } else {
                        throw UndertowLogger.ROOT_LOGGER.servletClassNotDefined(servlet.getServletName());
                    }
                } else {
                    Class<? extends Servlet> servletClass = (Class<? extends Servlet>) module.getClassLoader().loadClass(servlet.getServletClass());
                    ManagedReferenceFactory creator = componentRegistry.createInstanceFactory(servletClass);
                    if (creator != null) {
                        InstanceFactory<Servlet> factory = createInstanceFactory(creator);
                        s = new ServletInfo(servlet.getName(), servletClass, factory);
                    } else {
                        s = new ServletInfo(servlet.getName(), servletClass);
                    }
                }
            }
            s.setAsyncSupported(servlet.isAsyncSupported()).setJspFile(servlet.getJspFile()).setEnabled(servlet.isEnabled());
            if (servlet.getRunAs() != null) {
                s.setRunAs(servlet.getRunAs().getRoleName());
            }
            if (servlet.getLoadOnStartupSet()) {
                //todo why not cleanup api and just use int everywhere
                s.setLoadOnStartup(servlet.getLoadOnStartupInt());
            }
            if (servlet.getExecutorName() != null) {
                s.setExecutor(executorsByName.get(servlet.getExecutorName()).getValue());
            }
            handleServletMappings(is22OrOlder, seenMappings, servletMappings, s);
            if (servlet.getInitParam() != null) {
                for (ParamValueMetaData initParam : servlet.getInitParam()) {
                    if (!s.getInitParams().containsKey(initParam.getParamName())) {
                        s.addInitParam(initParam.getParamName(), initParam.getParamValue());
                    }
                }
            }
            if (servlet.getServletSecurity() != null) {
                ServletSecurityInfo securityInfo = new ServletSecurityInfo();
                s.setServletSecurityInfo(securityInfo);
                securityInfo.setEmptyRoleSemantic(servlet.getServletSecurity().getEmptyRoleSemantic() == EmptyRoleSemanticType.DENY ? DENY : PERMIT).setTransportGuaranteeType(transportGuaranteeType(servlet.getServletSecurity().getTransportGuarantee())).addRolesAllowed(servlet.getServletSecurity().getRolesAllowed());
                if (servlet.getServletSecurity().getHttpMethodConstraints() != null) {
                    for (HttpMethodConstraintMetaData method : servlet.getServletSecurity().getHttpMethodConstraints()) {
                        securityInfo.addHttpMethodSecurityInfo(new HttpMethodSecurityInfo().setEmptyRoleSemantic(method.getEmptyRoleSemantic() == EmptyRoleSemanticType.DENY ? DENY : PERMIT).setTransportGuaranteeType(transportGuaranteeType(method.getTransportGuarantee())).addRolesAllowed(method.getRolesAllowed()).setMethod(method.getMethod()));
                    }
                }
            }
            if (servlet.getSecurityRoleRefs() != null) {
                for (final SecurityRoleRefMetaData ref : servlet.getSecurityRoleRefs()) {
                    s.addSecurityRoleRef(ref.getRoleName(), ref.getRoleLink());
                }
            }
            if (servlet.getMultipartConfig() != null) {
                MultipartConfigMetaData mp = servlet.getMultipartConfig();
                s.setMultipartConfig(Servlets.multipartConfig(mp.getLocation(), mp.getMaxFileSize(), mp.getMaxRequestSize(), mp.getFileSizeThreshold()));
            }
            d.addServlet(s);
        }
        if (jspServlet != null) {
            if (!seenMappings.contains("*.jsp")) {
                jspServlet.addMapping("*.jsp");
            }
            if (!seenMappings.contains("*.jspx")) {
                jspServlet.addMapping("*.jspx");
            }
        }
        //we explicitly add the default servlet, to allow it to be mapped
        if (!mergedMetaData.getServlets().containsKey(ServletPathMatches.DEFAULT_SERVLET_NAME)) {
            ServletInfo defaultServlet = Servlets.servlet(DEFAULT_SERVLET_NAME, DefaultServlet.class);
            handleServletMappings(is22OrOlder, seenMappings, servletMappings, defaultServlet);
            d.addServlet(defaultServlet);
        }
        if (servletContainer.getDirectoryListingEnabled() != null) {
            ServletInfo defaultServlet = d.getServlets().get(DEFAULT_SERVLET_NAME);
            defaultServlet.addInitParam(DefaultServlet.DIRECTORY_LISTING, servletContainer.getDirectoryListingEnabled().toString());
        }
        if (mergedMetaData.getFilters() != null) {
            for (final FilterMetaData filter : mergedMetaData.getFilters()) {
                Class<? extends Filter> filterClass = (Class<? extends Filter>) module.getClassLoader().loadClass(filter.getFilterClass());
                ManagedReferenceFactory creator = componentRegistry.createInstanceFactory(filterClass);
                FilterInfo f;
                if (creator != null) {
                    InstanceFactory<Filter> instanceFactory = createInstanceFactory(creator);
                    f = new FilterInfo(filter.getName(), filterClass, instanceFactory);
                } else {
                    f = new FilterInfo(filter.getName(), filterClass);
                }
                f.setAsyncSupported(filter.isAsyncSupported());
                d.addFilter(f);
                if (filter.getInitParam() != null) {
                    for (ParamValueMetaData initParam : filter.getInitParam()) {
                        f.addInitParam(initParam.getParamName(), initParam.getParamValue());
                    }
                }
            }
        }
        if (mergedMetaData.getFilterMappings() != null) {
            for (final FilterMappingMetaData mapping : mergedMetaData.getFilterMappings()) {
                if (mapping.getUrlPatterns() != null) {
                    for (String url : mapping.getUrlPatterns()) {
                        if (is22OrOlder && !url.startsWith("*") && !url.startsWith("/")) {
                            url = "/" + url;
                        }
                        if (mapping.getDispatchers() != null && !mapping.getDispatchers().isEmpty()) {
                            for (DispatcherType dispatcher : mapping.getDispatchers()) {
                                d.addFilterUrlMapping(mapping.getFilterName(), url, javax.servlet.DispatcherType.valueOf(dispatcher.name()));
                            }
                        } else {
                            d.addFilterUrlMapping(mapping.getFilterName(), url, javax.servlet.DispatcherType.REQUEST);
                        }
                    }
                }
                if (mapping.getServletNames() != null) {
                    for (String servletName : mapping.getServletNames()) {
                        if (mapping.getDispatchers() != null && !mapping.getDispatchers().isEmpty()) {
                            for (DispatcherType dispatcher : mapping.getDispatchers()) {
                                d.addFilterServletNameMapping(mapping.getFilterName(), servletName, javax.servlet.DispatcherType.valueOf(dispatcher.name()));
                            }
                        } else {
                            d.addFilterServletNameMapping(mapping.getFilterName(), servletName, javax.servlet.DispatcherType.REQUEST);
                        }
                    }
                }
            }
        }
        if (scisMetaData != null && scisMetaData.getHandlesTypes() != null) {
            for (final ServletContainerInitializer sci : scisMetaData.getScis()) {
                final ImmediateInstanceFactory<ServletContainerInitializer> instanceFactory = new ImmediateInstanceFactory<>(sci);
                d.addServletContainerInitalizer(new ServletContainerInitializerInfo(sci.getClass(), instanceFactory, scisMetaData.getHandlesTypes().get(sci)));
            }
        }
        if (mergedMetaData.getListeners() != null) {
            for (ListenerMetaData listener : mergedMetaData.getListeners()) {
                addListener(module.getClassLoader(), componentRegistry, d, listener);
            }
        }
        if (mergedMetaData.getContextParams() != null) {
            for (ParamValueMetaData param : mergedMetaData.getContextParams()) {
                d.addInitParameter(param.getParamName(), param.getParamValue());
            }
        }
        if (mergedMetaData.getWelcomeFileList() != null && mergedMetaData.getWelcomeFileList().getWelcomeFiles() != null) {
            List<String> welcomeFiles = mergedMetaData.getWelcomeFileList().getWelcomeFiles();
            for (String file : welcomeFiles) {
                if (file.startsWith("/")) {
                    d.addWelcomePages(file.substring(1));
                } else {
                    d.addWelcomePages(file);
                }
            }
        } else {
            d.addWelcomePages("index.html", "index.htm", "index.jsp");
        }
        d.addWelcomePages(servletContainer.getWelcomeFiles());
        if (mergedMetaData.getErrorPages() != null) {
            for (final ErrorPageMetaData page : mergedMetaData.getErrorPages()) {
                final ErrorPage errorPage;
                if (page.getExceptionType() != null && !page.getExceptionType().isEmpty()) {
                    errorPage = new ErrorPage(page.getLocation(), (Class<? extends Throwable>) module.getClassLoader().loadClass(page.getExceptionType()));
                } else if (page.getErrorCode() != null && !page.getErrorCode().isEmpty()) {
                    errorPage = new ErrorPage(page.getLocation(), Integer.parseInt(page.getErrorCode()));
                } else {
                    errorPage = new ErrorPage(page.getLocation());
                }
                d.addErrorPages(errorPage);
            }
        }
        for (Map.Entry<String, String> entry : servletContainer.getMimeMappings().entrySet()) {
            d.addMimeMapping(new MimeMapping(entry.getKey(), entry.getValue()));
        }
        if (mergedMetaData.getMimeMappings() != null) {
            for (final MimeMappingMetaData mapping : mergedMetaData.getMimeMappings()) {
                d.addMimeMapping(new MimeMapping(mapping.getExtension(), mapping.getMimeType()));
            }
        }
        d.setDenyUncoveredHttpMethods(mergedMetaData.getDenyUncoveredHttpMethods() != null);
        Set<String> securityRoleNames = mergedMetaData.getSecurityRoleNames();
        if (mergedMetaData.getSecurityConstraints() != null) {
            for (SecurityConstraintMetaData constraint : mergedMetaData.getSecurityConstraints()) {
                SecurityConstraint securityConstraint = new SecurityConstraint().setTransportGuaranteeType(transportGuaranteeType(constraint.getTransportGuarantee()));
                List<String> roleNames = constraint.getRoleNames();
                if (constraint.getAuthConstraint() == null) {
                    // no auth constraint means we permit the empty roles
                    securityConstraint.setEmptyRoleSemantic(PERMIT);
                } else if (roleNames.size() == 1 && roleNames.contains("*") && securityRoleNames.contains("*")) {
                    // AS7-6932 - Trying to do a * to * mapping which JBossWeb passed through, for Undertow enable
                    // authentication only mode.
                    // TODO - AS7-6933 - Revisit workaround added to allow switching between JBoss Web and Undertow.
                    securityConstraint.setEmptyRoleSemantic(AUTHENTICATE);
                } else {
                    securityConstraint.addRolesAllowed(roleNames);
                }
                if (constraint.getResourceCollections() != null) {
                    for (final WebResourceCollectionMetaData resourceCollection : constraint.getResourceCollections()) {
                        securityConstraint.addWebResourceCollection(new WebResourceCollection().addHttpMethods(resourceCollection.getHttpMethods()).addHttpMethodOmissions(resourceCollection.getHttpMethodOmissions()).addUrlPatterns(resourceCollection.getUrlPatterns()));
                    }
                }
                d.addSecurityConstraint(securityConstraint);
            }
        }
        final LoginConfigMetaData loginConfig = mergedMetaData.getLoginConfig();
        if (loginConfig != null) {
            List<AuthMethodConfig> authMethod = authMethod(loginConfig.getAuthMethod());
            if (loginConfig.getFormLoginConfig() != null) {
                d.setLoginConfig(new LoginConfig(loginConfig.getRealmName(), loginConfig.getFormLoginConfig().getLoginPage(), loginConfig.getFormLoginConfig().getErrorPage()));
            } else {
                d.setLoginConfig(new LoginConfig(loginConfig.getRealmName()));
            }
            for (AuthMethodConfig method : authMethod) {
                d.getLoginConfig().addLastAuthMethod(method);
            }
        }
        d.addSecurityRoles(mergedMetaData.getSecurityRoleNames());
        Map<String, Set<String>> principalVersusRolesMap = mergedMetaData.getPrincipalVersusRolesMap();
        BiFunction<DeploymentInfo, Function<String, RunAsIdentityMetaData>, Registration> securityFunction = this.securityFunction.getOptionalValue();
        if (securityFunction != null) {
            Map<String, RunAsIdentityMetaData> runAsIdentityMap = mergedMetaData.getRunAsIdentity();
            registration = securityFunction.apply(d, runAsIdentityMap::get);
            d.addOuterHandlerChainWrapper(JACCContextIdHandler.wrapper(jaccContextId));
            if (mergedMetaData.isUseJBossAuthorization()) {
                UndertowLogger.ROOT_LOGGER.configurationOptionIgnoredWhenUsingElytron("use-jboss-authorization");
            }
        } else {
            if (securityDomain != null) {
                d.addThreadSetupAction(new SecurityContextThreadSetupAction(securityDomain, securityDomainContextValue.getValue(), principalVersusRolesMap));
                d.addInnerHandlerChainWrapper(SecurityContextAssociationHandler.wrapper(mergedMetaData.getRunAsIdentity()));
                d.addOuterHandlerChainWrapper(JACCContextIdHandler.wrapper(jaccContextId));
                d.addLifecycleInterceptor(new RunAsLifecycleInterceptor(mergedMetaData.getRunAsIdentity()));
            }
        }
        if (principalVersusRolesMap != null) {
            for (Map.Entry<String, Set<String>> entry : principalVersusRolesMap.entrySet()) {
                d.addPrincipalVsRoleMappings(entry.getKey(), entry.getValue());
            }
        }
        // Setup an deployer configured ServletContext attributes
        if (attributes != null) {
            for (ServletContextAttribute attribute : attributes) {
                d.addServletContextAttribute(attribute.getName(), attribute.getValue());
            }
        }
        //now setup websockets if they are enabled
        if (servletContainer.isWebsocketsEnabled() && webSocketDeploymentInfo != null) {
            webSocketDeploymentInfo.setBuffers(servletContainer.getWebsocketsBufferPool().getValue());
            webSocketDeploymentInfo.setWorker(servletContainer.getWebsocketsWorker().getValue());
            webSocketDeploymentInfo.setDispatchToWorkerThread(servletContainer.isDispatchWebsocketInvocationToWorker());
            if (servletContainer.isPerMessageDeflate()) {
                PerMessageDeflateHandshake perMessageDeflate = new PerMessageDeflateHandshake(false, servletContainer.getDeflaterLevel());
                webSocketDeploymentInfo.addExtension(perMessageDeflate);
            }
            final AtomicReference<ServerActivity> serverActivity = new AtomicReference<>();
            webSocketDeploymentInfo.addListener(wsc -> {
                serverActivity.set(new ServerActivity() {

                    @Override
                    public void preSuspend(ServerActivityCallback listener) {
                        listener.done();
                    }

                    @Override
                    public void suspended(final ServerActivityCallback listener) {
                        if (wsc.getConfiguredServerEndpoints().isEmpty()) {
                            listener.done();
                            return;
                        }
                        wsc.pause(new ServerWebSocketContainer.PauseListener() {

                            @Override
                            public void paused() {
                                listener.done();
                            }

                            @Override
                            public void resumed() {
                            }
                        });
                    }

                    @Override
                    public void resume() {
                        wsc.resume();
                    }
                });
                suspendControllerInjectedValue.getValue().registerActivity(serverActivity.get());
            });
            ServletContextListener sl = new ServletContextListener() {

                @Override
                public void contextInitialized(ServletContextEvent sce) {
                }

                @Override
                public void contextDestroyed(ServletContextEvent sce) {
                    final ServerActivity activity = serverActivity.get();
                    if (activity != null) {
                        suspendControllerInjectedValue.getValue().unRegisterActivity(activity);
                    }
                }
            };
            d.addListener(new ListenerInfo(sl.getClass(), new ImmediateInstanceFactory<EventListener>(sl)));
            d.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSocketDeploymentInfo);
        }
        if (mergedMetaData.getLocalEncodings() != null && mergedMetaData.getLocalEncodings().getMappings() != null) {
            for (LocaleEncodingMetaData locale : mergedMetaData.getLocalEncodings().getMappings()) {
                d.addLocaleCharsetMapping(locale.getLocale(), locale.getEncoding());
            }
        }
        if (predicatedHandlers != null && !predicatedHandlers.isEmpty()) {
            d.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PostWrapper());
            d.addOuterHandlerChainWrapper(new HandlerWrapper() {

                @Override
                public HttpHandler wrap(HttpHandler handler) {
                    if (predicatedHandlers.size() == 1) {
                        PredicatedHandler ph = predicatedHandlers.get(0);
                        return Handlers.predicate(ph.getPredicate(), ph.getHandler().wrap(handler), handler);
                    } else {
                        return Handlers.predicates(predicatedHandlers, handler);
                    }
                }
            });
            d.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PreWrapper());
        }
        if (mergedMetaData.getDefaultEncoding() != null) {
            d.setDefaultEncoding(mergedMetaData.getDefaultEncoding());
        } else if (servletContainer.getDefaultEncoding() != null) {
            d.setDefaultEncoding(servletContainer.getDefaultEncoding());
        }
        d.setCrawlerSessionManagerConfig(servletContainer.getCrawlerSessionManagerConfig());
        return d;
    } catch (ClassNotFoundException e) {
        throw new StartException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainerInitializer(javax.servlet.ServletContainerInitializer) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) MultipartConfigMetaData(org.jboss.metadata.web.spec.MultipartConfigMetaData) DefaultServlet(io.undertow.servlet.handlers.DefaultServlet) DispatcherType(org.jboss.metadata.web.spec.DispatcherType) HttpHandler(io.undertow.server.HttpHandler) JSPConfig(org.wildfly.extension.undertow.JSPConfig) ServerActivity(org.jboss.as.server.suspend.ServerActivity) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) WebResourceCollectionMetaData(org.jboss.metadata.web.spec.WebResourceCollectionMetaData) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) HandlerWrapper(io.undertow.server.HandlerWrapper) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) SecurityConstraintMetaData(org.jboss.metadata.web.spec.SecurityConstraintMetaData) FileResourceManager(io.undertow.server.handlers.resource.FileResourceManager) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) DefaultServlet(io.undertow.servlet.handlers.DefaultServlet) Servlet(javax.servlet.Servlet) JspServlet(org.apache.jasper.servlet.JspServlet) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) StartException(org.jboss.msc.service.StartException) FilterInfo(io.undertow.servlet.api.FilterInfo) LoginConfigMetaData(org.jboss.metadata.web.spec.LoginConfigMetaData) ServletContainerInitializerInfo(io.undertow.servlet.api.ServletContainerInitializerInfo) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) ServletContainerService(org.wildfly.extension.undertow.ServletContainerService) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) HttpMethodSecurityInfo(io.undertow.servlet.api.HttpMethodSecurityInfo) LocaleEncodingMetaData(org.jboss.metadata.web.spec.LocaleEncodingMetaData) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory) ServerActivityCallback(org.jboss.as.server.suspend.ServerActivityCallback) LinkedHashSet(java.util.LinkedHashSet) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) ErrorPage(io.undertow.servlet.api.ErrorPage) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ServletContextListener(javax.servlet.ServletContextListener) JspPropertyGroup(org.apache.jasper.deploy.JspPropertyGroup) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) Registration(org.wildfly.extension.undertow.ApplicationSecurityDomainDefinition.Registration) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData) ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) ErrorPageMetaData(org.jboss.metadata.web.spec.ErrorPageMetaData) ResourceManager(io.undertow.server.handlers.resource.ResourceManager) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) FileResourceManager(io.undertow.server.handlers.resource.FileResourceManager) RunAsLifecycleInterceptor(org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor) MimeMappingMetaData(org.jboss.metadata.web.spec.MimeMappingMetaData) ServletMappingMetaData(org.jboss.metadata.web.spec.ServletMappingMetaData) ListenerInfo(io.undertow.servlet.api.ListenerInfo) SecurityContextThreadSetupAction(org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile) ServletSecurityInfo(io.undertow.servlet.api.ServletSecurityInfo) JBossServletMetaData(org.jboss.metadata.web.jboss.JBossServletMetaData) PredicatedHandler(io.undertow.server.handlers.builder.PredicatedHandler) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) RunAsIdentityMetaData(org.jboss.metadata.javaee.jboss.RunAsIdentityMetaData) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) LoginConfig(io.undertow.servlet.api.LoginConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) TagLibraryInfo(org.apache.jasper.deploy.TagLibraryInfo) MimeMapping(io.undertow.servlet.api.MimeMapping) JspServlet(org.apache.jasper.servlet.JspServlet) HttpMethodConstraintMetaData(org.jboss.metadata.web.spec.HttpMethodConstraintMetaData) SecurityRoleRefMetaData(org.jboss.metadata.javaee.spec.SecurityRoleRefMetaData) ComponentRegistry(org.jboss.as.ee.component.ComponentRegistry) Filter(javax.servlet.Filter) WebInjectionContainer(org.jboss.as.web.common.WebInjectionContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) ServletExtension(io.undertow.servlet.ServletExtension) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 3 with ServletContextAttribute

use of org.jboss.as.web.common.ServletContextAttribute in project wildfly by wildfly.

the class JSFBeanValidationFactoryProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // Get the CDI-enabled ValidatorFactory and add it to the servlet context
    ValidatorFactory validatorFactory = deploymentUnit.getAttachment(BeanValidationAttachments.VALIDATOR_FACTORY);
    if (validatorFactory != null) {
        deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(VALIDATOR_FACTORY_KEY, validatorFactory));
    }
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute)

Example 4 with ServletContextAttribute

use of org.jboss.as.web.common.ServletContextAttribute in project wildfly by wildfly.

the class UndertowDeploymentProcessor method processDeployment.

private void processDeployment(final WarMetaData warMetaData, final DeploymentUnit deploymentUnit, final ServiceTarget serviceTarget, final String deploymentName, final String hostName, final String serverInstanceName) throws DeploymentUnitProcessingException {
    ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit));
    }
    final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData();
    final List<SetupAction> setupActions = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS);
    ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY);
    final Set<ServiceName> dependentComponents = new HashSet<>();
    // see AS7-2077
    // basically we want to ignore components that have failed for whatever reason
    // if they are important they will be picked up when the web deployment actually starts
    final List<ServiceName> components = deploymentUnit.getAttachmentList(WebComponentDescription.WEB_COMPONENTS);
    final Set<ServiceName> failed = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.FAILED_COMPONENTS);
    for (final ServiceName component : components) {
        if (!failed.contains(component)) {
            dependentComponents.add(component);
        }
    }
    String servletContainerName = metaData.getServletContainerName();
    if (servletContainerName == null) {
        servletContainerName = defaultContainer;
    }
    boolean componentRegistryExists = true;
    ComponentRegistry componentRegistry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.COMPONENT_REGISTRY);
    if (componentRegistry == null) {
        componentRegistryExists = false;
        //we do this to avoid lots of other null checks
        //this will only happen if the EE subsystem is not installed
        componentRegistry = new ComponentRegistry(null);
    }
    final WebInjectionContainer injectionContainer = new WebInjectionContainer(module.getClassLoader(), componentRegistry);
    String jaccContextId = metaData.getJaccContextID();
    if (jaccContextId == null) {
        jaccContextId = deploymentUnit.getName();
    }
    if (deploymentUnit.getParent() != null) {
        jaccContextId = deploymentUnit.getParent().getName() + "!" + jaccContextId;
    }
    final String pathName = pathNameOfDeployment(deploymentUnit, metaData);
    boolean securityEnabled = deploymentUnit.hasAttachment(SecurityAttachments.SECURITY_ENABLED);
    String metaDataSecurityDomain = metaData.getSecurityDomain();
    if (metaDataSecurityDomain == null) {
        metaDataSecurityDomain = getJBossAppSecurityDomain(deploymentUnit);
    }
    if (metaDataSecurityDomain != null) {
        metaDataSecurityDomain = metaDataSecurityDomain.trim();
    }
    final String securityDomain;
    if (securityEnabled) {
        securityDomain = metaDataSecurityDomain == null ? defaultSecurityDomain : SecurityUtil.unprefixSecurityDomain(metaDataSecurityDomain);
    } else {
        securityDomain = null;
    }
    final Set<ServiceName> additionalDependencies = new HashSet<>();
    for (final SetupAction setupAction : setupActions) {
        Set<ServiceName> dependencies = setupAction.dependencies();
        if (dependencies != null) {
            additionalDependencies.addAll(dependencies);
        }
    }
    SharedSessionManagerConfig sharedSessionManagerConfig = deploymentUnit.getParent() != null ? deploymentUnit.getParent().getAttachment(UndertowAttachments.SHARED_SESSION_MANAGER_CONFIG) : null;
    if (!deploymentResourceRoot.isUsePhysicalCodeSource()) {
        try {
            deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(Constants.CODE_SOURCE_ATTRIBUTE_NAME, deploymentRoot.toURL()));
        } catch (MalformedURLException e) {
            throw new DeploymentUnitProcessingException(e);
        }
    }
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(Constants.PERMISSION_COLLECTION_ATTRIBUTE_NAME, deploymentUnit.getAttachment(Attachments.MODULE_PERMISSIONS)));
    additionalDependencies.addAll(warMetaData.getAdditionalDependencies());
    final ServiceName hostServiceName = UndertowService.virtualHostName(serverInstanceName, hostName);
    final ServiceName deploymentServiceName = UndertowService.deploymentServiceName(serverInstanceName, hostName, pathName);
    TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
    UndertowDeploymentInfoService undertowDeploymentInfoService = UndertowDeploymentInfoService.builder().setAttributes(deploymentUnit.getAttachmentList(ServletContextAttribute.ATTACHMENT_KEY)).setContextPath(pathName).setDeploymentName(//todo: is this deployment name concept really applicable?
    deploymentName).setDeploymentRoot(deploymentRoot).setMergedMetaData(warMetaData.getMergedJBossWebMetaData()).setModule(module).setScisMetaData(scisMetaData).setJaccContextId(jaccContextId).setSecurityDomain(securityDomain).setSharedTlds(tldsMetaData == null ? Collections.<TldMetaData>emptyList() : tldsMetaData.getSharedTlds(deploymentUnit)).setTldsMetaData(tldsMetaData).setSetupActions(setupActions).setSharedSessionManagerConfig(sharedSessionManagerConfig).setOverlays(warMetaData.getOverlays()).setExpressionFactoryWrappers(deploymentUnit.getAttachmentList(ExpressionFactoryWrapper.ATTACHMENT_KEY)).setPredicatedHandlers(deploymentUnit.getAttachment(UndertowHandlersDeploymentProcessor.PREDICATED_HANDLERS)).setInitialHandlerChainWrappers(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_INITIAL_HANDLER_CHAIN_WRAPPERS)).setInnerHandlerChainWrappers(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_INNER_HANDLER_CHAIN_WRAPPERS)).setOuterHandlerChainWrappers(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_OUTER_HANDLER_CHAIN_WRAPPERS)).setThreadSetupActions(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_THREAD_SETUP_ACTIONS)).setServletExtensions(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_SERVLET_EXTENSIONS)).setExplodedDeployment(ExplodedDeploymentMarker.isExplodedDeployment(deploymentUnit)).setWebSocketDeploymentInfo(deploymentUnit.getAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO)).setTempDir(warMetaData.getTempDir()).setExternalResources(deploymentUnit.getAttachmentList(UndertowAttachments.EXTERNAL_RESOURCES)).setAllowSuspendedRequests(deploymentUnit.getAttachmentList(UndertowAttachments.ALLOW_REQUEST_WHEN_SUSPENDED)).createUndertowDeploymentInfoService();
    final ServiceName deploymentInfoServiceName = deploymentServiceName.append(UndertowDeploymentInfoService.SERVICE_NAME);
    ServiceBuilder<DeploymentInfo> infoBuilder = serviceTarget.addService(deploymentInfoServiceName, undertowDeploymentInfoService).addDependency(UndertowService.SERVLET_CONTAINER.append(servletContainerName), ServletContainerService.class, undertowDeploymentInfoService.getContainer()).addDependency(UndertowService.UNDERTOW, UndertowService.class, undertowDeploymentInfoService.getUndertowService()).addDependency(hostServiceName, Host.class, undertowDeploymentInfoService.getHost()).addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, undertowDeploymentInfoService.getServerEnvironmentInjectedValue()).addDependency(SuspendController.SERVICE_NAME, SuspendController.class, undertowDeploymentInfoService.getSuspendControllerInjectedValue()).addDependencies(additionalDependencies);
    if (securityDomain != null) {
        if (knownSecurityDomain.test(securityDomain)) {
            infoBuilder.addDependency(deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT).getCapabilityServiceName(ApplicationSecurityDomainDefinition.APPLICATION_SECURITY_DOMAIN_CAPABILITY, securityDomain), BiFunction.class, undertowDeploymentInfoService.getSecurityFunctionInjector());
        } else {
            infoBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomain), SecurityDomainContext.class, undertowDeploymentInfoService.getSecurityDomainContextValue());
        }
    }
    if (RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
        String topLevelName;
        if (deploymentUnit.getParent() == null) {
            topLevelName = deploymentUnit.getName();
        } else {
            topLevelName = deploymentUnit.getParent().getName();
        }
        infoBuilder.addDependency(ControlPointService.serviceName(topLevelName, UndertowExtension.SUBSYSTEM_NAME), ControlPoint.class, undertowDeploymentInfoService.getControlPointInjectedValue());
    }
    final Set<String> seenExecutors = new HashSet<String>();
    if (metaData.getExecutorName() != null) {
        final InjectedValue<Executor> executor = new InjectedValue<Executor>();
        infoBuilder.addDependency(IOServices.WORKER.append(metaData.getExecutorName()), Executor.class, executor);
        undertowDeploymentInfoService.addInjectedExecutor(metaData.getExecutorName(), executor);
        seenExecutors.add(metaData.getExecutorName());
    }
    if (metaData.getServlets() != null) {
        for (JBossServletMetaData servlet : metaData.getServlets()) {
            if (servlet.getExecutorName() != null && !seenExecutors.contains(servlet.getExecutorName())) {
                final InjectedValue<Executor> executor = new InjectedValue<Executor>();
                infoBuilder.addDependency(IOServices.WORKER.append(servlet.getExecutorName()), Executor.class, executor);
                undertowDeploymentInfoService.addInjectedExecutor(servlet.getExecutorName(), executor);
                seenExecutors.add(servlet.getExecutorName());
            }
        }
    }
    if (componentRegistryExists) {
        infoBuilder.addDependency(ComponentRegistry.serviceName(deploymentUnit), ComponentRegistry.class, undertowDeploymentInfoService.getComponentRegistryInjectedValue());
    } else {
        undertowDeploymentInfoService.getComponentRegistryInjectedValue().setValue(new ImmediateValue<>(componentRegistry));
    }
    if (sharedSessionManagerConfig != null) {
        infoBuilder.addDependency(deploymentUnit.getParent().getServiceName().append(SharedSessionManagerConfig.SHARED_SESSION_MANAGER_SERVICE_NAME), SessionManagerFactory.class, undertowDeploymentInfoService.getSessionManagerFactoryInjector());
        infoBuilder.addDependency(deploymentUnit.getParent().getServiceName().append(SharedSessionManagerConfig.SHARED_SESSION_IDENTIFIER_CODEC_SERVICE_NAME), SessionIdentifierCodec.class, undertowDeploymentInfoService.getSessionIdentifierCodecInjector());
    } else {
        CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        ServiceName sessionManagerFactoryServiceName = installSessionManagerFactory(support, serviceTarget, deploymentServiceName, deploymentName, module, metaData, deploymentUnit.getAttachment(UndertowAttachments.SERVLET_CONTAINER_SERVICE));
        infoBuilder.addDependency(sessionManagerFactoryServiceName, SessionManagerFactory.class, undertowDeploymentInfoService.getSessionManagerFactoryInjector());
        ServiceName sessionIdentifierCodecServiceName = installSessionIdentifierCodec(serviceTarget, deploymentServiceName, deploymentName, metaData);
        infoBuilder.addDependency(sessionIdentifierCodecServiceName, SessionIdentifierCodec.class, undertowDeploymentInfoService.getSessionIdentifierCodecInjector());
    }
    infoBuilder.install();
    final boolean isWebappBundle = deploymentUnit.hasAttachment(Attachments.OSGI_MANIFEST);
    final UndertowDeploymentService service = new UndertowDeploymentService(injectionContainer, !isWebappBundle);
    final ServiceBuilder<UndertowDeploymentService> builder = serviceTarget.addService(deploymentServiceName, service).addDependencies(dependentComponents).addDependency(UndertowService.SERVLET_CONTAINER.append(defaultContainer), ServletContainerService.class, service.getContainer()).addDependency(hostServiceName, Host.class, service.getHost()).addDependencies(deploymentUnit.getAttachmentList(Attachments.WEB_DEPENDENCIES)).addDependency(deploymentInfoServiceName, DeploymentInfo.class, service.getDeploymentInfoInjectedValue());
    // inject the server executor which can be used by the WebDeploymentService for blocking tasks in start/stop
    // of that service
    Services.addServerExecutorDependency(builder, service.getServerExecutorInjector(), false);
    deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, deploymentServiceName);
    // adding JACC service
    if (securityEnabled) {
        AbstractSecurityDeployer<WarMetaData> deployer = new WarJACCDeployer();
        JaccService<WarMetaData> jaccService = deployer.deploy(deploymentUnit, jaccContextId);
        if (jaccService != null) {
            final ServiceName jaccServiceName = deploymentUnit.getServiceName().append(JaccService.SERVICE_NAME);
            ServiceBuilder<?> jaccBuilder = serviceTarget.addService(jaccServiceName, jaccService);
            if (deploymentUnit.getParent() != null) {
                // add dependency to parent policy
                final DeploymentUnit parentDU = deploymentUnit.getParent();
                jaccBuilder.addDependency(parentDU.getServiceName().append(JaccService.SERVICE_NAME), PolicyConfiguration.class, jaccService.getParentPolicyInjector());
            }
            // add dependency to web deployment service
            jaccBuilder.addDependency(deploymentServiceName);
            jaccBuilder.setInitialMode(Mode.PASSIVE).install();
        }
    }
    // OSGi web applications are activated in {@link WebContextActivationProcessor} according to bundle lifecycle changes
    if (isWebappBundle) {
        UndertowDeploymentService.ContextActivatorImpl activator = new UndertowDeploymentService.ContextActivatorImpl(builder.install());
        deploymentUnit.putAttachment(ContextActivator.ATTACHMENT_KEY, activator);
        deploymentUnit.addToAttachmentList(Attachments.BUNDLE_ACTIVE_DEPENDENCIES, deploymentServiceName);
    } else {
        builder.install();
    }
    // Process the web related mgmt information
    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    final ModelNode node = deploymentResourceSupport.getDeploymentSubsystemModel(UndertowExtension.SUBSYSTEM_NAME);
    node.get(DeploymentDefinition.CONTEXT_ROOT.getName()).set("".equals(pathName) ? "/" : pathName);
    node.get(DeploymentDefinition.VIRTUAL_HOST.getName()).set(hostName);
    node.get(DeploymentDefinition.SERVER.getName()).set(serverInstanceName);
    processManagement(deploymentUnit, metaData);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) InjectedValue(org.jboss.msc.value.InjectedValue) MalformedURLException(java.net.MalformedURLException) JBossServletMetaData(org.jboss.metadata.web.jboss.JBossServletMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) SharedSessionManagerConfig(org.wildfly.extension.undertow.session.SharedSessionManagerConfig) DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) Executor(java.util.concurrent.Executor) SuspendController(org.jboss.as.server.suspend.SuspendController) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) HashSet(java.util.HashSet) ServletContainerService(org.wildfly.extension.undertow.ServletContainerService) SetupAction(org.jboss.as.server.deployment.SetupAction) Host(org.wildfly.extension.undertow.Host) ServiceName(org.jboss.msc.service.ServiceName) ComponentRegistry(org.jboss.as.ee.component.ComponentRegistry) WebInjectionContainer(org.jboss.as.web.common.WebInjectionContainer) WarJACCDeployer(org.wildfly.extension.undertow.security.jacc.WarJACCDeployer) Module(org.jboss.modules.Module) ModelNode(org.jboss.dmr.ModelNode) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ServletContextAttribute (org.jboss.as.web.common.ServletContextAttribute)4 HashSet (java.util.HashSet)3 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 HandlerWrapper (io.undertow.server.HandlerWrapper)1 HttpHandler (io.undertow.server.HttpHandler)1 PredicatedHandler (io.undertow.server.handlers.builder.PredicatedHandler)1 CachingResourceManager (io.undertow.server.handlers.resource.CachingResourceManager)1 FileResourceManager (io.undertow.server.handlers.resource.FileResourceManager)1 ResourceManager (io.undertow.server.handlers.resource.ResourceManager)1 ServletExtension (io.undertow.servlet.ServletExtension)1 AuthMethodConfig (io.undertow.servlet.api.AuthMethodConfig)1 ErrorPage (io.undertow.servlet.api.ErrorPage)1 FilterInfo (io.undertow.servlet.api.FilterInfo)1 HttpMethodSecurityInfo (io.undertow.servlet.api.HttpMethodSecurityInfo)1 ListenerInfo (io.undertow.servlet.api.ListenerInfo)1 LoginConfig (io.undertow.servlet.api.LoginConfig)1 MimeMapping (io.undertow.servlet.api.MimeMapping)1