Removed inappropriate inheritance from AbstractProcessingFilter (doesn't make sense for X509 case).

This commit is contained in:
Luke Taylor 2005-03-10 03:16:45 +00:00
parent ae91b58685
commit fea1725f39
1 changed files with 51 additions and 12 deletions

View File

@ -4,13 +4,22 @@ import net.sf.acegisecurity.ui.AbstractProcessingFilter;
import net.sf.acegisecurity.ui.WebAuthenticationDetails; import net.sf.acegisecurity.ui.WebAuthenticationDetails;
import net.sf.acegisecurity.Authentication; import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.AuthenticationException; import net.sf.acegisecurity.AuthenticationException;
import net.sf.acegisecurity.AuthenticationManager;
import net.sf.acegisecurity.context.ContextHolder; import net.sf.acegisecurity.context.ContextHolder;
import net.sf.acegisecurity.context.security.SecureContext; import net.sf.acegisecurity.context.security.SecureContext;
import net.sf.acegisecurity.context.security.SecureContextUtils;
import net.sf.acegisecurity.providers.x509.X509AuthenticationToken; import net.sf.acegisecurity.providers.x509.X509AuthenticationToken;
import net.sf.acegisecurity.providers.x509.X509AuthenticationProvider;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.*;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
/** /**
* Processes the X.509 certificate submitted by a client - typically * Processes the X.509 certificate submitted by a client - typically
@ -33,20 +42,42 @@ import java.security.cert.X509Certificate;
* *
* @author Luke Taylor * @author Luke Taylor
*/ */
public class X509ProcessingFilter extends AbstractProcessingFilter { public class X509ProcessingFilter implements Filter, InitializingBean {
//~ Static fields/initializers =============================================
public String getDefaultFilterProcessesUrl() { private static final Log logger = LogFactory.getLog(X509ProcessingFilter.class);
return "/*";
private AuthenticationManager authenticationManager;
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
} }
/** public void afterPropertiesSet() throws Exception {
* X.509 authentication doesn't have a specific login URL, so the default implementation if(authenticationManager == null)
* using <code>endsWith</code> isn't adequate. throw new IllegalArgumentException("An AuthenticationManager must be set");
* }
*/
protected boolean requiresAuthentication(HttpServletRequest request, public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse response) { if (!(request instanceof HttpServletRequest)) {
return true; // for the time being. Should probably do a pattern match on the URL throw new ServletException("Can only process HttpServletRequest");
}
if (!(response instanceof HttpServletResponse)) {
throw new ServletException("Can only process HttpServletResponse");
}
SecureContext ctx = SecureContextUtils.getSecureContext();
logger.debug("Checking secure context: " + ctx);
if(ctx.getAuthentication() == null) {
attemptAuthentication((HttpServletRequest)request);
}
filterChain.doFilter(request, response);
} }
/** /**
@ -62,6 +93,7 @@ public class X509ProcessingFilter extends AbstractProcessingFilter {
if(certs != null && certs.length > 0) { if(certs != null && certs.length > 0) {
clientCertificate = certs[0]; clientCertificate = certs[0];
logger.debug("Authenticating with certificate " + clientCertificate);
} else { } else {
logger.warn("No client certificate found in Request."); logger.warn("No client certificate found in Request.");
} }
@ -71,6 +103,13 @@ public class X509ProcessingFilter extends AbstractProcessingFilter {
// authRequest.setDetails(new WebAuthenticationDetails(request)); // authRequest.setDetails(new WebAuthenticationDetails(request));
return this.getAuthenticationManager().authenticate(authRequest); return authenticationManager.authenticate(authRequest);
} }
public void init(FilterConfig filterConfig) throws ServletException { }
public void destroy() { }
} }