From 7afa99a21a6cd1860c7c3d46f9b5a32073a1c9c0 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 20 Oct 2007 23:10:53 +0000 Subject: [PATCH] Security filter base class. --- .../security/ui/SpringSecurityFilter.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 core/src/main/java/org/springframework/security/ui/SpringSecurityFilter.java diff --git a/core/src/main/java/org/springframework/security/ui/SpringSecurityFilter.java b/core/src/main/java/org/springframework/security/ui/SpringSecurityFilter.java new file mode 100644 index 0000000000..a8adad08ff --- /dev/null +++ b/core/src/main/java/org/springframework/security/ui/SpringSecurityFilter.java @@ -0,0 +1,54 @@ +package org.springframework.security.ui; + +import org.springframework.core.Ordered; + + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import javax.servlet.FilterChain; +import javax.servlet.ServletResponse; +import javax.servlet.FilterConfig; +import javax.servlet.ServletRequest; +import javax.servlet.Filter; +import java.io.IOException; + +/** + * Implements Ordered interface as required by security namespace configuration and implements unused filter + * lifecycle methods and performs casting of request and response to http versions in doFilter method. + * + * @author Luke Taylor + * @version $Id$ + */ +public abstract class SpringSecurityFilter implements Filter, Ordered { + + /** + * Does nothing. We use IoC container lifecycle services instead. + * + * @param filterConfig ignored + * @throws ServletException ignored + */ + public void init(FilterConfig filterConfig) throws ServletException { + } + + /** + * Does nothing. We use IoC container lifecycle services instead. + */ + public void destroy() { + } + + public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + // Do we really need the checks on the types in practice ? + if (!(request instanceof HttpServletRequest)) { + throw new ServletException("Can only process HttpServletRequest"); + } + + if (!(response instanceof HttpServletResponse)) { + throw new ServletException("Can only process HttpServletResponse"); + } + + doFilterHttp((HttpServletRequest)request, (HttpServletResponse)response, chain); + } + + protected abstract void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException; +} \ No newline at end of file