Example usage for javax.servlet FilterConfig getServletContext

List of usage examples for javax.servlet FilterConfig getServletContext

Introduction

In this page you can find the example usage for javax.servlet FilterConfig getServletContext.

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:org.sakaiproject.util.RequestFilter.java

/**
 * Place this filter into service.//from  w w w  .j  a  v a  2 s.  c  o m
 *
 * @param filterConfig
 *        The filter configuration object
 */
public void init(FilterConfig filterConfig) throws ServletException {

    // Requesting the ServerConfigurationService here also triggers the promotion of certain
    // sakai.properties settings to system properties - see SakaiPropertyPromoter()
    ServerConfigurationService configService = org.sakaiproject.component.cover.ServerConfigurationService
            .getInstance();

    // knl-640
    appUrl = configService.getString("serverUrl", null);
    chsDomain = configService.getString("content.chs.serverName", null);
    chsUrl = configService.getString("content.chs.serverUrl", null);
    useContentHostingDomain = configService.getBoolean("content.separateDomains", false);
    contentPaths = configService.getStrings("content.chs.urlprefixes");
    if (contentPaths == null) {
        contentPaths = new String[] { "/access/", "/web/" };
    }
    loginPaths = configService.getStrings("content.login.urlprefixes");
    if (loginPaths == null) {
        loginPaths = new String[] { "/access/login", "/sakai-login-tool", "/access/require", "/access/accept" };
    }
    contentExceptions = configService.getStrings("content.chsexception.urlprefixes");
    if (contentExceptions == null) {
        // add in default exceptions here, if desired
        contentExceptions = new String[] { "/access/calendar/", "/access/citation/export_ris_sel/",
                "/access/citation/export_ris_all/" };
    }

    // capture the servlet context for later user
    m_servletContext = filterConfig.getServletContext();

    if (filterConfig.getInitParameter(CONFIG_SESSION) != null) {
        String s = filterConfig.getInitParameter(CONFIG_SESSION);
        if ("container".equalsIgnoreCase(s)) {
            m_sakaiHttpSession = CONTAINER_SESSION;
        } else if ("sakai".equalsIgnoreCase(s)) {
            m_sakaiHttpSession = SAKAI_SESSION;
        } else if ("context".equalsIgnoreCase(s)) {
            m_sakaiHttpSession = CONTEXT_SESSION;
        } else if ("tool".equalsIgnoreCase(s)) {
            m_sakaiHttpSession = TOOL_SESSION;
        } else {
            M_log.warn("invalid " + CONFIG_SESSION + " setting (" + s
                    + "): not one of container, sakai, context, tool");
        }
    }

    if (filterConfig.getInitParameter(CONFIG_REMOTE_USER) != null) {
        m_sakaiRemoteUser = Boolean.valueOf(filterConfig.getInitParameter(CONFIG_REMOTE_USER)).booleanValue();
    }

    if (filterConfig.getInitParameter(CONFIG_SESSION_AUTH) != null) {
        m_checkPrincipal = "basic".equals(filterConfig.getInitParameter(CONFIG_SESSION_AUTH));
    }

    if (filterConfig.getInitParameter(CONFIG_TOOL_PLACEMENT) != null) {
        m_toolPlacement = Boolean.valueOf(filterConfig.getInitParameter(CONFIG_TOOL_PLACEMENT)).booleanValue();
    }

    if (filterConfig.getInitParameter(CONFIG_CONTEXT) != null) {
        m_contextId = filterConfig.getInitParameter(CONFIG_CONTEXT);
    } else {
        // This is a little confusing as we're taking a display name and using it as an ID.
        m_contextId = m_servletContext.getServletContextName();
        if (m_contextId == null) {
            m_contextId = toString();
        }
    }

    if (filterConfig.getInitParameter(CONFIG_CHARACTER_ENCODING) != null) {
        m_characterEncoding = filterConfig.getInitParameter(CONFIG_CHARACTER_ENCODING);
    }

    if (filterConfig.getInitParameter(CONFIG_CHARACTER_ENCODING_ENABLED) != null) {
        m_characterEncodingEnabled = Boolean
                .valueOf(filterConfig.getInitParameter(CONFIG_CHARACTER_ENCODING_ENABLED)).booleanValue();
    }

    if (filterConfig.getInitParameter(CONFIG_UPLOAD_ENABLED) != null) {
        m_uploadEnabled = Boolean.valueOf(filterConfig.getInitParameter(CONFIG_UPLOAD_ENABLED)).booleanValue();
    }

    // get the maximum allowed upload size from the system property - use if not overriden, and also use as the ceiling if that
    // is not defined.
    if (System.getProperty(SYSTEM_UPLOAD_MAX) != null) {
        m_uploadMaxSize = Long.valueOf(System.getProperty(SYSTEM_UPLOAD_MAX).trim()).longValue() * 1024L
                * 1024L;
        m_uploadCeiling = m_uploadMaxSize;
    }

    // if the maximum allowed upload size is configured on the filter, it overrides the system property
    if (filterConfig.getInitParameter(CONFIG_UPLOAD_MAX) != null) {
        m_uploadMaxSize = Long.valueOf(filterConfig.getInitParameter(CONFIG_UPLOAD_MAX).trim()).longValue()
                * 1024L * 1024L;
    }

    // get the upload max ceiling that limits any other upload max, if defined
    if (System.getProperty(SYSTEM_UPLOAD_CEILING) != null) {
        m_uploadCeiling = Long.valueOf(System.getProperty(SYSTEM_UPLOAD_CEILING).trim()).longValue() * 1024L
                * 1024L;
    }

    // get the system wide settin, if present, for the temp dir
    if (System.getProperty(SYSTEM_UPLOAD_DIR) != null) {
        m_uploadTempDir = System.getProperty(SYSTEM_UPLOAD_DIR);
    }

    // override with our configuration for temp dir, if set
    if (filterConfig.getInitParameter(CONFIG_UPLOAD_DIR) != null) {
        m_uploadTempDir = filterConfig.getInitParameter(CONFIG_UPLOAD_DIR);
    }

    if (filterConfig.getInitParameter(CONFIG_UPLOAD_THRESHOLD) != null) {
        m_uploadThreshold = Integer.valueOf(filterConfig.getInitParameter(CONFIG_UPLOAD_THRESHOLD)).intValue();
    }

    if (filterConfig.getInitParameter(CONFIG_CONTINUE) != null) {
        m_uploadContinue = Boolean.valueOf(filterConfig.getInitParameter(CONFIG_CONTINUE)).booleanValue();
    }

    if (filterConfig.getInitParameter(CONFIG_MAX_PER_FILE) != null) {
        m_uploadMaxPerFile = Boolean.valueOf(filterConfig.getInitParameter(CONFIG_MAX_PER_FILE)).booleanValue();
    }

    // Note: if set to continue processing max exceeded uploads, we only support per-file max, not overall max
    if (m_uploadContinue && !m_uploadMaxPerFile) {
        M_log.warn("overridding " + CONFIG_MAX_PER_FILE + " setting: must be 'true' with " + CONFIG_CONTINUE
                + " ='true'");
        m_uploadMaxPerFile = true;
    }

    String clusterTerracotta = System.getProperty("sakai.cluster.terracotta");
    TERRACOTTA_CLUSTER = "true".equals(clusterTerracotta);

    // retrieve the configured cookie name, if any
    if (System.getProperty(SAKAI_COOKIE_NAME) != null) {
        cookieName = System.getProperty(SAKAI_COOKIE_NAME);
    }

    // retrieve the configured cookie domain, if any
    if (System.getProperty(SAKAI_COOKIE_DOMAIN) != null) {
        cookieDomain = System.getProperty(SAKAI_COOKIE_DOMAIN);
    }

    m_sessionParamAllow = configService.getBoolean(SAKAI_SESSION_PARAM_ALLOW, false);

    // retrieve option to enable or disable cookie HttpOnly
    m_cookieHttpOnly = configService.getBoolean(SAKAI_COOKIE_HTTP_ONLY, true);

    m_UACompatible = configService.getString(SAKAI_UA_COMPATIBLE, null);

    isLTIProviderAllowed = (configService.getString(SAKAI_BLTI_PROVIDER_TOOLS, null) != null);

    m_redirectRandomNode = configService.getBoolean(SAKAI_CLUSTER_REDIRECT_RANDOM, true);

}