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:com.agiletec.plugins.jpcrowdsourcing.aps.tags.IdeaTagListTag.java

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {//from w ww .j  a v  a 2s .com
        List<CategoryInfoBean> list = this.loadTags(reqCtx);
        this.pageContext.setAttribute(this.getVar(), list);
    } catch (Throwable t) {
        _logger.error("error in doEndTag", t);
        throw new JspException("Errore tag", t);
    }
    this.release();
    return super.doEndTag();
}

From source file:org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.java

public Errors getErrors(ServletRequest request) {
    return (Errors) request.getAttribute(ERRORS);
}

From source file:org.osaf.cosmo.acegisecurity.context.HttpRequestContextIntegrationFilter.java

/**
 * Generates a new security context, continues the filter chain,
 * then clears the context by generating another new one.
 *
 * @param request the servlet request/*from ww w  . j a v a 2 s  .  com*/
 * @param response the servlet response
 * @param chain the filter chain
 * @throws IOException if an I/O error occurs
 * @throws ServletException if any other error occurs
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request.getAttribute(FILTER_APPLIED) != null) {
        // ensure that filter is applied only once per request
        chain.doFilter(request, response);
        return;
    }

    request.setAttribute(FILTER_APPLIED, Boolean.TRUE);

    if (log.isDebugEnabled()) {
        log.debug("New SecurityContext instance associated with SecurityContextHolder");
    }
    SecurityContextHolder.setContext(generateNewContext());

    try {
        chain.doFilter(request, response);
    } catch (IOException ioe) {
        throw ioe;
    } catch (ServletException se) {
        throw se;
    } finally {
        // do clean up, even if there was an exception
        SecurityContextHolder.clearContext();
        if (log.isDebugEnabled()) {
            log.debug("SecurityContextHolder refreshed, as request processing completed");
        }
    }
}

From source file:com.rsmart.certification.impl.util.PortalParamManagerImpl.java

public Map<String, String> getParams(ServletRequest request) {
    Map<String, String> map = new HashMap<>();
    for (String key : parameters) {
        String value = request.getParameter(key);
        if (value == null) {
            value = (String) request.getAttribute(key);
        }// w  w w.java  2s  .  c  o m

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

    return map;
}

From source file:org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.java

public GroovyObject getController(ServletRequest request) {
    return (GroovyObject) request.getAttribute(CONTROLLER);
}

From source file:org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.java

/**
 * @deprecated Use {@link org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest#getContextPath() instead}
 * @param request The Servlet Reqest/*from   ww  w  .  jav a2  s.  c  o  m*/
 * @return The Application URI
 */
@Deprecated
public String getApplicationUri(ServletRequest request) {
    String appUri = (String) request.getAttribute(GrailsApplicationAttributes.APP_URI_ATTRIBUTE);
    if (appUri == null) {
        appUri = urlHelper.getContextPath((HttpServletRequest) request);
    }
    return appUri;
}

From source file:org.codice.ddf.security.handler.basic.AbstractBasicAuthenticationHandler.java

@Override
public HandlerResult handleError(ServletRequest servletRequest, ServletResponse servletResponse,
        FilterChain chain) throws ServletException {
    String realm = (String) servletRequest.getAttribute(ContextPolicy.ACTIVE_REALM);
    doAuthPrompt(realm, (HttpServletResponse) servletResponse);
    HandlerResult result = new HandlerResult(HandlerResult.Status.REDIRECTED, null);
    result.setSource(realm + "-" + SOURCE);
    LOGGER.debug("In error handler for basic auth - prompted for auth credentials.");
    return result;
}

From source file:com.agiletec.plugins.jpcrowdsourcing.aps.tags.CurrentPageWidgetTag.java

private String extractTitle(Widget showlet) {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    WidgetType type = showlet.getType();
    String value = type.getTitles().getProperty(currentLang.getCode());
    if (null == value || value.trim().length() == 0) {
        ILangManager langManager = (ILangManager) ApsWebApplicationUtils
                .getBean(SystemConstants.LANGUAGE_MANAGER, this.pageContext);
        Lang defaultLang = langManager.getDefaultLang();
        value = type.getTitles().getProperty(defaultLang.getCode());
    }/*from  w  ww  .j  a va  2s  .  c  o  m*/
    return value;
}

From source file:org.codice.ddf.security.handler.basic.AbstractBasicAuthenticationHandler.java

/**
 * Processes the incoming request to retrieve the username/password tokens. Handles responding
 * to the client that authentication is needed if they are not present in the request.
 * Returns the {@link org.codice.ddf.security.handler.api.HandlerResult} for the HTTP Request.
 *
 * @param request  http request to obtain attributes from and to pass into any local filter chains required
 * @param response http response to return http responses or redirects
 * @param chain    original filter chain (should not be called from your handler)
 * @param resolve  flag with true implying that credentials should be obtained, false implying return if no credentials are found.
 * @return//  w  w  w . ja  va 2 s  .c om
 */
@Override
public HandlerResult getNormalizedToken(ServletRequest request, ServletResponse response, FilterChain chain,
        boolean resolve) {

    String realm = (String) request.getAttribute(ContextPolicy.ACTIVE_REALM);
    HandlerResult handlerResult = new HandlerResult(HandlerResult.Status.NO_ACTION, null);
    handlerResult.setSource(realm + "-" + SOURCE);

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String path = httpRequest.getServletPath();
    LOGGER.debug("Handling request for path {}", path);

    LOGGER.debug("Doing authentication and authorization for path {}", path);

    BaseAuthenticationToken token = extractAuthenticationInfo(httpRequest);

    // we found credentials, attach to result and return with completed status
    if (token != null) {
        handlerResult.setToken(token);
        handlerResult.setStatus(HandlerResult.Status.COMPLETED);
        return handlerResult;
    }

    // we didn't find the credentials, see if we are to do anything or not
    if (resolve) {
        doAuthPrompt(realm, (HttpServletResponse) response);
        handlerResult.setStatus(HandlerResult.Status.REDIRECTED);
    }

    return handlerResult;
}

From source file:org.unitedinternet.cosmo.acegisecurity.context.HttpRequestContextIntegrationFilter.java

/**
 * Generates a new security context, continues the filter chain,
 * then clears the context by generating another new one.
 *
 * @param request the servlet request/*w w  w . j a va2 s . co m*/
 * @param response the servlet response
 * @param chain the filter chain
 * @throws IOException if an I/O error occurs
 * @throws ServletException if any other error occurs
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (request.getAttribute(FILTER_APPLIED) != null) {
        // ensure that filter is applied only once per request
        chain.doFilter(request, response);
        return;
    }

    request.setAttribute(FILTER_APPLIED, Boolean.TRUE);

    if (LOG.isDebugEnabled()) {
        LOG.debug("New SecurityContext instance associated with SecurityContextHolder");
    }
    SecurityContextHolder.setContext(generateNewContext());

    try {
        chain.doFilter(request, response);
    } catch (IOException ioe) {
        throw ioe;
    } catch (ServletException se) {
        throw se;
    } finally {
        // do clean up, even if there was an exception
        SecurityContextHolder.clearContext();
        if (LOG.isDebugEnabled()) {
            LOG.debug("SecurityContextHolder refreshed, as request processing completed");
        }
    }
}