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.topazproject.ambra.auth.web.UsernameReplacementWithGuidFilter.java
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain filterChain) throws IOException, ServletException { try {//from w w w . ja v a2s .c o m HttpServletRequest httpRequest = (HttpServletRequest) request; if (log.isDebugEnabled()) { dumpRequest(httpRequest, "before chain"); } final String usernameParameter = request.getParameter(USERNAME_PARAMETER); if (!((null == usernameParameter) || (usernameParameter.length() == 0))) { httpRequest = new UsernameRequestWrapper(httpRequest, usernameParameter); } filterChain.doFilter(httpRequest, response); } catch (final IOException ex) { log.error("", ex); throw ex; } catch (final ServletException ex) { log.error("", ex); throw ex; } }
From source file:au.org.paperminer.main.UserFilter.java
/** * Changes the status of a user/* w ww . j a v a 2 s.c om*/ * @param newStatus Status value to set * @param req * @param resp */ private void setStatus(int newStatus, ServletRequest req, ServletResponse resp) { m_logger.debug("set status"); String id = req.getParameter("id"); UserHelper helper = new UserHelper(id); if (helper.isKnownUser()) { m_logger.info("Upgrading status for user " + id); helper.set(UserHelper.STATUS, Integer.toString(newStatus)); try { helper.update(); } catch (PaperMinerException ex) { m_logger.error("Status update failed", ex); req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e105"); } req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e111"); } }
From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthWebFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; log.debug("OAuthWebFilter(" + httpRequest.getRequestURL() + ") code=" + request.getParameter("code")); Cookie gerritCookie = getGerritCookie(httpRequest); try {/*from w ww. j a v a 2 s . c o m*/ GitHubLogin ghLogin = loginProvider.get(httpRequest); if (OAuthProtocol.isOAuthLogout(httpRequest)) { logout(request, response, chain, httpRequest); } else if (OAuthProtocol.isOAuthRequest(httpRequest) && !ghLogin.isLoggedIn()) { login(request, httpRequest, httpResponse, ghLogin); } else { if (ghLogin != null && ghLogin.isLoggedIn()) { httpRequest = new AuthenticatedHttpRequest(httpRequest, config.httpHeader, ghLogin.getMyself().getLogin(), config.oauthHttpHeader, GITHUB_EXT_ID + ghLogin.getToken().accessToken); } if (OAuthProtocol.isOAuthFinalForOthers(httpRequest)) { httpResponse.sendRedirect(OAuthProtocol.getTargetOAuthFinal(httpRequest)); } else { chain.doFilter(httpRequest, response); } } } finally { HttpSession httpSession = httpRequest.getSession(); if (gerritCookie != null && httpSession != null) { String gerritCookieValue = gerritCookie.getValue(); String gerritSessionValue = (String) httpSession.getAttribute("GerritAccount"); if (gerritSessionValue == null) { httpSession.setAttribute("GerritAccount", gerritCookieValue); } else if (!gerritSessionValue.equals(gerritCookieValue)) { httpSession.invalidate(); } } } }
From source file:au.org.paperminer.main.UserFilter.java
/** * Loads info about an existing PM user into a session cookie * @param req/*w ww . ja v a 2 s . c om*/ * @param resp */ private void openUser(ServletRequest req, ServletResponse resp) { m_logger.info("opening user"); String email = req.getParameter("em"); String verify = req.getParameter("vfy"); removeCookie((HttpServletResponse) resp); UserHelper userHelper = new UserHelper(email, null); if (!userHelper.isKnownUser()) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e103"); } else { CookieHelper.addCookie((HttpServletResponse) resp, userHelper); if ((verify != null) && verify.equals("y")) { sendVerificationEmail(userHelper.get(UserHelper.ID), userHelper.get(UserHelper.EMAIL), req); } m_logger.info("user " + email + " exists with id " + userHelper.get(UserHelper.ID)); } }
From source file:com.esoft.yeepay.user.service.impl.YeePayCorpAccountOperation.java
@Override @Transactional(rollbackFor = Exception.class) public void receiveOperationS2SCallback(ServletRequest request, ServletResponse response) { try {// w w w . j a va2 s . c o m request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } // ?? xml? String notifyxml = request.getParameter("notify"); // ?? String sign = request.getParameter("sign"); boolean flag = CFCASignUtil.isVerifySign(notifyxml, sign); if (flag) { // ?? @SuppressWarnings("unchecked") Map<String, String> resultMap = Dom4jUtil.xmltoMap(notifyxml); String code = resultMap.get("code"); String message = resultMap.get("message"); String platformUserNo = resultMap.get("platformUserNo"); TrusteeshipOperation to = trusteeshipOperationBO.get(YeePayConstants.OperationType.ENTERPRISE_REGISTER, platformUserNo, platformUserNo, "yeepay"); ht.evict(to); to = ht.get(TrusteeshipOperation.class, to.getId(), LockMode.UPGRADE); to.setResponseTime(new Date()); to.setResponseData(notifyxml); User user = ht.get(User.class, platformUserNo); log.info("code:" + code); if ("1".equals(code)) { if (user != null) { TrusteeshipAccount ta = ht.get(TrusteeshipAccount.class, user.getId()); if (ta == null) { ta = new TrusteeshipAccount(); ta.setId(user.getId()); ta.setUser(user); } ta.setAccountId(user.getId()); ta.setCreateTime(new Date()); ta.setStatus(TrusteeshipConstants.Status.PASSED); ta.setTrusteeship("yeepay"); ht.saveOrUpdate(ta); userBO.removeRole(user, new Role("WAIT_CONFIRM")); userBO.addRole(user, new Role("LOANER")); // ?? springSecurityService.refreshLoginUserAuthorities(user.getId()); to.setStatus(TrusteeshipConstants.Status.PASSED); ht.merge(to); } } else if ("0".equals(code) || "104".equals(code)) { to.setStatus(TrusteeshipConstants.Status.REFUSED); ht.merge(to); userBO.removeRole(user, new Role("WAIT_CONFIRM")); // ?? springSecurityService.refreshLoginUserAuthorities(user.getId()); } else { // throw new RuntimeException(new TrusteeshipReturnException(code + ":" + message)); } } try { response.getWriter().write("SUCCESS"); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } }
From source file:org.apache.beehive.netui.pageflow.scoping.internal.ScopedRequestImpl.java
/** * Get the parameter from the scoped request only (don't check in listen scoped requests) * @param paramName//from w ww . jav a 2 s . co m * @return value of the parameter */ public String getLocalParameter(String paramName) { if (_additionalParameters != null) { String overrideParam = (String) _additionalParameters.get(paramName); if (overrideParam != null) { return overrideParam; } } ServletRequest request = getRequest(); String retVal = request.getParameter(_scopedContainer.getScopedName(paramName)); if (retVal == null && _isActiveRequest && paramName.startsWith(AUTOSCOPE_PREFIX)) { retVal = request.getParameter(paramName); } return retVal; }
From source file:org.sakaiproject.portlets.SakaiIFrame.java
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); // System.out.println("==== doView called ===="); // Grab that underlying request to get a GET parameter ServletRequest req = (ServletRequest) ThreadLocalManager.get(CURRENT_HTTP_REQUEST); String popupDone = req.getParameter("sakai.popup"); PrintWriter out = response.getWriter(); Placement placement = ToolManager.getCurrentPlacement(); response.setTitle(placement.getTitle()); String source = placement.getPlacementConfig().getProperty(SOURCE); if (source == null) source = ""; String height = placement.getPlacementConfig().getProperty(HEIGHT); if (height == null) height = "1200px"; boolean maximize = "true".equals(placement.getPlacementConfig().getProperty(MAXIMIZE)); boolean popup = false; // Comes from content item boolean oldPopup = "true".equals(placement.getPlacementConfig().getProperty(POPUP)); // Retrieve the corresponding content item and tool to check the launch Map<String, Object> content = null; Map<String, Object> tool = null; Long key = getContentIdFromSource(source); if (key == null) { out.println(rb.getString("get.info.notconfig")); M_log.warn("Cannot find content id placement=" + placement.getId() + " source=" + source); return;/*from w w w. j av a 2 s .co m*/ } try { content = m_ltiService.getContent(key); Long tool_id = getLongNull(content.get("tool_id")); // If we are supposed to popup (per the content), do so and optionally // copy the calue into the placement to communicate with the portal if (tool_id != null) { tool = m_ltiService.getTool(tool_id); m_ltiService.filterContent(content, tool); } Object popupValue = content.get("newpage"); popup = getLongNull(popupValue) == 1; if (oldPopup != popup) { placement.getPlacementConfig().setProperty(POPUP, popup ? "true" : "false"); placement.save(); } String launch = (String) content.get("launch"); // Force http:// to pop-up if we are https:// String serverUrl = ServerConfigurationService.getServerUrl(); if (request.isSecure() || (serverUrl != null && serverUrl.startsWith("https://"))) { if (launch != null && launch.startsWith("http://")) popup = true; } } catch (Exception e) { out.println(rb.getString("get.info.notconfig")); e.printStackTrace(); return; } if (source != null && source.trim().length() > 0) { Context context = new VelocityContext(); context.put("tlang", rb); context.put("validator", validator); context.put("source", source); context.put("height", height); sendAlert(request, context); context.put("popupdone", Boolean.valueOf(popupDone != null)); context.put("popup", Boolean.valueOf(popup)); context.put("maximize", Boolean.valueOf(maximize)); vHelper.doTemplate(vengine, "/vm/main.vm", context, out); } else { out.println(rb.getString("get.info.notconfig")); } // System.out.println("==== doView complete ===="); }
From source file:com.esoft.yeepay.user.service.impl.YeePayCorpAccountOperation.java
@Override @Transactional(rollbackFor = Exception.class, noRollbackFor = TrusteeshipReturnException.class) public void receiveOperationPostCallback(ServletRequest request) throws TrusteeshipReturnException { try {//from www.j a v a 2 s .c om request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } // ?? xml? String respXML = request.getParameter("resp"); log.debug(respXML.toString()); // ?? String sign = request.getParameter("sign"); boolean flag = CFCASignUtil.isVerifySign(respXML, sign); if (flag) { // ?? @SuppressWarnings("unchecked") Map<String, String> resultMap = Dom4jUtil.xmltoMap(respXML); // ?? userId String requestNo = resultMap.get("requestNo").substring(resultMap.get("requestNo").indexOf("a") + 1); // ? String code = resultMap.get("code"); String description = resultMap.get("description"); TrusteeshipOperation to = trusteeshipOperationBO.get(YeePayConstants.OperationType.ENTERPRISE_REGISTER, requestNo, requestNo, "yeepay"); ht.evict(to); to = ht.get(TrusteeshipOperation.class, to.getId(), LockMode.UPGRADE); to.setResponseTime(new Date()); to.setResponseData(respXML); // ? ???? User user = ht.get(User.class, requestNo); if ("1".equals(code)) { if (user != null) { TrusteeshipAccount ta = ht.get(TrusteeshipAccount.class, user.getId()); if (ta == null) { ta = new TrusteeshipAccount(); ta.setId(user.getId()); ta.setUser(user); } ta.setAccountId(user.getId()); ta.setCreateTime(new Date()); ta.setStatus(TrusteeshipConstants.Status.PASSED); ta.setTrusteeship("yeepay"); ht.saveOrUpdate(ta); userBO.removeRole(user, new Role("WAIT_CONFIRM")); userBO.addRole(user, new Role("LOANER")); // ?? springSecurityService.refreshLoginUserAuthorities(user.getId()); to.setStatus(TrusteeshipConstants.Status.PASSED); ht.merge(to); } } else { to.setStatus(TrusteeshipConstants.Status.REFUSED); ht.merge(to); userBO.removeRole(user, new Role("WAIT_CONFIRM")); // ?? springSecurityService.refreshLoginUserAuthorities(user.getId()); if ("0".equals(code)) { throw new TrusteeshipReturnException(description); } // throw new TrusteeshipReturnException(code + ":" + description); } } }
From source file:au.org.paperminer.main.UserFilter.java
/** * Creates a DB entry for a new user and loads their info into a session cookie. * The email is checked for basic syntax, and the trove key is validated by a Trove API call * before the DB record is created.// w w w.j a va 2 s . co m * @param req * @param resp */ private void addUser(ServletRequest req, ServletResponse resp) { m_logger.info("adding user"); String email = req.getParameter("em"); String troveKey = req.getParameter("tk"); String verify = req.getParameter("vfy"); m_logger.info("AddUserFilter email:" + email + " key:" + troveKey + " verify=" + verify); UserHelper userHelper = new UserHelper(email, troveKey); try { if (userHelper.isKnownUser()) { m_logger.info("user " + email + " exists with id " + userHelper.get(UserHelper.ID)); req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e100"); } else { m_logger.info("Adding " + email + " (" + troveKey + ")"); if (!isValidEmailAddress(email)) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e101"); } else if (!isValidTroveKey(troveKey)) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e102"); } else { userHelper.createUser(email, troveKey); CookieHelper.addCookie((HttpServletResponse) resp, userHelper); m_logger.debug("user ID=" + userHelper.get(UserHelper.ID) + " status=" + userHelper.get(UserHelper.STATUS)); if ((verify != null) && verify.equals("y")) { sendVerificationEmail(userHelper.get(UserHelper.ID), userHelper.get(UserHelper.EMAIL), req); } m_logger.info("Added " + email + " (" + troveKey + ") OK"); } } } catch (PaperMinerException ex) { m_logger.error("unexpected error", ex); } }
From source file:fr.openwide.talendalfresco.rest.server.CommandAuthenticationFilter.java
/** * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */// w w w. ja v a2 s . co m public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpRes = (HttpServletResponse) res; // checking whether this request is has enough info for ticket auth by CommandServlet boolean ticketAuth = false; String ticket = req.getParameter(ARG_TICKET); if (ticket == null || ticket.length() == 0) { // no ticket sent, maybe there's still a User in session with one ? HttpSession session = httpReq.getSession(false); if (session != null) { ticketAuth = (session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER) != null); } } else { ticketAuth = true; } if (ticketAuth) { // this request is ready for ticket auth by the CommandServlet // so let's forward it to the CommandServlet, which will auth its ticket // and then do whatever Command it wants try { chain.doFilter(req, res); } catch (Throwable t) { String msg = "Unknown internal error"; logger.error(msg, t); // attempting to output response RestServerHelper.outputErrorResponse(httpRes, msg, t); } return; } // else not logged in yet // now attempting login : try { RestCommandProcessor processor = this.login(httpReq, httpRes); // output processor state with Command result res.setContentType("text/xml"); PrintWriter out = httpRes.getWriter(); processor.outputStatus(out); out.close(); } catch (Throwable t) { String msg = "Error during command auth filter processing: " + t.getMessage(); logger.error(msg, t); // attempting to output response RestServerHelper.outputErrorResponse(httpRes, msg, t); } }