Example usage for javax.servlet ServletRequest getAttribute

List of usage examples for javax.servlet ServletRequest getAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Usage

From source file:it.unipmn.di.dcs.sharegrid.web.servlet.MultipartFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request.getAttribute(MultipartFilter.DoFilterCalledAttr) != null) {
        chain.doFilter(request, response);
        return;/*  www.j  a v  a  2  s  . com*/
    }

    request.setAttribute(MultipartFilter.DoFilterCalledAttr, "true");

    // sanity check
    if (!(response instanceof HttpServletResponse)) {
        chain.doFilter(request, response);
        return;
    }

    HttpServletRequest httpReq = (HttpServletRequest) request;

    if (!ServletFileUpload.isMultipartContent(httpReq)) {
        chain.doFilter(request, response);
        return;
    }

    // Wraps the current request into a multipart request object
    // for handling multipart form parameters.

    MultipartRequestWrapper reqWrapper = null;

    reqWrapper = new MultipartRequestWrapper(httpReq, this.maxSize, this.maxFileSize, this.thresholdSize,
            this.repositoryPath);

    chain.doFilter(reqWrapper, response);
}

From source file:org.soasecurity.mutual.ssl.filter.MutualSSLFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    log.debug("Mutual SSL Filter is invoked.");

    X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");

    if (certs != null) {

        // client certificate must be first certificate in the chain
        X509Certificate clientCert = certs[0];

        // encode certificate
        String certificateData = "";
        try {//from  w  ww.  ja  va 2 s. c  om
            certificateData = new String(Base64.encodeBase64(clientCert.getEncoded()));
        } catch (CertificateEncodingException e) {
            log.error("Error while encoding the certificate", e);
        }

        Principal principal = clientCert.getSubjectDN();

        String subjectDN = principal.getName();

        log.debug("Mutual Authentication is success full with subject : " + subjectDN);

        // creating new wrapper to set a new parameter
        X509HTTPServletWrapper wrapper = new X509HTTPServletWrapper((HttpServletRequest) request, subjectDN,
                certificateData);

        chain.doFilter(wrapper, response);

    } else {

        chain.doFilter(request, response);
    }
}

From source file:org.sakaiproject.nakamura.http.qos.QoSFilter.java

private QoSToken getQoSControl(ServletRequest request) {
    QoSToken control = (QoSToken) request.getAttribute(QoSToken.CONTROL_ATTR);
    if (control != null) {
        return control;
    }//from  w w  w. ja  va 2s .c o m

    QoSControl qoSControl = null;

    HttpServletRequest hrequest = (HttpServletRequest) request;
    String requestPath = hrequest.getRequestURI();
    String[] pathElements = StringUtils.split(requestPath, "/", 1);
    if (pathElements != null && pathElements.length > 0) {
        String method = StringUtils.lowerCase(hrequest.getMethod());

        qoSControl = qoSControMap.get(method + ":" + pathElements[0]);
        if (qoSControl == null) {
            qoSControl = qoSControMap.get("*:" + pathElements[0]);
        }
    }
    if (qoSControl == null) {
        qoSControl = defaultQoSControl;
    }
    QoSToken qoSToken = new QoSTokenImpl(qoSControl, request);
    request.setAttribute(QoSToken.CONTROL_ATTR, qoSToken);
    return qoSToken;
}

From source file:org.seasar.s2click.servlet.S2ClickServlet.java

/**
 * HOT deploy????Click Framework?????//from  w w w  . j  ava  2  s .c  o m
 */
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {

    String hotDeployInitStatus = (String) req.getAttribute(UrlPatternFilter.HOTDEPLOY_INIT_KEY);

    if (initialized == false && !"initialized".equals(hotDeployInitStatus)) {
        super.init();
        req.setAttribute(UrlPatternFilter.HOTDEPLOY_INIT_KEY, "initialized");

        if ("initialize".equals(hotDeployInitStatus)) {
            return;
        }
    }

    super.service(new S2ClickRequestWrapper((HttpServletRequest) req), res);
}

From source file:com.google.code.profiling.filters.ProfilingTimerFilter.java

/**
 * Check for parameters to turn the filter on or off. If parameters are given, change the
 * current state of the filter. If current state is off then pass to filter chain. If current
 * state is on - record start time, pass to filter chain, and then record total time on the
 * return.//w ww .  j a v a  2s . c  o  m
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, javax.servlet.ServletException {
    String resource = null;
    // if an include file then get the proper resource name.
    if (request.getAttribute("javax.servlet.include.request_uri") != null) {
        resource = (String) request.getAttribute("javax.servlet.include.request_uri");
    } else {
        resource = ((HttpServletRequest) request).getRequestURI();
    }

    this.utilTimerStack.push(resource);
    try {
        // time and perform the request
        chain.doFilter(request, response);
    } finally {
        this.utilTimerStack.pop(resource);
    }

}

From source file:com.google.code.profiling.filters.ProfilingMemoryFilter.java

/**
 * Check for parameters to turn the filter on or off. If parameters are given, change the
 * current state of the filter. If current state is off then pass to filter chain. If current
 * state is on - record start time, pass to filter chain, and then record total time on the
 * return./*from   ww  w . j  a  va2  s.  co m*/
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, javax.servlet.ServletException {
    String resource = null;
    // if an include file then get the proper resource name.
    if (request.getAttribute("javax.servlet.include.request_uri") != null) {
        resource = (String) request.getAttribute("javax.servlet.include.request_uri");
    } else {
        resource = ((HttpServletRequest) request).getRequestURI();
    }

    this.utilMemoryStack.push(resource);
    try {
        // memory and perform the request
        chain.doFilter(request, response);
    } finally {
        this.utilMemoryStack.pop(resource);
    }

}

From source file:org.eclipse.orion.server.servlets.XSRFPreventionFilter.java

private boolean isException(ServletRequest req, String path) {
    if (exceptionList.contains(path))
        return true;
    // Self-hosting check
    return exceptionList.contains((String) req.getAttribute(RequestDispatcher.FORWARD_PATH_INFO));
}

From source file:org.apache.tiles.web.util.TilesDecorationFilter.java

/**
 * Checks if the prevent evaluation token is present.
 *
 * @param request The HTTP request object.
 * @return <code>true</code> if the token is present.
 *//*from   ww  w  .j  ava  2 s  .c  o  m*/
private boolean isPreventTokenPresent(ServletRequest request) {
    return preventDecorationToken != null && request.getAttribute(preventDecorationToken) != null;
}

From source file:org.eclipse.orion.server.servlets.XSRFPreventionFilter.java

private boolean isEntryPoint(ServletRequest req, String path) {
    if (entryPointList.contains(path))
        return true;
    // Self-hosting check
    return entryPointList.contains((String) req.getAttribute(RequestDispatcher.FORWARD_PATH_INFO));
}

From source file:org.sakaiproject.metaobj.shared.mgt.impl.PortalParamManagerImpl.java

public Map getParams(ServletRequest request) {
    Map map = new Hashtable();

    for (Iterator i = getParameters().iterator(); i.hasNext();) {
        String key = (String) i.next();
        String value = request.getParameter(key);
        if (value == null) {
            value = (String) request.getAttribute(key);
        }//ww w .  j  a v  a 2 s .  com

        if (value != null) {
            map.put(key, value);
        }
    }

    return map;
}