parent
5e804608df
commit
80748794ca
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright 2006 The JA-SIG Collaborative. All rights reserved. See license
|
||||
* distributed with this file and available online at
|
||||
* http://www.ja-sig.org/products/cas/overview/license/index.html
|
||||
*/
|
||||
package org.jasig.cas.client.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Utility class to retrieve a Filter from a Spring-managed configuration file.
|
||||
* Based on the FilterToBeanProxy class in Acegi Security (but simplified)
|
||||
*
|
||||
* @author Scott Battaglia
|
||||
* @version $Revision$ $Date$
|
||||
* @since 3.0
|
||||
*/
|
||||
public class FilterToBeanProxy implements Filter {
|
||||
|
||||
/**
|
||||
* The filter we are proxying.
|
||||
*/
|
||||
private Filter filter;
|
||||
|
||||
/**
|
||||
* Instance of commons logging.
|
||||
*/
|
||||
protected final Log log = LogFactory.getLog(this.getClass());
|
||||
|
||||
public final void destroy() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public final void doFilter(final ServletRequest request,
|
||||
final ServletResponse response, final FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
this.filter.doFilter(request, response, chain);
|
||||
}
|
||||
|
||||
public final void init(final FilterConfig filterConfig)
|
||||
throws ServletException {
|
||||
final String targetBean = filterConfig.getInitParameter("targetBean");
|
||||
|
||||
if (CommonUtils.isBlank(targetBean)) {
|
||||
throw new ServletException(
|
||||
"init-parameter missing: targetBean is required.");
|
||||
}
|
||||
|
||||
final ApplicationContext ctx = this.getContext(filterConfig);
|
||||
|
||||
if (!ctx.containsBean(targetBean)) {
|
||||
throw new ServletException("targetBean '" + targetBean
|
||||
+ "' not found in context");
|
||||
}
|
||||
|
||||
log.trace("Loading filter from Spring ApplicationContext with name: " + targetBean);
|
||||
this.filter = (Filter) ctx.getBean(targetBean, Filter.class);
|
||||
}
|
||||
|
||||
protected ApplicationContext getContext(FilterConfig filterConfig) {
|
||||
return WebApplicationContextUtils
|
||||
.getRequiredWebApplicationContext(filterConfig.getServletContext());
|
||||
}
|
||||
}
|
||||
|
|
@ -17,27 +17,27 @@
|
|||
|
||||
<filter>
|
||||
<filter-name>CAS Authentication Filter Proxy</filter-name>
|
||||
<filter-class>org.jasig.cas.client.util.FilterToBeanProxy</filter-class>
|
||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||
<init-param>
|
||||
<param-name>targetBean</param-name>
|
||||
<param-name>targetBeanName</param-name>
|
||||
<param-value>casAuthenticationFilter</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
<filter>
|
||||
<filter-name>CAS Validation Filter Proxy</filter-name>
|
||||
<filter-class>org.jasig.cas.client.util.FilterToBeanProxy</filter-class>
|
||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||
<init-param>
|
||||
<param-name>targetBean</param-name>
|
||||
<param-name>targetBeanName</param-name>
|
||||
<param-value>casValidationFilter</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
<filter>
|
||||
<filter-name>CAS Authorization Filter Proxy</filter-name>
|
||||
<filter-class>org.jasig.cas.client.util.FilterToBeanProxy</filter-class>
|
||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||
<init-param>
|
||||
<param-name>targetBean</param-name>
|
||||
<param-name>targetBeanName</param-name>
|
||||
<param-value>casAuthorizationFilter</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
|
|
|||
Loading…
Reference in New Issue