Example usage for javax.servlet ServletRequest getParameter

List of usage examples for javax.servlet ServletRequest getParameter

Introduction

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

Prototype

public String getParameter(String name);

Source Link

Document

Returns the value of a request parameter as a String, or null if the parameter does not exist.

Usage

From source file:com.salesmanager.core.security.JAASCustomerSecurityFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    resp.setHeader("Cache-Control", "no-cache");
    resp.setHeader("Pragma", "no-cache");
    resp.setDateHeader("Expires", 0);
    String url = req.getRequestURI();
    if (isEscapeUrlFromFilter(url) || url.endsWith(".css") || url.endsWith(".js")) {
        chain.doFilter(request, response);
        return;/*from ww  w.j  av a 2  s.co  m*/
    }

    String authToken = request.getParameter(CUSTOMER_AUTH_TOKEN);
    if (StringUtils.isBlank(authToken)) {

        HttpSession session = req.getSession();
        if (session == null) {
            resp.sendRedirect(getLogonPage(req));
        } else {
            if (session.getAttribute(SecurityConstants.SM_CUSTOMER_USER) != null) {
                chain.doFilter(request, response);
            } else {
                resp.sendRedirect(getLogonPage(req));
            }
        }
    } else {
        if (logonModule.isValidAuthToken(authToken)) {
            chain.doFilter(request, response);
        } else {
            ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }
    }

}

From source file:pt.webdetails.cdv.CdvContentGenerator.java

private Map<String, Object> getRenderRequestParameters(String dashboardName) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("solution", "system");
    params.put("path", UI_PATH);
    params.put("file", dashboardName);
    params.put("bypassCache", "true");
    params.put("absolute", "true");
    params.put("inferScheme", "true");
    params.put("root", getRoot());

    //add request parameters
    ServletRequest request = getRequest();
    @SuppressWarnings("unchecked") //should always be String
    Enumeration<String> originalParams = request.getParameterNames();
    // Iterate and put the values there
    while (originalParams.hasMoreElements()) {
        String originalParam = originalParams.nextElement();
        params.put(originalParam, request.getParameter(originalParam));
    }//  ww w  .  j  a  v  a 2 s  .co m

    return params;
}

From source file:org.kuali.rice.krad.web.filter.UifSessionTimeoutFilter.java

/**
 * Checks for a session timeout and if one has occurred pulls the view session policy to determine whether
 * a redirect needs to happen//from   w  w  w .ja v a 2 s.  c om
 *
 * <p>
 * To determine whether a session timeout has occurred, the filter looks for the existence of a request parameter
 * named {@link org.kuali.rice.krad.uif.UifParameters#SESSION_ID}. If found it then compares that id to the id
 * on the current session. If they are different, or a session does not currently exist a timeout is assumed.
 *
 * In addition, if a request was made for a form key and the view has session storage enabled, a check is made
 * to verify the form manager contains a session form. If not this is treated like a session timeout
 * </p>
 *
 * <p>
 * If a timeout has occurred an attempt is made to resolve a view from the request (based on the view id or
 * type parameters), then the associated {@link ViewSessionPolicy} is pulled which indicates how the timeout should
 * be handled. This either results in doing a redirect or nothing
 * </p>
 *
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *      javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filerChain)
        throws IOException, ServletException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    HttpSession httpSession = (httpServletRequest).getSession(false);

    boolean timeoutOccurred = false;

    // compare session id in request to id on current session, if different or a session does not exist
    // then assume a session timeout has occurred
    if (request.getParameter(UifParameters.SESSION_ID) != null) {
        String requestedSessionId = request.getParameter(UifParameters.SESSION_ID);

        if ((httpSession == null) || !StringUtils.equals(httpSession.getId(), requestedSessionId)) {
            timeoutOccurred = true;
        }
    }

    String viewId = getViewIdFromRequest(httpServletRequest);
    if (StringUtils.isBlank(viewId)) {
        //  can't retrieve a session policy if view id was not passed
        filerChain.doFilter(request, response);

        return;
    }

    // check for requested form key for a POST and if found and session storage is enabled for the
    // view, verify the form is present in the form manager
    boolean isGetRequest = RequestMethod.GET.name().equals(httpServletRequest.getMethod());

    String formKeyParam = request.getParameter(UifParameters.FORM_KEY);
    if (StringUtils.isNotBlank(formKeyParam) && !isGetRequest
            && getViewDictionaryService().isSessionStorageEnabled(viewId) && (httpSession != null)) {
        UifFormManager uifFormManager = (UifFormManager) httpSession.getAttribute(UifParameters.FORM_MANAGER);

        // if session form not found, treat like a session timeout
        if ((uifFormManager != null) && !uifFormManager.hasSessionForm(formKeyParam)) {
            timeoutOccurred = true;
        }
    }

    // if no timeout occurred continue filter chain
    if (!timeoutOccurred) {
        filerChain.doFilter(request, response);

        return;
    }

    // retrieve timeout policy associated with the view to determine what steps to take
    ViewSessionPolicy sessionPolicy = getViewDictionaryService().getViewSessionPolicy(viewId);

    if (sessionPolicy.isRedirectToHome() || StringUtils.isNotBlank(sessionPolicy.getRedirectUrl())
            || sessionPolicy.isRenderTimeoutView()) {
        String redirectUrl = getRedirectUrl(sessionPolicy, httpServletRequest);

        sendRedirect(httpServletRequest, (HttpServletResponse) response, redirectUrl);
    }
}

From source file:org.acmsl.commons.utils.http.HttpServletUtils.java

/**
 * Retrieves an integer parameter./*from w  w  w  .ja va 2s.c  o  m*/
 * @param request the request.
 * @param paramName the parameter name
 * @param defaultValue the default value.
 * @return the int value.
 */
public int getIntParam(@NotNull final ServletRequest request, @NotNull final String paramName,
        final int defaultValue) {
    int result = defaultValue;

    @Nullable
    final String value = request.getParameter(paramName);

    if (value != null) {
        result = getIntParam(paramName, value, defaultValue);
    }

    return result;
}

From source file:org.sonatype.nexus.security.filter.authc.NexusHttpAuthenticationFilter.java

@Override
protected String getAuthzHeader(ServletRequest request) {
    String authzHeader = super.getAuthzHeader(request);

    // If in header use it
    if (!StringUtils.isEmpty(authzHeader)) {
        getLogger().debug("Using authorization header from request");
        return authzHeader;
    }/*  w  ww.j  ava2 s  . c o m*/
    // otherwise check request params for it
    else {
        authzHeader = request.getParameter("authorization");

        if (!StringUtils.isEmpty(authzHeader)) {
            getLogger().debug("Using authorization from request parameter");
        } else {
            getLogger().debug("No authorization found (header or request parameter)");
        }

        return authzHeader;
    }
}

From source file:org.silverpeas.core.web.util.viewgenerator.html.arraypanes.AbstractArrayPane.java

@Override
public void init(String name, String url, ServletRequest request, HttpSession session) {
    columns = new ArrayList<>();
    lines = new ArrayList<>();
    this.name = name;
    setRoutingAddress(url);// www. j  a v a 2 s . com
    this.session = session;
    this.request = request;

    state = initState();

    String target = defaultStringIfNotDefined(request.getParameter(TARGET_PARAMETER_NAME));
    if (target.equals(name)) {
        String action = request.getParameter(ACTION_PARAMETER_NAME);
        if ("Sort".equals(action)) {
            initColumnSorting();
        } else if ("ChangePage".equals(action)) {
            initNbLinesPerPage();
        }
    }

    if (state.getSortColumn() >= 1) {
        setColumnToSort(state.getSortColumn());
    }
}

From source file:ro.raisercostin.web.DebuggingFilter.java

public void doFilter(final ServletRequest request, final ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    request.setAttribute("debug", new DebugInfo() {
        public String getJspInfo() {
            return debug(servletContext, (HttpServletRequest) request, (HttpServletResponse) response,
                    new HtmlPrinter(), true, true);
        }//  w ww. j a  v  a  2  s  . co m

        public boolean isRequested() {
            String debug = request.getParameter("debug");
            if (debug != null) {
                if ("false".equals(debug)) {
                    return false;
                }
                return true;
            }
            return false;
        }
    });
    if (loggerParameters.isDebugEnabled()) {
        loggerParameters
                .debug(debug(servletContext, (HttpServletRequest) request, (HttpServletResponse) response,
                        new PlainTextPrinter(), loggerAll.isDebugEnabled(), loggerRequest.isDebugEnabled()));
    }
    chain.doFilter(request, response);
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java

/**
 * Returns a link containing the URL + ALL the parameters of the
 * request query string minus the sort links, and the alpha link +
 * the additional params passed in the paramsToAdd map. The resulting
 * string is urlEncode'd with & encoded as &amp; so it can be used
 * in a href directly./*w  w w.j a v  a 2 s  .  c om*/
 *
 * @param request the Servlet Request
 * @param listName the current list name
 * @param paramsToAdd the params you might want to append to the url
 *                  for example makeSortLink passes in sortByLabel
 *                  while alpha bar passes in params that are specific to it.
 *  @param paramsToIgnore params to not include that would be normally
 * @return a link containing the URL  + (OtherParams - Sort - Alpha) + paramsToAdd
 */
public static String makeParamsLink(ServletRequest request, String listName, Map<String, String> paramsToAdd,
        List<String> paramsToIgnore) {
    String url = (String) request.getAttribute(ListTagHelper.PARENT_URL);
    String sortByLabel = makeSortByLabel(listName);
    String sortByDir = makeSortDirLabel(listName);
    String alphaKey = AlphaBarHelper.makeAlphaKey(listName);
    StringBuilder params = new StringBuilder();
    if (url.indexOf('?') < 0) {
        params.append("?");
    } else if (url.indexOf('?') != url.length() - 1) {
        url += "&amp;";
    }

    for (Enumeration<String> en = request.getParameterNames(); en.hasMoreElements();) {
        String paramName = en.nextElement();
        if (!sortByLabel.equals(paramName) && !sortByDir.equals(paramName) && !alphaKey.equals(paramName)
                && !paramsToIgnore.contains(paramName)) {
            if (params.length() > 1) {
                params.append("&amp;");
            }
            params.append(StringUtil.urlEncode(paramName)).append("=")
                    .append(StringUtil.urlEncode(request.getParameter(paramName)));
        }
    }
    for (String key : paramsToAdd.keySet()) {
        if (params.length() > 1) {
            params.append("&amp;");
        }
        params.append(StringUtil.urlEncode(key)).append("=").append(StringUtil.urlEncode(paramsToAdd.get(key)));
    }

    return url + params.toString();
}

From source file:ru.org.linux.user.EditProfileController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView editProfile(ServletRequest request, @RequestParam("topics") int topics,
        @RequestParam("messages") int messages, @PathVariable String nick) throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isSessionAuthorized()) {
        throw new AccessViolationException("Not authorized");
    }/*  w  w w . j  a va2  s  . co  m*/

    if (!tmpl.getNick().equals(nick)) {
        throw new AccessViolationException("Not authorized");
    }

    if (topics <= 0 || topics > 500) {
        throw new BadInputException(" ? ");
    }

    if (messages <= 0 || messages > 1000) {
        throw new BadInputException(" ? ?");
    }

    if (!DefaultProfile.getStyleList().contains(request.getParameter("style"))) {
        throw new BadInputException("  ");
    }

    tmpl.getProf().setTopics(topics);
    tmpl.getProf().setMessages(messages);
    tmpl.getProf().setShowNewFirst("on".equals(request.getParameter("newfirst")));
    tmpl.getProf().setShowPhotos("on".equals(request.getParameter("photos")));
    tmpl.getProf().setHideAdsense("on".equals(request.getParameter("hideAdsense")));
    tmpl.getProf().setShowGalleryOnMain("on".equals(request.getParameter("mainGallery")));
    tmpl.getProf().setFormatMode(request.getParameter("format_mode"));
    tmpl.getProf().setStyle(request.getParameter("style")); // TODO   
    userDao.setStyle(tmpl.getCurrentUser(), request.getParameter("style"));

    tmpl.getProf().setShowSocial("on".equals(request.getParameter("showSocial")));

    String avatar = request.getParameter("avatar");

    if (!DefaultProfile.getAvatars().contains(avatar)) {
        throw new BadInputException("invalid avatar value");
    }

    tmpl.getProf().setAvatarMode(avatar);

    tmpl.getProf().setShowAnonymous("on".equals(request.getParameter("showanonymous")));
    tmpl.getProf().setUseHover("on".equals(request.getParameter("hover")));

    tmpl.writeProfile(nick);

    return new ModelAndView(new RedirectView("/people/" + nick + "/profile"));
}