Search in sources :

Example 16 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class WebBundleRuntimeNode method addDescriptor.

/**
 * Adds  a new DOL descriptor instance to the descriptor instance associated with
 * this XMLNode
 *
 * @param newDescriptor the new descriptor
 */
@Override
public void addDescriptor(Object newDescriptor) {
    SunWebAppImpl sunWebApp = (SunWebAppImpl) descriptor.getSunDescriptor();
    if (newDescriptor instanceof WebComponentDescriptor) {
        WebComponentDescriptor servlet = (WebComponentDescriptor) newDescriptor;
        // for backward compatibility with s1as schema2beans generated desc
        Servlet s1descriptor = new Servlet();
        s1descriptor.setServletName(servlet.getCanonicalName());
        if (servlet.getRunAsIdentity() != null) {
            s1descriptor.setPrincipalName(servlet.getRunAsIdentity().getPrincipal());
        }
        sunWebApp.addServlet(s1descriptor);
    } else if (newDescriptor instanceof ServiceReferenceDescriptor) {
        descriptor.addServiceReferenceDescriptor((ServiceReferenceDescriptor) newDescriptor);
    } else if (newDescriptor instanceof SecurityRoleMapping) {
        SecurityRoleMapping srm = (SecurityRoleMapping) newDescriptor;
        sunWebApp.addSecurityRoleMapping(srm);
        // store it in the application using pure DOL descriptors...
        Application app = descriptor.getApplication();
        if (app != null) {
            Role role = new Role(srm.getRoleName());
            SecurityRoleMapper rm = app.getRoleMapper();
            if (rm != null) {
                List<PrincipalNameDescriptor> principals = srm.getPrincipalNames();
                for (int i = 0; i < principals.size(); i++) {
                    rm.assignRole(principals.get(i).getPrincipal(), role, descriptor);
                }
                List<String> groups = srm.getGroupNames();
                for (int i = 0; i < groups.size(); i++) {
                    rm.assignRole(new Group(groups.get(i)), role, descriptor);
                }
            }
        }
    } else if (newDescriptor instanceof IdempotentUrlPattern) {
        sunWebApp.addIdempotentUrlPattern((IdempotentUrlPattern) newDescriptor);
    } else if (newDescriptor instanceof SessionConfig) {
        sunWebApp.setSessionConfig((SessionConfig) newDescriptor);
    } else if (newDescriptor instanceof Cache) {
        sunWebApp.setCache((Cache) newDescriptor);
    } else if (newDescriptor instanceof ClassLoader) {
        sunWebApp.setClassLoader((ClassLoader) newDescriptor);
    } else if (newDescriptor instanceof JspConfig) {
        sunWebApp.setJspConfig((JspConfig) newDescriptor);
    } else if (newDescriptor instanceof LocaleCharsetInfo) {
        sunWebApp.setLocaleCharsetInfo((LocaleCharsetInfo) newDescriptor);
    } else if (newDescriptor instanceof WebProperty) {
        sunWebApp.addWebProperty((WebProperty) newDescriptor);
    } else if (newDescriptor instanceof Valve) {
        sunWebApp.addValve((Valve) newDescriptor);
    } else
        super.addDescriptor(descriptor);
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) Group(org.glassfish.security.common.Group) JspConfig(org.glassfish.web.deployment.runtime.JspConfig) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) SecurityRoleMapping(com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping) SecurityRoleMapper(org.glassfish.deployment.common.SecurityRoleMapper) IdempotentUrlPattern(com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern) PrincipalNameDescriptor(com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor) SessionConfig(org.glassfish.web.deployment.runtime.SessionConfig) ServiceReferenceDescriptor(com.sun.enterprise.deployment.ServiceReferenceDescriptor) Role(org.glassfish.security.common.Role) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) Servlet(org.glassfish.web.deployment.runtime.Servlet) ClassLoader(org.glassfish.web.deployment.runtime.ClassLoader) Valve(org.glassfish.web.deployment.runtime.Valve) Application(com.sun.enterprise.deployment.Application) LocaleCharsetInfo(org.glassfish.web.deployment.runtime.LocaleCharsetInfo) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 17 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class JSPCompiler method configureJspc.

// //////////////////////////////////////////////////////////////////////////
/*
     * Configures the given JspC instance with the jsp-config properties
	 * specified in the sun-web.xml of the web module represented by the
	 * given WebBundleDescriptor.
	 *
	 * @param jspc JspC instance to be configured
	 * @param wbd WebBundleDescriptor of the web module whose sun-web.xml
     * is used to configure the given JspC instance
	 */
private static void configureJspc(JspC jspc, WebBundleDescriptor wbd) {
    SunWebAppImpl sunWebApp = (SunWebAppImpl) wbd.getSunDescriptor();
    if (sunWebApp == null) {
        return;
    }
    // START SJSAS 6384538
    if (sunWebApp.sizeWebProperty() > 0) {
        WebProperty[] props = sunWebApp.getWebProperty();
        for (int i = 0; i < props.length; i++) {
            String pName = props[i].getAttributeValue("name");
            String pValue = props[i].getAttributeValue("value");
            if (pName == null || pValue == null) {
                throw new IllegalArgumentException("Missing sun-web-app property name or value");
            }
            if ("enableTldValidation".equals(pName)) {
                jspc.setIsValidationEnabled(Boolean.valueOf(pValue).booleanValue());
            }
        }
    }
    // END SJSAS 6384538
    // START SJSAS 6170435
    /*
             * Configure JspC with the init params of the JspServlet
             */
    Set<WebComponentDescriptor> set = wbd.getWebComponentDescriptors();
    if (!set.isEmpty()) {
        Iterator<WebComponentDescriptor> iterator = set.iterator();
        while (iterator.hasNext()) {
            WebComponentDescriptor webComponentDesc = iterator.next();
            if ("jsp".equals(webComponentDesc.getCanonicalName())) {
                Enumeration<InitializationParameter> en = webComponentDesc.getInitializationParameters();
                if (en != null) {
                    while (en.hasMoreElements()) {
                        InitializationParameter initP = en.nextElement();
                        configureJspc(jspc, initP.getName(), initP.getValue());
                    }
                }
                break;
            }
        }
    }
    // END SJSAS 6170435
    /*
             * Configure JspC with jsp-config properties from sun-web.xml,
             * which override JspServlet init params of the same name.
             */
    JspConfig jspConfig = sunWebApp.getJspConfig();
    if (jspConfig == null) {
        return;
    }
    WebProperty[] props = jspConfig.getWebProperty();
    for (int i = 0; props != null && i < props.length; i++) {
        configureJspc(jspc, props[i].getAttributeValue("name"), props[i].getAttributeValue("value"));
    }
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) JspConfig(org.glassfish.web.deployment.runtime.JspConfig) InitializationParameter(com.sun.enterprise.deployment.web.InitializationParameter)

Example 18 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class WebBundleContext method createContextForWeb.

/**
 * This method create a context for web component(s) by using
 * descriptor(s) associated to given webComponet impl class.
 * Return null if corresponding descriptor is not found.
 */
public AnnotatedElementHandler createContextForWeb() {
    AnnotatedElement anTypeElement = this.getProcessingContext().getProcessor().getLastAnnotatedElement(ElementType.TYPE);
    WebComponentDescriptor[] webComps = null;
    if (anTypeElement != null) {
        String implClassName = ((Class) anTypeElement).getName();
        webComps = getDescriptor().getWebComponentByImplName(implClassName);
    }
    AnnotatedElementHandler aeHandler = null;
    if (webComps != null && webComps.length > 1) {
        aeHandler = new WebComponentsContext(webComps);
    } else if (webComps != null && webComps.length == 1) {
        aeHandler = new WebComponentContext(webComps[0]);
    }
    if (aeHandler != null) {
        // push a WebComponent(s)Context to stack
        this.getProcessingContext().pushHandler(aeHandler);
    }
    return aeHandler;
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Example 19 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class ServletParamValue method check.

/**
 * Param Value exists test.
 *      *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Set servlets;
    Iterator itr;
    String epValue;
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    WebComponentDescriptor servlet;
    Enumeration en;
    EnvironmentProperty ep = null;
    boolean oneFailed = false;
    boolean status = false;
    boolean notApp = false;
    if (!descriptor.getServletDescriptors().isEmpty()) {
        // get the servlets in this .war
        servlets = descriptor.getServletDescriptors();
        itr = servlets.iterator();
        // test the servlets in this .war
        while (itr.hasNext()) {
            servlet = (WebComponentDescriptor) itr.next();
            en = servlet.getInitializationParameters();
            if (en.hasMoreElements()) {
                ep = (EnvironmentProperty) en.nextElement();
                epValue = ep.getValue();
                if (epValue.length() != 0) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Param named/value exists for in the servlet [ {0} ].", new Object[] { servlet.getName() }));
                } else {
                    // failed
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Param name/value entry should of finite length."));
                }
            }
        }
    } else {
        notApp = true;
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no initialization parameters for the servlet within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else if (notApp) {
        result.setStatus(Result.NOT_APPLICABLE);
    } else {
        result.setStatus(Result.PASSED);
    }
    return result;
}
Also used : WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor)

Example 20 with WebComponentDescriptor

use of com.sun.enterprise.deployment.WebComponentDescriptor in project Payara by payara.

the class RunAsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebComponentContext[] webCompContexts) throws AnnotationProcessorException {
    RunAs runAsAn = (RunAs) ainfo.getAnnotation();
    for (WebComponentContext webCompContext : webCompContexts) {
        WebComponentDescriptor webDesc = webCompContext.getDescriptor();
        // override by xml
        if (webDesc.getRunAsIdentity() != null) {
            continue;
        }
        String roleName = runAsAn.value();
        Role role = new Role(roleName);
        // add Role if not exists
        webDesc.getWebBundleDescriptor().addRole(role);
        RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
        runAsDesc.setRoleName(roleName);
        webDesc.setRunAsIdentity(runAsDesc);
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) WebComponentDescriptor(com.sun.enterprise.deployment.WebComponentDescriptor) WebComponentContext(com.sun.enterprise.deployment.annotation.context.WebComponentContext) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) RunAs(javax.annotation.security.RunAs)

Aggregations

WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)28 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)7 Iterator (java.util.Iterator)5 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)4 WebComponentContext (com.sun.enterprise.deployment.annotation.context.WebComponentContext)4 Role (org.glassfish.security.common.Role)4 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)3 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)3 WebServicesDescriptor (com.sun.enterprise.deployment.WebServicesDescriptor)3 Set (java.util.Set)3 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)3 Application (com.sun.enterprise.deployment.Application)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebService (com.sun.enterprise.deployment.WebService)2 WebBundleContext (com.sun.enterprise.deployment.annotation.context.WebBundleContext)2 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)2 IdempotentUrlPattern (com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 WebServlet (javax.servlet.annotation.WebServlet)2 SecurityRoleMapper (org.glassfish.deployment.common.SecurityRoleMapper)2