Search in sources :

Example 1 with FiltersMetaData

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

the class WebIntegrationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription module = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        WeldLogger.DEPLOYMENT_LOGGER.debug("Not installing Weld web tier integration as no war metadata found");
        return;
    }
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        WeldLogger.DEPLOYMENT_LOGGER.debug("Not installing Weld web tier integration as no merged web metadata found");
        return;
    }
    if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
            createDependency(deploymentUnit, warMetaData);
        }
        return;
    }
    createDependency(deploymentUnit, warMetaData);
    List<ListenerMetaData> listeners = webMetaData.getListeners();
    if (listeners == null) {
        listeners = new ArrayList<ListenerMetaData>();
        webMetaData.setListeners(listeners);
    } else {
        // if the weld servlet listener is present remove it
        // this should allow wars to be portable between AS7 and servlet containers
        final ListIterator<ListenerMetaData> iterator = listeners.listIterator();
        while (iterator.hasNext()) {
            final ListenerMetaData listener = iterator.next();
            if (listener.getListenerClass().trim().equals(WELD_SERVLET_LISTENER)) {
                WeldLogger.DEPLOYMENT_LOGGER.debugf("Removing weld servlet listener %s from web config, as it is not needed in EE6 environments", WELD_SERVLET_LISTENER);
                iterator.remove();
                break;
            }
        }
    }
    listeners.add(0, INITIAL_LISTENER_METADATA);
    listeners.add(TERMINAL_LISTENER_MEDATADA);
    // These listeners use resource injection, so they need to be components
    registerAsComponent(WELD_INITIAL_LISTENER, deploymentUnit);
    registerAsComponent(WELD_TERMINAL_LISTENER, deploymentUnit);
    deploymentUnit.addToAttachmentList(ExpressionFactoryWrapper.ATTACHMENT_KEY, WeldJspExpressionFactoryWrapper.INSTANCE);
    if (webMetaData.getContextParams() == null) {
        webMetaData.setContextParams(new ArrayList<ParamValueMetaData>());
    }
    final List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    setupWeldContextIgnores(contextParams, InitParameters.CONTEXT_IGNORE_FORWARD);
    setupWeldContextIgnores(contextParams, InitParameters.CONTEXT_IGNORE_INCLUDE);
    if (webMetaData.getFilterMappings() != null) {
        // register ConversationFilter
        boolean filterMappingFound = false;
        for (FilterMappingMetaData mapping : webMetaData.getFilterMappings()) {
            if (CONVERSATION_FILTER_NAME.equals(mapping.getFilterName())) {
                filterMappingFound = true;
                break;
            }
        }
        if (filterMappingFound) {
            // otherwise WeldListener will take care of conversation context activation
            boolean filterFound = false;
            // register ConversationFilter
            if (webMetaData.getFilters() == null) {
                webMetaData.setFilters(new FiltersMetaData());
            }
            for (FilterMetaData filter : webMetaData.getFilters()) {
                if (CONVERSATION_FILTER_CLASS.equals(filter.getFilterClass())) {
                    filterFound = true;
                    break;
                }
            }
            if (!filterFound) {
                webMetaData.getFilters().add(conversationFilterMetadata);
                registerAsComponent(CONVERSATION_FILTER_CLASS, deploymentUnit);
                webMetaData.getContextParams().add(CONVERSATION_FILTER_INITIALIZED);
            }
        }
    }
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData)

Example 2 with FiltersMetaData

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

the class DevelopmentModeProcessor method registerProbeFilter.

private void registerProbeFilter(DeploymentUnit deploymentUnit, JBossWebMetaData webMetaData) throws DeploymentUnitProcessingException {
    if (webMetaData.getFilters() == null) {
        webMetaData.setFilters(new FiltersMetaData());
    }
    if (webMetaData.getFilterMappings() == null) {
        webMetaData.setFilterMappings(new ArrayList<FilterMappingMetaData>());
    }
    // probe filter
    webMetaData.getFilters().add(PROBE_FILTER);
    // probe filter mapping
    webMetaData.getFilterMappings().add(0, PROBE_FILTER_MAPPING);
    Utils.registerAsComponent(PROBE_FILTER_CLASS_NAME, deploymentUnit);
}
Also used : FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData)

Example 3 with FiltersMetaData

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

the class TracingDeploymentProcessor method addJaxRsIntegration.

private void addJaxRsIntegration(DeploymentUnit deploymentUnit) {
    JBossWebMetaData jbossWebMetaData = getJBossWebMetaData(deploymentUnit);
    if (jbossWebMetaData == null) {
        return;
    }
    addResteasyProvidersParameter(jbossWebMetaData);
    if (jbossWebMetaData.getFilters() == null) {
        jbossWebMetaData.setFilters(new FiltersMetaData());
    }
    FilterMetaData filter = new FilterMetaData();
    filter.setFilterClass("io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter");
    filter.setAsyncSupported(true);
    filter.setFilterName("io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter");
    jbossWebMetaData.getFilters().add(filter);
    FilterMappingMetaData mapping = new FilterMappingMetaData();
    mapping.setFilterName("io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter");
    mapping.setDispatchers(Collections.singletonList(DispatcherType.REQUEST));
    mapping.setUrlPatterns(Collections.singletonList("*"));
    if (jbossWebMetaData.getFilterMappings() == null) {
        jbossWebMetaData.setFilterMappings(new ArrayList<FilterMappingMetaData>());
    }
    jbossWebMetaData.getFilterMappings().add(mapping);
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData)

Example 4 with FiltersMetaData

use of org.jboss.metadata.web.spec.FiltersMetaData 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

FilterMappingMetaData (org.jboss.metadata.web.spec.FilterMappingMetaData)4 FiltersMetaData (org.jboss.metadata.web.spec.FiltersMetaData)4 FilterMetaData (org.jboss.metadata.web.spec.FilterMetaData)3 ParamValueMetaData (org.jboss.metadata.javaee.spec.ParamValueMetaData)2 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)2 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)2 ArrayList (java.util.ArrayList)1 Descriptions (org.jboss.annotation.javaee.Descriptions)1 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 WarMetaData (org.jboss.as.web.common.WarMetaData)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 AnnotationTarget (org.jboss.jandex.AnnotationTarget)1 AnnotationValue (org.jboss.jandex.AnnotationValue)1 ClassInfo (org.jboss.jandex.ClassInfo)1 DescriptionGroupMetaData (org.jboss.metadata.javaee.spec.DescriptionGroupMetaData)1 RunAsMetaData (org.jboss.metadata.javaee.spec.RunAsMetaData)1 SecurityRoleMetaData (org.jboss.metadata.javaee.spec.SecurityRoleMetaData)1