diff --git a/web/src/main/java/org/springframework/security/web/header/HeaderWriterFilter.java b/web/src/main/java/org/springframework/security/web/header/HeaderWriterFilter.java index d963c79748..1fbd0c256e 100644 --- a/web/src/main/java/org/springframework/security/web/header/HeaderWriterFilter.java +++ b/web/src/main/java/org/springframework/security/web/header/HeaderWriterFilter.java @@ -15,17 +15,15 @@ */ package org.springframework.security.web.header; -import java.io.IOException; -import java.util.List; +import org.springframework.util.Assert; +import org.springframework.web.filter.OncePerRequestFilter; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.web.util.OnCommittedResponseWrapper; -import org.springframework.util.Assert; -import org.springframework.web.filter.OncePerRequestFilter; +import java.io.IOException; +import java.util.*; /** * Filter implementation to add headers to the current response. Can be useful to add @@ -58,52 +56,12 @@ public class HeaderWriterFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) - throws ServletException, IOException { + throws ServletException, IOException { - HeaderWriterResponse headerWriterResponse = new HeaderWriterResponse(request, - response, this.headerWriters); - try { - filterChain.doFilter(request, headerWriterResponse); - } - finally { - headerWriterResponse.writeHeaders(); + for (HeaderWriter headerWriter : headerWriters) { + headerWriter.writeHeaders(request, response); } + filterChain.doFilter(request, response); } - static class HeaderWriterResponse extends OnCommittedResponseWrapper { - private final HttpServletRequest request; - private final List headerWriters; - - HeaderWriterResponse(HttpServletRequest request, HttpServletResponse response, - List headerWriters) { - super(response); - this.request = request; - this.headerWriters = headerWriters; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.security.web.util.OnCommittedResponseWrapper# - * onResponseCommitted() - */ - @Override - protected void onResponseCommitted() { - writeHeaders(); - this.disableOnResponseCommitted(); - } - - protected void writeHeaders() { - if (isDisableOnResponseCommitted()) { - return; - } - for (HeaderWriter headerWriter : this.headerWriters) { - headerWriter.writeHeaders(this.request, getHttpResponse()); - } - } - - private HttpServletResponse getHttpResponse() { - return (HttpServletResponse) getResponse(); - } - } } diff --git a/web/src/main/java/org/springframework/security/web/header/writers/CacheControlHeadersWriter.java b/web/src/main/java/org/springframework/security/web/header/writers/CacheControlHeadersWriter.java index d5f115abbb..ae6c93443e 100644 --- a/web/src/main/java/org/springframework/security/web/header/writers/CacheControlHeadersWriter.java +++ b/web/src/main/java/org/springframework/security/web/header/writers/CacheControlHeadersWriter.java @@ -15,20 +15,14 @@ */ package org.springframework.security.web.header.writers; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.springframework.security.web.header.Header; -import org.springframework.security.web.header.HeaderWriter; -import org.springframework.util.ReflectionUtils; /** - * Inserts headers to prevent caching if no cache control headers have been specified. - * Specifically it adds the following headers: + * A {@link StaticHeadersWriter} that inserts headers to prevent caching. Specifically it + * adds the following headers: *