Search in sources :

Example 1 with MultipartConfigMetaData

use of org.jboss.metadata.web.spec.MultipartConfigMetaData in project wildfly by wildfly.

the class JSFMetadataProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    WarMetaData metaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (JsfVersionMarker.isJsfDisabled(deploymentUnit)) {
        return;
    }
    if (metaData == null || metaData.getMergedJBossWebMetaData() == null || metaData.getMergedJBossWebMetaData().getServlets() == null) {
        return;
    }
    JBossServletMetaData jsf = null;
    for (JBossServletMetaData servlet : metaData.getMergedJBossWebMetaData().getServlets()) {
        if (JAVAX_FACES_WEBAPP_FACES_SERVLET.equals(servlet.getServletClass())) {
            jsf = servlet;
        }
    }
    if (jsf != null && jsf.getMultipartConfig() == null) {
        // WFLY-2329 File upload doesn't work
        jsf.setMultipartConfig(new MultipartConfigMetaData());
    }
    if (disallowDoctypeDecl != null) {
        // Add the disallowDoctypeDecl context param if it's not already present
        setContextParameterIfAbsent(metaData.getMergedJBossWebMetaData(), DISALLOW_DOCTYPE_DECL, disallowDoctypeDecl.toString());
    }
    // This can otherwise cause missing @PreDestroy events.
    if (metaData.getMergedJBossWebMetaData().getDistributable() != null) {
        String disabled = Boolean.toString(false);
        if (!setContextParameterIfAbsent(metaData.getMergedJBossWebMetaData(), LAZY_BEAN_VALIDATION_PARAM, disabled).equals(disabled)) {
            JSFLogger.ROOT_LOGGER.lazyBeanValidationEnabled();
        }
    }
}
Also used : JBossServletMetaData(org.jboss.metadata.web.jboss.JBossServletMetaData) MultipartConfigMetaData(org.jboss.metadata.web.spec.MultipartConfigMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 2 with MultipartConfigMetaData

use of org.jboss.metadata.web.spec.MultipartConfigMetaData in project wildfly by wildfly.

the class UndertowDeploymentInfoService method createServletConfig.

private DeploymentInfo createServletConfig() throws StartException {
    final ComponentRegistry componentRegistry = this.componentRegistry.get();
    try {
        if (!mergedMetaData.isMetadataComplete()) {
            mergedMetaData.resolveAnnotations();
        }
        mergedMetaData.resolveRunAs();
        final DeploymentInfo d = new DeploymentInfo();
        d.setContextPath(contextPath);
        if (mergedMetaData.getDescriptionGroup() != null) {
            d.setDisplayName(mergedMetaData.getDescriptionGroup().getDisplayName());
        }
        d.setDeploymentName(deploymentName);
        d.setHostName(host.get().getName());
        final ServletContainerService servletContainer = container.get();
        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(servletContainer.getFileCacheMetadataSize(), servletContainer.getFileCacheMaxFileSize(), servletContainer.getBufferCache(), resourceManager, servletContainer.getFileCacheTimeToLive() == null ? (explodedDeployment ? 2000 : -1) : servletContainer.getFileCacheTimeToLive());
            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);
        }
        d.setDefaultCookieVersion(servletContainer.getDefaultCookieVersion());
        // 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.isDisableSessionIdReuse()) {
            d.setCheckOtherSessionManagers(false);
        }
        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<>();
        // default Jakarta Server Pages 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 CachingWebInjectionContainer(module.getClassLoader(), componentRegistry)));
            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 Jakarta Server Pages 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()).get());
        }
        Boolean proactiveAuthentication = mergedMetaData.getProactiveAuthentication();
        if (proactiveAuthentication == null) {
            proactiveAuthentication = container.get().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());
                }
            }
        }
        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, true);
                    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()).get());
            }
            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) {
            Set<String> tldListeners = new HashSet<>();
            for (Map.Entry<String, TagLibraryInfo> e : tldInfo.entrySet()) {
                tldListeners.addAll(Arrays.asList(e.getValue().getListeners()));
            }
            for (ListenerMetaData listener : mergedMetaData.getListeners()) {
                addListener(module.getClassLoader(), componentRegistry, d, listener, tldListeners.contains(listener.getListenerClass()));
            }
        }
        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();
        if (isElytronActive()) {
            Map<String, RunAsIdentityMetaData> runAsIdentityMap = mergedMetaData.getRunAsIdentity();
            applyElytronSecurity(d, runAsIdentityMap::get);
        } else {
            if (securityDomain != null) {
                throw UndertowLogger.ROOT_LOGGER.legacySecurityUnsupported();
            }
        }
        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());
            webSocketDeploymentInfo.setWorker(servletContainer.getWebsocketsWorker());
            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()) {
                            // TODO: remove this once undertow bug fix is upstream
                            listener.done();
                            return;
                        }
                        wsc.pause(new ServerWebSocketContainer.PauseListener() {

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

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

                    @Override
                    public void resume() {
                        wsc.resume();
                    }
                });
                suspendController.get().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) {
                        suspendController.get().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) {
                    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());
        d.setPreservePathOnForward(servletContainer.isPreservePathOnForward());
        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) CachingWebInjectionContainer(org.jboss.as.web.common.CachingWebInjectionContainer) 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) 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) MimeMappingMetaData(org.jboss.metadata.web.spec.MimeMappingMetaData) ServletMappingMetaData(org.jboss.metadata.web.spec.ServletMappingMetaData) ListenerInfo(io.undertow.servlet.api.ListenerInfo) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile) ServletSecurityInfo(io.undertow.servlet.api.ServletSecurityInfo) JBossServletMetaData(org.jboss.metadata.web.jboss.JBossServletMetaData) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) RunAsIdentityMetaData(org.jboss.metadata.javaee.jboss.RunAsIdentityMetaData) 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) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) ServletExtension(io.undertow.servlet.ServletExtension) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 3 with MultipartConfigMetaData

use of org.jboss.metadata.web.spec.MultipartConfigMetaData in project wildfly by wildfly.

the class WarAnnotationDeploymentProcessor method processAnnotations.

/**
 * Process a single index.
 *
 * @param index the annotation index
 *
 * @throws DeploymentUnitProcessingException
 */
protected WebMetaData processAnnotations(Index index) throws DeploymentUnitProcessingException {
    WebMetaData metaData = new WebMetaData();
    // @WebServlet
    final List<AnnotationInstance> webServletAnnotations = index.getAnnotations(webServlet);
    if (webServletAnnotations != null && !webServletAnnotations.isEmpty()) {
        ServletsMetaData servlets = new ServletsMetaData();
        List<ServletMappingMetaData> servletMappings = new ArrayList<ServletMappingMetaData>();
        for (final AnnotationInstance annotation : webServletAnnotations) {
            ServletMetaData servlet = new ServletMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebServletAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            servlet.setServletClass(classInfo.toString());
            AnnotationValue nameValue = annotation.value("name");
            if (nameValue == null || nameValue.asString().isEmpty()) {
                servlet.setName(classInfo.toString());
            } else {
                servlet.setName(nameValue.asString());
            }
            AnnotationValue loadOnStartup = annotation.value("loadOnStartup");
            if (loadOnStartup != null && loadOnStartup.asInt() >= 0) {
                servlet.setLoadOnStartupInt(loadOnStartup.asInt());
            }
            AnnotationValue asyncSupported = annotation.value("asyncSupported");
            if (asyncSupported != null) {
                servlet.setAsyncSupported(asyncSupported.asBoolean());
            }
            AnnotationValue initParamsValue = annotation.value("initParams");
            if (initParamsValue != null) {
                AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
                if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
                    List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
                    for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
                        ParamValueMetaData initParam = new ParamValueMetaData();
                        AnnotationValue initParamName = initParamsAnnotation.value("name");
                        AnnotationValue initParamValue = initParamsAnnotation.value();
                        if (initParamName == null || initParamValue == null) {
                            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
                        }
                        AnnotationValue initParamDescription = initParamsAnnotation.value("description");
                        initParam.setParamName(initParamName.asString());
                        initParam.setParamValue(initParamValue.asString());
                        if (initParamDescription != null) {
                            Descriptions descriptions = getDescription(initParamDescription.asString());
                            if (descriptions != null) {
                                initParam.setDescriptions(descriptions);
                            }
                        }
                        initParams.add(initParam);
                    }
                    servlet.setInitParam(initParams);
                }
            }
            AnnotationValue descriptionValue = annotation.value("description");
            AnnotationValue displayNameValue = annotation.value("displayName");
            AnnotationValue smallIconValue = annotation.value("smallIcon");
            AnnotationValue largeIconValue = annotation.value("largeIcon");
            DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
            if (descriptionGroup != null) {
                servlet.setDescriptionGroup(descriptionGroup);
            }
            ServletMappingMetaData servletMapping = new ServletMappingMetaData();
            servletMapping.setServletName(servlet.getName());
            List<String> urlPatterns = new ArrayList<String>();
            AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            urlPatternsValue = annotation.value();
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            if (!urlPatterns.isEmpty()) {
                servletMapping.setUrlPatterns(urlPatterns);
                servletMappings.add(servletMapping);
            }
            servlets.add(servlet);
        }
        metaData.setServlets(servlets);
        metaData.setServletMappings(servletMappings);
    }
    // @WebFilter
    final List<AnnotationInstance> webFilterAnnotations = index.getAnnotations(webFilter);
    if (webFilterAnnotations != null && !webFilterAnnotations.isEmpty()) {
        FiltersMetaData filters = new FiltersMetaData();
        List<FilterMappingMetaData> filterMappings = new ArrayList<FilterMappingMetaData>();
        for (final AnnotationInstance annotation : webFilterAnnotations) {
            FilterMetaData filter = new FilterMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFilterAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            filter.setFilterClass(classInfo.toString());
            AnnotationValue nameValue = annotation.value("filterName");
            if (nameValue == null || nameValue.asString().isEmpty()) {
                filter.setName(classInfo.toString());
            } else {
                filter.setName(nameValue.asString());
            }
            AnnotationValue asyncSupported = annotation.value("asyncSupported");
            if (asyncSupported != null) {
                filter.setAsyncSupported(asyncSupported.asBoolean());
            }
            AnnotationValue initParamsValue = annotation.value("initParams");
            if (initParamsValue != null) {
                AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
                if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
                    List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
                    for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
                        ParamValueMetaData initParam = new ParamValueMetaData();
                        AnnotationValue initParamName = initParamsAnnotation.value("name");
                        AnnotationValue initParamValue = initParamsAnnotation.value();
                        if (initParamName == null || initParamValue == null) {
                            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
                        }
                        AnnotationValue initParamDescription = initParamsAnnotation.value("description");
                        initParam.setParamName(initParamName.asString());
                        initParam.setParamValue(initParamValue.asString());
                        if (initParamDescription != null) {
                            Descriptions descriptions = getDescription(initParamDescription.asString());
                            if (descriptions != null) {
                                initParam.setDescriptions(descriptions);
                            }
                        }
                        initParams.add(initParam);
                    }
                    filter.setInitParam(initParams);
                }
            }
            AnnotationValue descriptionValue = annotation.value("description");
            AnnotationValue displayNameValue = annotation.value("displayName");
            AnnotationValue smallIconValue = annotation.value("smallIcon");
            AnnotationValue largeIconValue = annotation.value("largeIcon");
            DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
            if (descriptionGroup != null) {
                filter.setDescriptionGroup(descriptionGroup);
            }
            filters.add(filter);
            FilterMappingMetaData filterMapping = new FilterMappingMetaData();
            filterMapping.setFilterName(filter.getName());
            List<String> urlPatterns = new ArrayList<String>();
            List<String> servletNames = new ArrayList<String>();
            List<DispatcherType> dispatchers = new ArrayList<DispatcherType>();
            AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            urlPatternsValue = annotation.value();
            if (urlPatternsValue != null) {
                for (String urlPattern : urlPatternsValue.asStringArray()) {
                    urlPatterns.add(urlPattern);
                }
            }
            if (!urlPatterns.isEmpty()) {
                filterMapping.setUrlPatterns(urlPatterns);
            }
            AnnotationValue servletNamesValue = annotation.value("servletNames");
            if (servletNamesValue != null) {
                for (String servletName : servletNamesValue.asStringArray()) {
                    servletNames.add(servletName);
                }
            }
            if (!servletNames.isEmpty()) {
                filterMapping.setServletNames(servletNames);
            }
            AnnotationValue dispatcherTypesValue = annotation.value("dispatcherTypes");
            if (dispatcherTypesValue != null) {
                for (String dispatcherValue : dispatcherTypesValue.asEnumArray()) {
                    dispatchers.add(DispatcherType.valueOf(dispatcherValue));
                }
            }
            if (!dispatchers.isEmpty()) {
                filterMapping.setDispatchers(dispatchers);
            }
            if (!urlPatterns.isEmpty() || !servletNames.isEmpty()) {
                filterMappings.add(filterMapping);
            }
        }
        metaData.setFilters(filters);
        metaData.setFilterMappings(filterMappings);
    }
    // @WebListener
    final List<AnnotationInstance> webListenerAnnotations = index.getAnnotations(webListener);
    if (webListenerAnnotations != null && !webListenerAnnotations.isEmpty()) {
        List<ListenerMetaData> listeners = new ArrayList<ListenerMetaData>();
        for (final AnnotationInstance annotation : webListenerAnnotations) {
            ListenerMetaData listener = new ListenerMetaData();
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebListenerAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            listener.setListenerClass(classInfo.toString());
            AnnotationValue descriptionValue = annotation.value();
            if (descriptionValue != null) {
                DescriptionGroupMetaData descriptionGroup = getDescriptionGroup(descriptionValue.asString());
                if (descriptionGroup != null) {
                    listener.setDescriptionGroup(descriptionGroup);
                }
            }
            listeners.add(listener);
        }
        metaData.setListeners(listeners);
    }
    // @RunAs
    final List<AnnotationInstance> runAsAnnotations = index.getAnnotations(runAs);
    if (runAsAnnotations != null && !runAsAnnotations.isEmpty()) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : runAsAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                continue;
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            if (annotation.value() == null) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidRunAsAnnotation(target));
            }
            RunAsMetaData runAs = new RunAsMetaData();
            runAs.setRoleName(annotation.value().asString());
            annotationMD.setRunAs(runAs);
        }
    }
    // @DeclareRoles
    final List<AnnotationInstance> declareRolesAnnotations = index.getAnnotations(declareRoles);
    if (declareRolesAnnotations != null && !declareRolesAnnotations.isEmpty()) {
        SecurityRolesMetaData securityRoles = metaData.getSecurityRoles();
        if (securityRoles == null) {
            securityRoles = new SecurityRolesMetaData();
            metaData.setSecurityRoles(securityRoles);
        }
        for (final AnnotationInstance annotation : declareRolesAnnotations) {
            if (annotation.value() == null) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidDeclareRolesAnnotation(annotation.target()));
            }
            for (String role : annotation.value().asStringArray()) {
                SecurityRoleMetaData sr = new SecurityRoleMetaData();
                sr.setRoleName(role);
                securityRoles.add(sr);
            }
        }
    }
    // @MultipartConfig
    final List<AnnotationInstance> multipartConfigAnnotations = index.getAnnotations(multipartConfig);
    if (multipartConfigAnnotations != null && !multipartConfigAnnotations.isEmpty()) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : multipartConfigAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidMultipartConfigAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            MultipartConfigMetaData multipartConfig = new MultipartConfigMetaData();
            AnnotationValue locationValue = annotation.value("location");
            if (locationValue != null && locationValue.asString().length() > 0) {
                multipartConfig.setLocation(locationValue.asString());
            }
            AnnotationValue maxFileSizeValue = annotation.value("maxFileSize");
            if (maxFileSizeValue != null && maxFileSizeValue.asLong() != -1L) {
                multipartConfig.setMaxFileSize(maxFileSizeValue.asLong());
            }
            AnnotationValue maxRequestSizeValue = annotation.value("maxRequestSize");
            if (maxRequestSizeValue != null && maxRequestSizeValue.asLong() != -1L) {
                multipartConfig.setMaxRequestSize(maxRequestSizeValue.asLong());
            }
            AnnotationValue fileSizeThresholdValue = annotation.value("fileSizeThreshold");
            if (fileSizeThresholdValue != null && fileSizeThresholdValue.asInt() != 0) {
                multipartConfig.setFileSizeThreshold(fileSizeThresholdValue.asInt());
            }
            annotationMD.setMultipartConfig(multipartConfig);
        }
    }
    // @ServletSecurity
    final List<AnnotationInstance> servletSecurityAnnotations = index.getAnnotations(servletSecurity);
    if (servletSecurityAnnotations != null && !servletSecurityAnnotations.isEmpty()) {
        AnnotationsMetaData annotations = metaData.getAnnotations();
        if (annotations == null) {
            annotations = new AnnotationsMetaData();
            metaData.setAnnotations(annotations);
        }
        for (final AnnotationInstance annotation : servletSecurityAnnotations) {
            AnnotationTarget target = annotation.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidServletSecurityAnnotation(target));
            }
            ClassInfo classInfo = ClassInfo.class.cast(target);
            AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
            if (annotationMD == null) {
                annotationMD = new AnnotationMetaData();
                annotationMD.setClassName(classInfo.toString());
                annotations.add(annotationMD);
            }
            ServletSecurityMetaData servletSecurity = new ServletSecurityMetaData();
            AnnotationValue httpConstraintValue = annotation.value();
            List<String> rolesAllowed = new ArrayList<String>();
            if (httpConstraintValue != null) {
                AnnotationInstance httpConstraint = httpConstraintValue.asNested();
                AnnotationValue httpConstraintERSValue = httpConstraint.value();
                if (httpConstraintERSValue != null) {
                    servletSecurity.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpConstraintERSValue.asEnum()));
                }
                AnnotationValue httpConstraintTGValue = httpConstraint.value("transportGuarantee");
                if (httpConstraintTGValue != null) {
                    servletSecurity.setTransportGuarantee(TransportGuaranteeType.valueOf(httpConstraintTGValue.asEnum()));
                }
                AnnotationValue rolesAllowedValue = httpConstraint.value("rolesAllowed");
                if (rolesAllowedValue != null) {
                    for (String role : rolesAllowedValue.asStringArray()) {
                        rolesAllowed.add(role);
                    }
                }
            }
            servletSecurity.setRolesAllowed(rolesAllowed);
            AnnotationValue httpMethodConstraintsValue = annotation.value("httpMethodConstraints");
            if (httpMethodConstraintsValue != null) {
                AnnotationInstance[] httpMethodConstraints = httpMethodConstraintsValue.asNestedArray();
                if (httpMethodConstraints.length > 0) {
                    List<HttpMethodConstraintMetaData> methodConstraints = new ArrayList<HttpMethodConstraintMetaData>();
                    for (AnnotationInstance httpMethodConstraint : httpMethodConstraints) {
                        HttpMethodConstraintMetaData methodConstraint = new HttpMethodConstraintMetaData();
                        AnnotationValue httpMethodConstraintValue = httpMethodConstraint.value();
                        if (httpMethodConstraintValue != null) {
                            methodConstraint.setMethod(httpMethodConstraintValue.asString());
                        }
                        AnnotationValue httpMethodConstraintERSValue = httpMethodConstraint.value("emptyRoleSemantic");
                        if (httpMethodConstraintERSValue != null) {
                            methodConstraint.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpMethodConstraintERSValue.asEnum()));
                        }
                        AnnotationValue httpMethodConstraintTGValue = httpMethodConstraint.value("transportGuarantee");
                        if (httpMethodConstraintTGValue != null) {
                            methodConstraint.setTransportGuarantee(TransportGuaranteeType.valueOf(httpMethodConstraintTGValue.asEnum()));
                        }
                        AnnotationValue rolesAllowedValue = httpMethodConstraint.value("rolesAllowed");
                        rolesAllowed = new ArrayList<String>();
                        if (rolesAllowedValue != null) {
                            for (String role : rolesAllowedValue.asStringArray()) {
                                rolesAllowed.add(role);
                            }
                        }
                        methodConstraint.setRolesAllowed(rolesAllowed);
                        methodConstraints.add(methodConstraint);
                    }
                    servletSecurity.setHttpMethodConstraints(methodConstraints);
                }
            }
            annotationMD.setServletSecurity(servletSecurity);
        }
    }
    return metaData;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) SecurityRoleMetaData(org.jboss.metadata.javaee.spec.SecurityRoleMetaData) ArrayList(java.util.ArrayList) SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) ServletSecurityMetaData(org.jboss.metadata.web.spec.ServletSecurityMetaData) Descriptions(org.jboss.annotation.javaee.Descriptions) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) MultipartConfigMetaData(org.jboss.metadata.web.spec.MultipartConfigMetaData) ServletMetaData(org.jboss.metadata.web.spec.ServletMetaData) DispatcherType(org.jboss.metadata.web.spec.DispatcherType) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData) AnnotationTarget(org.jboss.jandex.AnnotationTarget) ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) RunAsMetaData(org.jboss.metadata.javaee.spec.RunAsMetaData) HttpMethodConstraintMetaData(org.jboss.metadata.web.spec.HttpMethodConstraintMetaData) FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) ServletMappingMetaData(org.jboss.metadata.web.spec.ServletMappingMetaData) ServletsMetaData(org.jboss.metadata.web.spec.ServletsMetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) DescriptionGroupMetaData(org.jboss.metadata.javaee.spec.DescriptionGroupMetaData) AnnotationsMetaData(org.jboss.metadata.web.spec.AnnotationsMetaData) AnnotationMetaData(org.jboss.metadata.web.spec.AnnotationMetaData) WebMetaData(org.jboss.metadata.web.spec.WebMetaData) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

MultipartConfigMetaData (org.jboss.metadata.web.spec.MultipartConfigMetaData)3 ArrayList (java.util.ArrayList)2 JBossServletMetaData (org.jboss.metadata.web.jboss.JBossServletMetaData)2 HandlerWrapper (io.undertow.server.HandlerWrapper)1 HttpHandler (io.undertow.server.HttpHandler)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 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)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 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)1 ServletContainerInitializerInfo (io.undertow.servlet.api.ServletContainerInitializerInfo)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1