List of usage examples for javax.servlet.http HttpServletResponseWrapper HttpServletResponseWrapper
public HttpServletResponseWrapper(HttpServletResponse response)
From source file:org.thymeleaf.spring4.view.FragmentRenderer.java
public static String render(final ThymeleafView view, final IFragmentSpec fragmentSpec, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) throws Exception { final StringWriter htmlStringWriter = new StringWriter(); new ThymeleafView() { @Override/*w ww. j a v a 2 s .c om*/ public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper(response) { @Override public PrintWriter getWriter() throws IOException { return new PrintWriter(htmlStringWriter); } }; view.renderFragment(fragmentSpec, model, request, wrapper); } }.render(modelMap, request, response); return htmlStringWriter.toString(); }
From source file:com.marklogic.samplestack.web.security.SamplestackLogoutSuccessHandler.java
@Override /**//from w w w .j a va 2 s . c o m * Override handler for logout success. */ public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); responseWrapper.setStatus(HttpStatus.SC_OK); }
From source file:com.marklogic.samplestack.web.security.SamplestackAuthenticationEntryPoint.java
@Override /**/*from w w w .j av a2 s . co m*/ * Override handler that returns 401 for any unauthenticated * request to a secured endpoint. */ public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); responseWrapper.setStatus(HttpStatus.SC_UNAUTHORIZED); Writer out = responseWrapper.getWriter(); errors.writeJsonResponse(out, HttpStatus.SC_UNAUTHORIZED, "Unauthorized"); out.close(); }
From source file:com.marklogic.samplestack.web.security.SamplestackAccessDeniedHandler.java
@Override /**//from www .j av a 2 s . c o m * Handler override to return 403s on the HttpResponse. */ public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); responseWrapper.setStatus(HttpStatus.SC_FORBIDDEN); Writer out = responseWrapper.getWriter(); errors.writeJsonResponse(out, HttpStatus.SC_FORBIDDEN, "Forbidden"); out.close(); }
From source file:com.marklogic.samplestack.web.security.SamplestackAuthenticationFailureHandler.java
@Override /**//from ww w .java2s.c o m * Override handler that returns 401 after failed authentication. */ public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); responseWrapper.setStatus(HttpStatus.SC_UNAUTHORIZED); Writer out = responseWrapper.getWriter(); errors.writeJsonResponse(out, HttpStatus.SC_UNAUTHORIZED, "Unauthorized"); out.close(); }
From source file:com.epam.cme.storefront.security.cookie.EnhancedCookieGenerator.java
public void addCookie(final HttpServletRequest request, final HttpServletResponse response, final String cookieValue) { final CookieDecorator cookieDecorator = getCookieDecorator(request, response); super.addCookie(new HttpServletResponseWrapper(response) { @Override/*from w w w . j av a2 s . c o m*/ public void addCookie(final Cookie cookie) { super.addCookie(cookieDecorator.decorate(cookie)); } }, cookieValue); }
From source file:miage.ecom.web.security.ExtJsAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); Writer out = responseWrapper.getWriter(); out.write("{success:true}"); out.close();/*from ww w. ja va2 s. c o m*/ }
From source file:miage.ecom.web.security.ExtJsAuthenticationFailureHandler.java
@Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); Writer out = responseWrapper.getWriter(); out.write("{success:false, errors: { reason: 'Login failed. Try again.' }}"); out.close();/*w ww . j a v a 2 s . co m*/ }
From source file:com.marklogic.samplestack.web.SessionController.java
/** * Exposes endpoint that returns CSRF token information and a session for use in login. * @param request The Http Request./*from w w w .ja v a 2 s . c o m*/ * @param response The Http response. * @return A JsonNode with bare-bones acknowledgement. */ @RequestMapping(value = "session", method = RequestMethod.GET) public @ResponseBody JsonNode hello(HttpServletRequest request, HttpServletResponse response) { CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf"); String headerName = csrfToken.getHeaderName(); String token = csrfToken.getToken(); HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response); responseWrapper.addHeader(headerName, token); return errors.makeJsonResponse(200, "New Session"); }
From source file:com.acc.storefront.security.cookie.EnhancedCookieGenerator.java
@Override public void addCookie(final HttpServletResponse response, final String cookieValue) { super.addCookie(new HttpServletResponseWrapper(response) { @Override/*from ww w . j av a 2 s.c o m*/ public void addCookie(final Cookie cookie) { setEnhancedCookiePath(cookie); if (isHttpOnly()) { // Custom code to write the cookie including the httpOnly flag final StringBuffer headerBuffer = new StringBuffer(100); ServerCookie.appendCookieValue(headerBuffer, cookie.getVersion(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getComment(), cookie.getMaxAge(), cookie.getSecure(), true); response.addHeader(HEADER_COOKIE, headerBuffer.toString()); } else { // Write the cookie as normal super.addCookie(cookie); } } }, cookieValue); }