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.ambraproject.cas.filter.GetGuidReturnEmailFilter.java
/** * For the HttpServletRequest Parameter <em>guid</em>, query the user database for that * user's Email Address, write that Email Address to the HttpServletResponse, and then exit. * <p/>/* www . j a v a 2 s. co m*/ * Returns <strong>only</strong> the user's Email Address. * <p/> * <strong>Caveat</strong>: Does <strong>not</strong> call <em>FilterChain.doFilter(...)</em>, * but rather simply writes the String (which it hopes is the Email Address) to the Response * and exits. * * @param request The incoming HttpServletRequest from which the Parameter <em>guid</em> is read * @param response The HttpServletResponse to which the results String is written * @param filterChain Passed in, but not used; * <em>FilterChain.doFilter(...)</em> is <strong>never called</strong>. * @throws IOException Unlikely to be thrown except for an infrastructure failure * @throws ServletException Potentially thrown by interactions with <em>request</em> * and <em>response</em>, but never explicitly raised in this method */ public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain filterChain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; if (log.isDebugEnabled()) { log.debug("Received the guid parameter: " + request.getParameter("guid")); } httpResponse.setHeader("Pragma", "no-cache"); httpResponse.setHeader("Cache-Control", "no-store"); httpResponse.setDateHeader("Expires", -1); final PrintWriter writer = response.getWriter(); try { String emailFromGuid = databaseService.getEmailAddressFromGuid(request.getParameter("guid")); if (log.isDebugEnabled()) { log.debug("Now passing back the email address: " + emailFromGuid); } if (emailFromGuid != null) { writer.write(emailFromGuid); } else { writer.write( "Unable to lookup email address from the CAS server. Please contact the system administrator."); } } catch (Exception e) { log.error("Unable to query an email address or to write that email address to ServletResponse." + " Attempted to query an email address for the guid = " + request.getParameter("guid"), e); // TODO: Replace this with some clever logic. This is NOT something to show to the user. writer.write("fake_guid_returned_from_cas"); } // This next command is somewhat unfortunate. A Filter should always invoke "doFilter(...)" at this point, but doing so can break this fragile email lookup. // A typical failure mode is to see the login page in the middle of the Edit User Profile page, where the user's Email Address should be. // The core issue is that one of the other Filters may require authentication, so it calls the "/login" URL and the default behavior // for that URL is to send the user to the Login page. Ambra is querying for a single String (the user's email address), so it takes the String // (which might be the entire Login page) and shows it to the user. // It is, therefore, recommended that Ambra acquire its users' email addresses in a different manner. return; // filterChain.doFilter(httpRequest, response); }
From source file:com.gamewin.weixin.web.account.RegisterController.java
@RequestMapping(value = "registerByAdminCode", method = RequestMethod.POST) public String registerByAdminCode(@Valid User user, RedirectAttributes redirectAttributes, ServletRequest request, String userName, String ssnumber, String address, String description) { user.setIsdelete(0);//from www .j a va 2 s . c o m String activationCode = request.getParameter("activationCode"); if (!StringUtils.isEmpty(activationCode)) { List<ActivationCode> codeList = activationCodeService.getActivationCodeByCode(activationCode); if (codeList != null && codeList.size() > 0) { ActivationCode code = codeList.get(0); if (!"CREATETHREEADMIN".equals(code.getActivationCodeType())) { redirectAttributes.addFlashAttribute("message", ",??"); return "redirect:/register"; } if ("disabled".equals(code.getStatus())) { user.setUpuser(code.getUser()); user.setStatus("Audit"); accountService.registerAdminUser(user); ApplyThreeAdmin newApplyThreeAdmin = new ApplyThreeAdmin(); newApplyThreeAdmin.setUser(user); newApplyThreeAdmin.setIsdelete(0); newApplyThreeAdmin.setStatus("submit"); newApplyThreeAdmin.setUpuser(code.getUser()); newApplyThreeAdmin.setUserName(userName); newApplyThreeAdmin.setSsnumber(ssnumber); newApplyThreeAdmin.setAddress(address); newApplyThreeAdmin.setDescription(description); newApplyThreeAdmin.setCreateDate(new Date()); newApplyThreeAdmin.setApprovalOpinion( "?'" + activationCode + "',?"); redirectAttributes.addFlashAttribute("message", "?,??,."); return "redirect:/login"; } else { user.setUpuser(code.getUser()); user.setStatus("enabled"); accountService.registerAdminUser(user); ApplyThreeAdmin newApplyThreeAdmin = new ApplyThreeAdmin(); newApplyThreeAdmin.setUser(user); newApplyThreeAdmin.setIsdelete(0); newApplyThreeAdmin.setStatus("pass"); newApplyThreeAdmin.setUpuser(code.getUser()); newApplyThreeAdmin.setUserName(userName); newApplyThreeAdmin.setSsnumber(ssnumber); newApplyThreeAdmin.setAddress(address); newApplyThreeAdmin.setDescription(description); newApplyThreeAdmin.setCreateDate(new Date()); newApplyThreeAdmin.setApprovalOpinion("?'" + activationCode + "'?"); redirectAttributes.addFlashAttribute("message", "?.?"); return "redirect:/login"; } } else { redirectAttributes.addFlashAttribute("message", ",??!"); return "redirect:/register"; } } else { redirectAttributes.addFlashAttribute("message", ",??!"); return "redirect:/register"; } }
From source file:org.craftercms.cstudio.share.servlet.ShareAuthenticationFilter.java
/** * add time zone information to request header * * @param request//from www . j ava2 s . c om * @param response * @param remote */ protected void addTimeZone(ServletRequest request, ServletResponse response, RemoteClient remote) { try { String site = request.getParameter("site"); if (!StringUtils.isEmpty(site) && !site.equals("null")) { String timeZoneStr = remote.call("/cstudio/wcm/util/timezone?site=" + site).getResponse(); timeZoneStr = timeZoneStr.trim(); ((HttpServletResponse) response).setHeader(TIMEZONE, timeZoneStr); } } catch (Exception e) { LOGGER.warn("could not set timezone"); } }
From source file:no.kantega.commons.filter.ParamEncodingFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (((HttpServletRequest) servletRequest).getMethod().equals("POST")) { servletRequest.setCharacterEncoding(encoding); } else {//from w ww . j ava 2s.com servletRequest.setCharacterEncoding(GETencoding); } for (String s : servletRequest.getParameterMap().keySet()) { servletRequest.getParameter(s); } filterChain.doFilter(servletRequest, servletResponse); }
From source file:org.wso2.carbon.identity.captcha.connector.recaptcha.SSOLoginReCaptchaConfig.java
@Override public boolean canHandle(ServletRequest servletRequest, ServletResponse servletResponse) throws CaptchaException { if (!CaptchaDataHolder.getInstance().isReCaptchaEnabled()) { return false; }/*from w w w. j av a2 s.c o m*/ String userName = servletRequest.getParameter("username"); if (StringUtils.isBlank(userName)) { return false; } String tenantDomain = MultitenantUtils.getTenantDomain(userName); Property[] connectorConfigs; try { connectorConfigs = identityGovernanceService.getConfiguration( new String[] { CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.ENABLE }, tenantDomain); } catch (Exception e) { // Can happen due to invalid user/ invalid tenant/ invalid configuration if (log.isDebugEnabled()) { log.debug("Unable to load connector configuration.", e); } return false; } if (connectorConfigs == null || connectorConfigs.length == 0 || !Boolean.valueOf(connectorConfigs[0].getValue())) { return false; } String currentPath = ((HttpServletRequest) servletRequest).getRequestURI(); if (StringUtils.isBlank(currentPath) || !CaptchaUtil.isPathAvailable(currentPath, SECURED_DESTINATIONS)) { return false; } String[] connectorIdentifierAttributes = CONNECTOR_IDENTIFIER_ATTRIBUTE.split(","); for (String attribute : connectorIdentifierAttributes) { if (servletRequest.getParameter(attribute) == null) { return false; } } return true; }
From source file:org.wso2.carbon.identity.application.authentication.endpoint.AuthenticationEndpointFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { String redirectUrl = null;/*www . j av a2 s . co m*/ String appSpecificCustomPageConfigKey = null; String serviceProviderName = servletRequest.getParameter(REQUEST_PARAM_SP) != null ? servletRequest.getParameter(REQUEST_PARAM_SP) : servletRequest.getParameter(REQUEST_PARAM_APPLICATION) != null ? servletRequest.getParameter(REQUEST_PARAM_APPLICATION) : null; String relativePath = ((HttpServletRequest) servletRequest).getRequestURI() .substring(((HttpServletRequest) servletRequest).getContextPath().length()); if (StringUtils.isNotBlank(serviceProviderName)) { appSpecificCustomPageConfigKey = AuthenticationEndpointUtil.getApplicationSpecificCustomPageConfigKey( CharacterEncoder.getSafeText(serviceProviderName), relativePath); } if (appSpecificCustomPageConfigKey != null) { // Check for application specific custom page mappings matching the request uri. redirectUrl = AuthenticationEndpointUtil.getCustomPageRedirectUrl( context.getInitParameter(appSpecificCustomPageConfigKey), ((HttpServletRequest) servletRequest).getQueryString()); } if (redirectUrl == null) { // No application specific custom page mappings. // Check for global custom page mappings matching the request uri. redirectUrl = AuthenticationEndpointUtil.getCustomPageRedirectUrl( context.getInitParameter(relativePath), ((HttpServletRequest) servletRequest).getQueryString()); } if (redirectUrl != null) { // There is a custom configuration matching the request uri. Redirect. if (log.isDebugEnabled()) { log.debug("There is a custom configuration matching the request uri. Redirecting to : " + redirectUrl); } ((HttpServletResponse) servletResponse).sendRedirect(redirectUrl); return; } if (((HttpServletRequest) servletRequest).getRequestURI().contains(URI_LOGIN)) { String hrdParam = CharacterEncoder.getSafeText(servletRequest.getParameter(REQUEST_PARAM_HRD)); if (hrdParam != null && "true".equalsIgnoreCase(hrdParam)) { servletRequest.getRequestDispatcher("domain.jsp").forward(servletRequest, servletResponse); return; } Map<String, String> idpAuthenticatorMapping = new HashMap<String, String>(); String authenticators = CharacterEncoder .getSafeText(servletRequest.getParameter(REQUEST_PARAM_AUTHENTICATORS)); if (authenticators != null) { String[] authenticatorIdPMappings = authenticators.split(";"); for (String authenticatorIdPMapping : authenticatorIdPMappings) { String[] authenticatorIdPMapArr = authenticatorIdPMapping.split(":"); for (int i = 1; i < authenticatorIdPMapArr.length; i++) { if (idpAuthenticatorMapping.containsKey(authenticatorIdPMapArr[i])) { idpAuthenticatorMapping.put(authenticatorIdPMapArr[i], idpAuthenticatorMapping.get(authenticatorIdPMapArr[i]) + "," + authenticatorIdPMapArr[0]); } else { idpAuthenticatorMapping.put(authenticatorIdPMapArr[i], authenticatorIdPMapArr[0]); } } } } if (!idpAuthenticatorMapping.isEmpty()) { servletRequest.setAttribute(Constants.IDP_AUTHENTICATOR_MAP, idpAuthenticatorMapping); } String loadPage; String protocolType = CharacterEncoder.getSafeText(servletRequest.getParameter(REQUEST_PARAM_TYPE)); if (SAMLSSO.equals(protocolType)) { loadPage = URI_SAMLSSO_LOGIN; } else if (OPENID.equals(protocolType)) { loadPage = URI_OPENID_LOGIN; } else if (PASSIVESTS.equals(protocolType)) { loadPage = URI_PASSIVESTS_LOGIN; } else if (OAUTH2.equals(protocolType) || OIDC.equals(protocolType)) { loadPage = URI_OAUTH2_LOGIN; } else if (FIDO.equals(protocolType)) { loadPage = "authentication.jsp"; } else { loadPage = "login.jsp"; } servletRequest.getRequestDispatcher(loadPage).forward(servletRequest, servletResponse); } else { filterChain.doFilter(servletRequest, servletResponse); } }
From source file:gov.nih.nci.ncicb.cadsr.cdebrowser.servlets.SessionFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException { String expiredSessionJSP = filterConfig.getInitParameter("expiredSessionJSP"); //String controller = filterConfig.getInitParameter("controllerName"); HttpServletRequest req = (HttpServletRequest) request; //Object param = request.getParameter("FirstTimer"); String param = request.getParameter("FirstTimer"); HttpSession userSession = req.getSession(false); if (param == null && userSession == null) { ((HttpServletResponse) response).sendRedirect(req.getContextPath() + expiredSessionJSP); return;//from www . ja va2 s . c o m } chain.doFilter(request, response); }
From source file:CheckFilter.java
private void reject(ServletRequest request, ServletResponse response) throws IOException, ServletException { request.setAttribute("errorMsg", "Please make sure to provide a valid value for all of the text fields."); Enumeration params = request.getParameterNames(); String paramN = null;// w w w . ja v a 2 s . com while (params.hasMoreElements()) { paramN = (String) params.nextElement(); request.setAttribute(paramN, request.getParameter(paramN)); } RequestDispatcher dispatcher = request.getRequestDispatcher("/form.jsp"); dispatcher.forward(request, response); }
From source file:org.infoscoop.web.CheckSessionIdFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpRes = (HttpServletResponse) res; String uid = (String) httpReq.getSession().getAttribute("Uid"); //If an uid is empty, we don't check. if (uid != null || !"true".equalsIgnoreCase(req.getParameter(CheckDuplicateUidFilter.IS_PREVIEW))) { try {/*from w ww . j a v a 2 s . c om*/ String sessionId = httpReq.getHeader("MSDPortal-SessionId"); SessionDAO dao = SessionDAO.newInstance(); String currentId = dao.getSessionId(uid); if (HttpStatusCode.MSD_FORCE_RELOAD.equals(currentId)) { dao.deleteSessionId(uid); httpRes.setHeader(HttpStatusCode.HEADER_NAME, HttpStatusCode.MSD_FORCE_RELOAD); httpRes.sendError(500); if (log.isInfoEnabled()) log.info("session required reload. status=" + HttpStatusCode.MSD_FORCE_RELOAD); return; } if (sessionId != null && !sessionId.equals(currentId)) { httpRes.setHeader(HttpStatusCode.HEADER_NAME, HttpStatusCode.MSD_INVALID_SESSION); httpRes.sendError(500); if (log.isInfoEnabled()) log.info("invalid session error occured. status=" + HttpStatusCode.MSD_INVALID_SESSION); return; } //Access log LogService.getHandle().insertDailyAccessLog(uid); } catch (Exception e) { log.error("The unexcepted error occured", e); } } chain.doFilter(req, res); }
From source file:com.gamewin.weixin.web.account.ApplyThreeAdminController.java
@RequestMapping(value = "create", method = RequestMethod.POST) public String create(@Valid ApplyThreeAdmin newApplyThreeAdmin, RedirectAttributes redirectAttributes, ServletRequest request) { User user = new User(getCurrentUserId()); newApplyThreeAdmin.setUser(user);// w ww .ja v a 2 s. co m newApplyThreeAdmin.setIsdelete(0); newApplyThreeAdmin.setStatus("submit"); String upuserId = request.getParameter("upuserId"); if (!StringUtils.isEmpty(upuserId)) { User upuser = accountService.getUser(Long.parseLong(upuserId)); if (upuser != null && "TwoAdmin".equals(upuser.getRoles())) { newApplyThreeAdmin.setUpuser(upuser); applyThreeAdminService.saveApplyThreeAdmin(newApplyThreeAdmin); redirectAttributes.addFlashAttribute("applyThreeAdmin", newApplyThreeAdmin); redirectAttributes.addFlashAttribute("message", ","); return "redirect:/ApplyThreeAdmin/applyThreeAdminView"; } else { applyThreeAdminService.saveApplyThreeAdmin(newApplyThreeAdmin); redirectAttributes.addFlashAttribute("applyThreeAdmin", newApplyThreeAdmin); redirectAttributes.addFlashAttribute("message", ",?"); return "redirect:/ApplyThreeAdmin/applyThreeAdminView"; } } else { applyThreeAdminService.saveApplyThreeAdmin(newApplyThreeAdmin); redirectAttributes.addFlashAttribute("applyThreeAdmin", newApplyThreeAdmin); redirectAttributes.addFlashAttribute("message", ",?"); return "redirect:/ApplyThreeAdmin/applyThreeAdminView"; } }