List of usage examples for org.springframework.web.context.request ServletWebRequest ServletWebRequest
public ServletWebRequest(HttpServletRequest request)
From source file:org.broadleafcommerce.core.web.controller.account.BroadleafSocialRegisterController.java
public String processRegister(RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response, Model model) throws ServiceException, PricingException { if (isUseEmailForLogin()) { Customer customer = registerCustomerForm.getCustomer(); customer.setUsername(customer.getEmailAddress()); }/* w ww . j a v a2 s . c o m*/ registerCustomerValidator.validate(registerCustomerForm, errors, isUseEmailForLogin()); if (!errors.hasErrors()) { Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm()); assert (newCustomer != null); ProviderSignInUtils.handlePostSignUp(newCustomer.getUsername(), new ServletWebRequest(request)); // The next line needs to use the customer from the input form and not the customer returned after registration // so that we still have the unencoded password for use by the authentication mechanism. loginService.loginCustomer(registerCustomerForm.getCustomer()); // Need to ensure that the Cart on CartState is owned by the newly registered customer. Order cart = CartState.getCart(); if (cart != null && !(cart instanceof NullOrderImpl) && cart.getEmailAddress() == null) { cart.setEmailAddress(newCustomer.getEmailAddress()); orderService.save(cart, false); } String redirectUrl = registerCustomerForm.getRedirectUrl(); if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) { redirectUrl = null; } return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl; } else { return getRegisterView(); } }
From source file:org.broadleafcommerce.core.web.order.security.BroadleafAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { String targetUrl = request.getParameter(getTargetUrlParameter()); if (BLCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) { request.getSession().removeAttribute(SESSION_ATTR); }//from w w w. java2 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.broadleafcommerce.core.web.order.SessionOrderLockManager.java
@Override public boolean isActive() { if (getRequest() == null) { return false; }//from ww w . ja v a 2s. c om if (BroadleafRequestContext.getBroadleafRequestContext() != null && BroadleafRequestContext.getBroadleafRequestContext().getWebRequest() != null) { if (!BLCRequestUtils .isOKtoUseSession(BroadleafRequestContext.getBroadleafRequestContext().getWebRequest())) { return false; } } else if (!BLCRequestUtils.isOKtoUseSession(new ServletWebRequest(getRequest()))) { return false; } return true; }
From source file:org.broadleafcommerce.profile.web.core.security.SessionFixationProtectionFilter.java
protected void abortUser(HttpServletRequest request, HttpServletResponse response) throws IOException { SecurityContextHolder.clearContext(); cookieUtils.invalidateCookie(response, SessionFixationProtectionCookie.COOKIE_NAME); if (BLCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) { request.getSession().invalidate(); }//from w w w . ja va 2 s . c o m response.sendRedirect("/"); }
From source file:org.fao.geonet.api.GlobalExceptionController.java
/** * * @param request the HTTP request object. * @return true if the content type is allowed to have a body when returning an error to the client, false if the * response should contain an empty body. *///from w ww .jav a2s . c o m private boolean contentTypeNeedsBody(HttpServletRequest request) { boolean needsBody; List<MediaType> requestMediaTypes = resolveMediaTypes(new ServletWebRequest(request)); Set<MediaType> allowedContentTypes = Sets.newHashSet(MediaType.APPLICATION_XML, MediaType.APPLICATION_XHTML_XML, MediaType.APPLICATION_JSON); needsBody = !Collections.disjoint(allowedContentTypes, requestMediaTypes); return needsBody; }
From source file:org.jtalks.jcommune.service.nontransactional.MentionedUsersTest.java
private void setupRequestAttributes() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(8080);/*w ww. j ava2 s. com*/ request.setContextPath("/forum"); RequestContextHolder.setRequestAttributes(new ServletWebRequest(request)); }
From source file:org.jtalks.jcommune.service.transactional.TransactionalUserServiceTest.java
private void boundMockHttpRequestToThread(String contextPath) { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("testing.com"); request.setServerPort(1234);/*from www.j av a2 s . c o m*/ request.setContextPath(contextPath); RequestContextHolder.setRequestAttributes(new ServletWebRequest(request)); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.SessionController1_8Test.java
@Before public void before() { controller = new SessionController1_8(); MockHttpServletRequest hsr = new MockHttpServletRequest(); hsr.setSession(new MockHttpSession(new MockServletContext(), SESSION_ID)); request = new ServletWebRequest(hsr); Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, sp, fr")); }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.DelegatingController.java
/** * Initialize the given binder instance, for example with custom editors. * Called by <code>createBinder</code>. * <p>This method allows you to register custom editors for certain fields of your * command 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. * <p>Note: the command object is not directly passed to this method, but it's available * via {@link org.springframework.validation.DataBinder#getTarget()} * @param request current HTTP request/* ww w . j a v a 2 s.c om*/ * @param binder 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, ComponentDataBinder binder) throws Exception { if (this.webBindingInitializer != null) { this.webBindingInitializer.initBinder(binder, new ServletWebRequest(request)); } if (binder.getTarget() instanceof SubCommandProvider) { Map<String, CommandWrapper> pathMap = ComponentUtils .getComponentPathMap((SubCommandProvider) binder.getTarget()); for (Entry<String, CommandWrapper> entry : pathMap.entrySet()) { String name = entry.getValue().getTagName(); SegmentConfiguration config = ComponentUtils.getConfiguration(getWebApplicationContext(), name); if (config != null && config.getComponentBindingInitializers() != null) { for (ComponentBindingInitializer bindInitializer : config.getComponentBindingInitializers()) { bindInitializer.initBinder(new ServletWebRequest(request), binder, entry.getKey()); } } } } }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.DelegatingController.java
protected void postProcessModel(HttpServletRequest request, ModelAndView modelAndView) throws Exception { SubCommandProvider command = ComponentUtils.getCommand(modelAndView); if (command != null) { Map<String, CommandWrapper> pathMap = ComponentUtils.getComponentPathMap((SubCommandProvider) command); for (Entry<String, CommandWrapper> entry : pathMap.entrySet()) { String name = entry.getValue().getTagName(); SegmentConfiguration config = ComponentUtils.getConfiguration(getWebApplicationContext(), name); if (config != null && config.getComponentPostprocessors() != null) { for (ComponentPostprocessor processor : config.getComponentPostprocessors()) { processor.postHandle(new ServletWebRequest(request), modelAndView, entry.getKey()); }//from w w w . j av a 2 s . co m } } } }