Search in sources :

Example 1 with WebSessionCookieConfig

use of com.sun.enterprise.web.session.WebSessionCookieConfig in project Payara by payara.

the class TomcatDeploymentConfig method configureStandardContext.

/**
 * Configure the <code>WebModule</code> instance by creating
 * <code>StandardWrapper</code> using the information contained
 * in the deployment descriptor (Welcome Files, JSP, Servlets etc.)
 */
protected static void configureStandardContext(WebModule webModule, WebBundleDescriptorImpl wmd) {
    for (WebComponentDescriptor webComponentDesc : wmd.getWebComponentDescriptors()) {
        addWebComponentDescriptor(webModule, webComponentDesc);
    }
    SessionConfig sessionConfig = wmd.getSessionConfig();
    // <session-config><session-timeout>
    webModule.setSessionTimeout(sessionConfig.getSessionTimeout());
    // <session-config><cookie-config>
    CookieConfig cookieConfig = sessionConfig.getCookieConfig();
    if (cookieConfig != null) {
        SessionCookieConfig sessionCookieConfig = webModule.getSessionCookieConfig();
        /* 
             * Unlike a cookie's domain, path, and comment, its name
             * will be empty (instead of null) if left unspecified
             * inside <session-config><cookie-config>
             */
        if (cookieConfig.getName() != null && !cookieConfig.getName().isEmpty()) {
            sessionCookieConfig.setName(cookieConfig.getName());
        }
        sessionCookieConfig.setDomain(cookieConfig.getDomain());
        sessionCookieConfig.setPath(cookieConfig.getPath());
        sessionCookieConfig.setComment(cookieConfig.getComment());
        sessionCookieConfig.setHttpOnly(cookieConfig.isHttpOnly());
        sessionCookieConfig.setSecure(cookieConfig.isSecure());
        sessionCookieConfig.setMaxAge(cookieConfig.getMaxAge());
    }
    // <session-config><tracking-mode>
    if (!sessionConfig.getTrackingModes().isEmpty()) {
        webModule.setSessionTrackingModes(sessionConfig.getTrackingModes());
    }
    // glassfish-web.xml override the web.xml
    com.sun.enterprise.web.session.SessionCookieConfig gfSessionCookieConfig = webModule.getSessionCookieConfigFromSunWebXml();
    if (gfSessionCookieConfig != null) {
        WebSessionCookieConfig sessionCookieConfig = (WebSessionCookieConfig) webModule.getSessionCookieConfig();
        if (gfSessionCookieConfig.getName() != null && !gfSessionCookieConfig.getName().isEmpty()) {
            sessionCookieConfig.setName(gfSessionCookieConfig.getName());
        }
        if (gfSessionCookieConfig.getPath() != null) {
            sessionCookieConfig.setPath(gfSessionCookieConfig.getPath());
        }
        if (gfSessionCookieConfig.getMaxAge() != null) {
            sessionCookieConfig.setMaxAge(gfSessionCookieConfig.getMaxAge());
        }
        if (gfSessionCookieConfig.getDomain() != null) {
            sessionCookieConfig.setDomain(gfSessionCookieConfig.getDomain());
        }
        if (gfSessionCookieConfig.getComment() != null) {
            sessionCookieConfig.setComment(gfSessionCookieConfig.getComment());
        }
        if (gfSessionCookieConfig.getSecure() != null) {
            sessionCookieConfig.setSecure(gfSessionCookieConfig.getSecure());
        }
        if (gfSessionCookieConfig.getHttpOnly() != null) {
            sessionCookieConfig.setHttpOnly(gfSessionCookieConfig.getHttpOnly());
        }
    }
    Enumeration enumeration = wmd.getWelcomeFiles();
    while (enumeration.hasMoreElements()) {
        webModule.addWelcomeFile((String) enumeration.nextElement());
    }
    LocaleEncodingMappingListDescriptor lemds = wmd.getLocaleEncodingMappingListDescriptor();
    if (lemds != null) {
        for (LocaleEncodingMappingDescriptor lemd : lemds.getLocaleEncodingMappingSet()) {
            webModule.addLocaleEncodingMappingParameter(lemd.getLocale(), lemd.getEncoding());
        }
    }
    webModule.setOrderedLibs(wmd.getOrderedLibs());
    String[] majorMinorVersions = wmd.getSpecVersion().split("\\.");
    if (majorMinorVersions.length != 2) {
        throw new IllegalArgumentException("Illegal Servlet spec version");
    }
    webModule.setEffectiveMajorVersion(Integer.parseInt(majorMinorVersions[0]));
    webModule.setEffectiveMinorVersion(Integer.parseInt(majorMinorVersions[1]));
}
Also used : Enumeration(java.util.Enumeration) WebSessionCookieConfig(com.sun.enterprise.web.session.WebSessionCookieConfig) SessionCookieConfig(javax.servlet.SessionCookieConfig) WebSessionCookieConfig(com.sun.enterprise.web.session.WebSessionCookieConfig) WebSessionCookieConfig(com.sun.enterprise.web.session.WebSessionCookieConfig) SessionCookieConfig(javax.servlet.SessionCookieConfig)

Example 2 with WebSessionCookieConfig

use of com.sun.enterprise.web.session.WebSessionCookieConfig in project Payara by payara.

the class PwcCoyoteRequest method configureSessionCookie.

/*
     * Configures the given JSESSIONID cookie with the cookie-properties from
     * sun-web.xml.
     *
     * @param cookie The JSESSIONID cookie to be configured
     */
@Override
public void configureSessionCookie(Cookie cookie) {
    super.configureSessionCookie(cookie);
    PwcWebModule wm = (PwcWebModule) getContext();
    WebSessionCookieConfig cookieConfig = (WebSessionCookieConfig) wm.getSessionCookieConfig();
    CookieSecureType type = cookieConfig.getSecure();
    if (CookieSecureType.TRUE == type) {
        cookie.setSecure(true);
    } else if (CookieSecureType.FALSE == type) {
        cookie.setSecure(false);
    } else {
        cookie.setSecure(isSecure());
    }
}
Also used : PwcWebModule(com.sun.enterprise.web.pwc.PwcWebModule) CookieSecureType(com.sun.enterprise.web.session.WebSessionCookieConfig.CookieSecureType) WebSessionCookieConfig(com.sun.enterprise.web.session.WebSessionCookieConfig)

Aggregations

WebSessionCookieConfig (com.sun.enterprise.web.session.WebSessionCookieConfig)2 PwcWebModule (com.sun.enterprise.web.pwc.PwcWebModule)1 CookieSecureType (com.sun.enterprise.web.session.WebSessionCookieConfig.CookieSecureType)1 Enumeration (java.util.Enumeration)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1