List of usage examples for javax.servlet ServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:org.infoscoop.web.CheckDuplicateUidFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String isPreview = request.getParameter(CheckDuplicateUidFilter.IS_PREVIEW); String uid = (String) req.getSession().getAttribute("Uid"); if (uid == null || "true".equalsIgnoreCase(isPreview)) { chain.doFilter(req, resp);/* w w w. j a va 2s .co m*/ return; } SessionFactory sessionFactory = (SessionFactory) SpringUtil.getBean("sessionFactory"); Session session = sessionFactory.openSession(); try { Collection preferences = session.createCriteria(Preference.class) .add(Expression.eq("Uid", uid).ignoreCase()).list(); if (preferences.size() == 1) { Preference pref = (Preference) preferences.iterator().next(); if (!uid.toLowerCase().equals(pref.getUid())) { resp.sendRedirect("mergeprofile?Uid=" + pref.getUid()); return; } } else if (preferences.size() > 1) { Map dupeIdMap = new HashMap(); for (Iterator ite = preferences.iterator(); ite.hasNext();) { Preference pref = (Preference) ite.next(); String dupeId = pref.getUid(); String lastModified = null; try { Xml2Json x2j = new Xml2Json(); String rootPath = "/preference"; x2j.addSkipRule(rootPath); x2j.addPathRule(rootPath + "/property", "name", true, true); String prefJsonStr = x2j.xml2json(pref.getElement()); JSONObject prefJSONObj = new JSONObject(prefJsonStr); lastModified = prefJSONObj.getJSONObject("property").getString("logoffDateTime"); } catch (Exception ex) { // ignore } dupeIdMap.put(dupeId, lastModified); } req.getSession().setAttribute("dupeIdMap", dupeIdMap); resp.sendRedirect("selectProfile.jsp"); return; } } finally { session.close(); } chain.doFilter(req, resp); }
From source file:com.xt.views.taglib.html.BaseFieldTag.java
/** * ?value/*from w w w .j a v a 2 s . c om*/ * * @return * @throws JspException */ protected void caculateValue() throws JspException { try { ServletRequest req = pageContext.getRequest(); if (req.getAttribute("GET_VALUE_FROM_PARAMS") != null) { beforeFormatedValue = req.getParameter(property); } else { beforeFormatedValue = TagUtils.getInstance().lookup(pageContext, name, property, null); } } catch (Throwable e) { // ?? LogWriter.warn(e.getMessage()); } this.value = myFormatValue(beforeFormatedValue); }
From source file:de.thorstenberger.taskmodel.view.webapp.filter.ExportPDFFilter.java
/** * {@inheritDoc}//from w ww .j a va 2 s. co m */ public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { if (servletRequest.getParameter(EXPORTFILENAME) == null) { // don't filter! filterChain.doFilter(servletRequest, servletResponse); } else { // create a buffer for the rendered contents final ContentCaptureServletResponse wrapper = new ContentCaptureServletResponse( (HttpServletResponse) servletResponse); // call the rest of the filter chain filterChain.doFilter(servletRequest, wrapper); final Document dom = getRenderedXhtml(new String(wrapper.getBinaryContent(), Charset.forName("UTF8"))); // call flying saucer to render xHtml to pdf renderPdf(dom, (HttpServletRequest) servletRequest, servletResponse); } }
From source file:gov.nih.nci.firebird.web.filter.FirebirdCsrfGuardFilter.java
private void logCsrfGuardResults(ServletRequest request, HttpServletRequest httpRequest, CsrfGuard csrfGuard) { String requestURI = httpRequest.getRequestURI(); if (requestURI.contains(".action")) { if (csrfGuard.isUnprotectedPageOrMethod(httpRequest)) { String tokenFromPageRequest = request.getParameter(csrfGuard.getTokenName()); String tokenFromRequest = httpRequest.getHeader(csrfGuard.getTokenName()); if (tokenFromRequest != null || tokenFromPageRequest != null) { csrfGuard.getLogger().log(LogLevel.Error, "Request " + requestURI + " contains token yet it is not protected"); } else { csrfGuard.getLogger().log(LogLevel.Error, "Not protecting " + requestURI); }/*from w ww . j a va2 s .c o m*/ } else { csrfGuard.getLogger().log(LogLevel.Error, "Protecting " + requestURI); } } }
From source file:com.swdouglass.joid.consumer.OpenIdFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { // basically just check for openId parameters HttpServletRequest request = (HttpServletRequest) servletRequest; if (servletRequest.getParameter(OPENID_ATTRIBUTE) != null && !ignored(request)) { try {//w w w . j a va2s .c o m @SuppressWarnings("unchecked") AuthenticationResult result = joid .authenticate(convertToStringValueMap(servletRequest.getParameterMap())); String identity = result.getIdentity(); if (identity != null) { HttpServletRequest req = (HttpServletRequest) servletRequest; req.getSession(true).setAttribute(OpenIdFilter.OPENID_ATTRIBUTE, identity); HttpServletResponse resp = (HttpServletResponse) servletResponse; // could check this before setting Cookie cookie = new Cookie(OPENID_ATTRIBUTE, identity); if (cookieDomain != null) { cookie.setDomain(cookieDomain); } if (cookieMaxAge != null) { cookie.setMaxAge(cookieMaxAge); } resp.addCookie(cookie); // redirect to get rid of the long url resp.sendRedirect(result.getResponse().getReturnTo()); return; } } catch (AuthenticationException e) { e.printStackTrace(); log.info("auth failed: " + e.getMessage()); // should this be handled differently? } catch (Exception e) { e.printStackTrace(); } } filterChain.doFilter(servletRequest, servletResponse); }
From source file:com.redhat.rhn.frontend.struts.RhnUnpagedListAction.java
/** * Sets up the ListControl filter data/*from www. j a v a2s. c o m*/ * @param lc ListControl to use * @param request ServletRequest * @param viewer user requesting the page */ public void filterList(ListControl lc, ServletRequest request, User viewer) { /* * Make sure we have a user. If not, something bad happened and we should * just bail out with an exception. Since this is probably the result of * a bad uid param, throw a BadParameterException. */ if (viewer == null) { throw new BadParameterException("Null viewer"); } String filterData = request.getParameter(RequestContext.FILTER_STRING); request.setAttribute("isFiltered", Boolean.valueOf(!StringUtils.isEmpty(filterData))); if (!StringUtils.isBlank(filterData)) { HttpServletRequest req = (HttpServletRequest) request; createSuccessMessage(req, "filter.clearfilter", req.getRequestURI()); } lc.setFilterData(filterData); }
From source file:org.commonfarm.web.ECSideFilter.java
public String getFileName(ServletRequest servletRequest) { String fileName = servletRequest.getParameter(ECSideConstants.EASY_DATA_EXPORT_FILENAME); if (StringUtils.isBlank(fileName)) { String eda = servletRequest.getParameter(ECSideConstants.EASY_DATA_EXPORT_FLAG); if (eda.indexOf('.') > 0) { fileName = eda.substring(eda.indexOf('.') + 1); }// w ww . j a va 2 s . c om } return StringUtils.isNotBlank(fileName) ? fileName : null; }
From source file:org.commonfarm.web.ECSideFilter.java
public String getSqlName(ServletRequest servletRequest) { String sqlName = servletRequest.getParameter(ECSideConstants.EASY_DATA_ACCESS_SQLNAME); if (StringUtils.isBlank(sqlName)) { String eda = servletRequest.getParameter(ECSideConstants.EASY_DATA_ACCESS_FLAG); if (StringUtils.isBlank(eda)) { eda = servletRequest.getParameter(ECSideConstants.EASY_DATA_EXPORT_FLAG); }/*from w w w . j a v a 2 s . c o m*/ if (StringUtils.isNotBlank(eda) && eda.indexOf('.') > 0) { sqlName = eda.substring(eda.indexOf('.') + 1); } } return StringUtils.isNotBlank(sqlName) ? sqlName : null; }
From source file:com.netspective.sparx.navigate.query.QueryResultsNavigatorPage.java
public void handlePageBody(Writer writer, NavigationContext nc) throws ServletException, IOException { if (!valid) { writer.write(invalidMessage);//from w ww.j a v a 2s. c om return; } final Map templateVars; final ServletRequest request = nc.getRequest(); try { final String executionId = getQueryExectionId(nc); final boolean refresh = request.getParameter(refreshResultSetParamName) != null || request.getAttribute(refreshResultSetParamName) != null; QueryResultsNavigatorState queryResults = refresh ? null : getQueryResultsNavigatorStatesManager().getActiveUserQueryResults(this, nc, executionId); if (queryResults == null) { queryResults = constructQueryResults(nc, executionId); if (queryResults.getScrollState().isScrollable()) getQueryResultsNavigatorStatesManager().setActiveUserQueryResults(nc, queryResults); } final Integer scrollToPageOverride = (Integer) request.getAttribute(activeScrollPageParamName); if (scrollToPageOverride != null) queryResults.getScrollState().scrollToPage(scrollToPageOverride.intValue()); else { final String scrollToPage = request.getParameter(activeScrollPageParamName); if (scrollToPage != null && scrollToPage.length() > 0) queryResults.getScrollState().scrollToPage(Integer.parseInt(scrollToPage)); } templateVars = createDefaultResultsBodyTemplateVars(nc, queryResults); } catch (NamingException e) { throw new NestableRuntimeException(e); } catch (SQLException e) { throw new NestableRuntimeException(e); } // handle the body template if (templateVars != null) getBodyTemplate().process(writer, nc, templateVars); else writer.write("No active result set found."); }
From source file:org.wso2.carbon.identity.captcha.connector.recaptcha.SSOLoginReCaptchaConfig.java
@Override public CaptchaPreValidationResponse preValidate(ServletRequest servletRequest, ServletResponse servletResponse) throws CaptchaException { CaptchaPreValidationResponse preValidationResponse = new CaptchaPreValidationResponse(); String userName = servletRequest.getParameter("username"); String tenantDomain = MultitenantUtils.getTenantDomain(userName); if (CaptchaUtil.isMaximumFailedLoginAttemptsReached(MultitenantUtils.getTenantAwareUsername(userName), tenantDomain)) {//w ww . j a v a 2 s . co m preValidationResponse.setCaptchaValidationRequired(true); preValidationResponse.setMaxFailedLimitReached(true); // Add parameters which need to send back in case of failure. preValidationResponse.setOnCaptchaFailRedirectUrls(Collections.singletonList(ON_FAIL_REDIRECT_URL)); Map<String, String> params = new HashMap<>(); params.put("reCaptcha", "true"); params.put("reCaptchaKey", CaptchaDataHolder.getInstance().getReCaptchaSiteKey()); params.put("reCaptchaAPI", CaptchaDataHolder.getInstance().getReCaptchaAPIUrl()); params.put("authFailure", "true"); params.put("authFailureMsg", "recaptcha.fail.message"); preValidationResponse.setCaptchaAttributes(params); } // Post validate all requests preValidationResponse.setMaxFailedLimitReached(true); preValidationResponse.setPostValidationRequired(true); return preValidationResponse; }