List of usage examples for org.springframework.web.context.request ServletWebRequest ServletWebRequest
public ServletWebRequest(HttpServletRequest request)
From source file:org.sparkcommerce.core.web.controller.account.SparkLoginController.java
/** * Looks up the passed in username and sends an email to the address on file with a * reset password token. /*w ww.ja va 2 s . c om*/ * * Returns error codes for invalid username. * * @param username * @param request * @param model * @return the return view */ public String processForgotPassword(String username, HttpServletRequest request, Model model) { GenericResponse errorResponse = customerService.sendForgotPasswordNotification(username, getResetPasswordUrl(request)); if (errorResponse.getHasErrors()) { String errorCode = errorResponse.getErrorCodesList().get(0); model.addAttribute("errorCode", errorCode); return getForgotPasswordView(); } else { if (SCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) { request.getSession(true).setAttribute("forgot_password_username", username); } return getForgotPasswordSuccessView(); } }
From source file:org.sparkcommerce.core.web.controller.account.SparkLoginController.java
/** * Initializes the reset password by ensuring that the passed in token URL * parameter initializes the hidden form field. * // w w w .j a v a 2 s .c o m * Also, if the reset password request is in the same session as the * forgotPassword request, the username will auto-populate * * @param request * @return the return view */ public ResetPasswordForm initResetPasswordForm(HttpServletRequest request) { ResetPasswordForm resetPasswordForm = new ResetPasswordForm(); String username = null; if (SCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) { username = (String) request.getSession(true).getAttribute("forgot_password_username"); } String token = request.getParameter("token"); resetPasswordForm.setToken(token); resetPasswordForm.setUsername(username); return resetPasswordForm; }
From source file:org.sparkcommerce.core.web.order.security.SparkAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { String targetUrl = request.getParameter(getTargetUrlParameter()); if (SCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) { request.getSession().removeAttribute(SESSION_ATTR); }//from ww w .j av a 2 s .c o m if (StringUtils.isNotBlank(targetUrl) && targetUrl.contains(":")) { getRedirectStrategy().sendRedirect(request, response, getDefaultTargetUrl()); } else { super.onAuthenticationSuccess(request, response, authentication); } }
From source file:org.sparkcommerce.core.web.order.SessionOrderLockManager.java
@Override public boolean isActive() { if (getRequest() == null) { return false; }/* w ww .j a va2s . co m*/ if (SparkRequestContext.getSparkRequestContext() != null && SparkRequestContext.getSparkRequestContext().getWebRequest() != null) { if (!SCRequestUtils.isOKtoUseSession(SparkRequestContext.getSparkRequestContext().getWebRequest())) { return false; } } else if (!SCRequestUtils.isOKtoUseSession(new ServletWebRequest(getRequest()))) { return false; } return true; }
From source file:org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter.java
private List<MediaType> getAcceptableMediaTypes(HttpServletRequest request) throws HttpMediaTypeNotAcceptableException { List<MediaType> mediaTypes = this.contentNegotiationManager .resolveMediaTypes(new ServletWebRequest(request)); return mediaTypes.isEmpty() ? Collections.singletonList(MediaType.ALL) : mediaTypes; }
From source file:org.springframework.security.web.util.matcher.MediaTypeRequestMatcher.java
public boolean matches(HttpServletRequest request) { List<MediaType> httpRequestMediaTypes; try {/*from w ww .java 2 s . c om*/ httpRequestMediaTypes = this.contentNegotiationStrategy .resolveMediaTypes(new ServletWebRequest(request)); } catch (HttpMediaTypeNotAcceptableException e) { this.logger.debug("Failed to parse MediaTypes, returning false", e); return false; } if (this.logger.isDebugEnabled()) { this.logger.debug("httpRequestMediaTypes=" + httpRequestMediaTypes); } for (MediaType httpRequestMediaType : httpRequestMediaTypes) { if (this.logger.isDebugEnabled()) { this.logger.debug("Processing " + httpRequestMediaType); } if (shouldIgnore(httpRequestMediaType)) { this.logger.debug("Ignoring"); continue; } if (this.useEquals) { boolean isEqualTo = this.matchingMediaTypes.contains(httpRequestMediaType); this.logger.debug("isEqualTo " + isEqualTo); return isEqualTo; } for (MediaType matchingMediaType : this.matchingMediaTypes) { boolean isCompatibleWith = matchingMediaType.isCompatibleWith(httpRequestMediaType); if (this.logger.isDebugEnabled()) { this.logger.debug(matchingMediaType + " .isCompatibleWith " + httpRequestMediaType + " = " + isCompatibleWith); } if (isCompatibleWith) { return true; } } } this.logger.debug("Did not match any media types"); return false; }
From source file:org.springframework.security.web.util.MediaTypeRequestMatcher.java
@Override public boolean matches(HttpServletRequest request) { List<MediaType> httpRequestMediaTypes; try {/*www . j a v a 2 s . c om*/ httpRequestMediaTypes = contentNegotiationStrategy.resolveMediaTypes(new ServletWebRequest(request)); } catch (HttpMediaTypeNotAcceptableException e) { logger.debug("Failed to parse MediaTypes, returning false", e); return false; } for (MediaType httpRequestMediaType : httpRequestMediaTypes) { if (ignoredMediaTypes.contains(httpRequestMediaType)) { continue; } if (useEquals) { return matchingMediaTypes.contains(httpRequestMediaType); } for (MediaType matchingMediaType : matchingMediaTypes) { if (matchingMediaType.isCompatibleWith(httpRequestMediaType)) { return true; } } } return false; }
From source file:org.springframework.web.servlet.mvc.generic.GenericFormController.java
/** * Initialize the given binder instance, for example with custom editors. * Called by {@link #createBinder}.// ww w.j a v a2 s. com * <p>This method allows you to register custom editors for certain fields of your * formObject class. For instance, you will be able to transform Date objects into a * String pattern and back, in order to allow your JavaBeans to have Date properties * and still be able to set and display them in an HTML interface. * <p>The default implementation is empty. * @param request current HTTP request * @param binder the new binder instance * @throws Exception in case of invalid state or arguments * @see #createBinder * @see org.springframework.validation.DataBinder#registerCustomEditor * @see org.springframework.beans.propertyeditors.CustomDateEditor */ protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { if (this.webBindingInitializer != null) { this.webBindingInitializer.initBinder(binder, new ServletWebRequest(request)); } }