|
|
|
|
@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
|
|
import org.jasig.cas.client.Protocol;
|
|
|
|
|
import org.jasig.cas.client.configuration.ConfigurationKey;
|
|
|
|
|
import org.jasig.cas.client.configuration.ConfigurationKeys;
|
|
|
|
|
import org.jasig.cas.client.util.AbstractCasFilter;
|
|
|
|
|
import org.jasig.cas.client.util.CommonUtils;
|
|
|
|
|
@ -73,6 +74,8 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|
|
|
|
|
|
|
|
|
private UrlPatternMatcherStrategy ignoreUrlPatternMatcherStrategyClass = null;
|
|
|
|
|
|
|
|
|
|
private UrlPatternMatcherStrategy includeUrlPatternMatcherStrategyClass = null;
|
|
|
|
|
|
|
|
|
|
private static final Map<String, Class<? extends UrlPatternMatcherStrategy>> PATTERN_MATCHER_TYPES =
|
|
|
|
|
new HashMap<String, Class<? extends UrlPatternMatcherStrategy>>();
|
|
|
|
|
|
|
|
|
|
@ -97,25 +100,11 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|
|
|
|
setRenew(getBoolean(ConfigurationKeys.RENEW));
|
|
|
|
|
setGateway(getBoolean(ConfigurationKeys.GATEWAY));
|
|
|
|
|
|
|
|
|
|
final String ignorePattern = getString(ConfigurationKeys.IGNORE_PATTERN);
|
|
|
|
|
final String ignoreUrlPatternType = getString(ConfigurationKeys.IGNORE_URL_PATTERN_TYPE);
|
|
|
|
|
configureUrlPatternMatchers(ConfigurationKeys.IGNORE_PATTERN, ConfigurationKeys.IGNORE_URL_PATTERN_TYPE,
|
|
|
|
|
this.ignoreUrlPatternMatcherStrategyClass);
|
|
|
|
|
|
|
|
|
|
if (ignorePattern != null) {
|
|
|
|
|
final Class<? extends UrlPatternMatcherStrategy> ignoreUrlMatcherClass = PATTERN_MATCHER_TYPES.get(ignoreUrlPatternType);
|
|
|
|
|
if (ignoreUrlMatcherClass != null) {
|
|
|
|
|
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(ignoreUrlMatcherClass.getName());
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
logger.trace("Assuming {} is a qualified class name...", ignoreUrlPatternType);
|
|
|
|
|
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(ignoreUrlPatternType);
|
|
|
|
|
} catch (final IllegalArgumentException e) {
|
|
|
|
|
logger.error("Could not instantiate class [{}]", ignoreUrlPatternType, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (this.ignoreUrlPatternMatcherStrategyClass != null) {
|
|
|
|
|
this.ignoreUrlPatternMatcherStrategyClass.setPattern(ignorePattern);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
configureUrlPatternMatchers(ConfigurationKeys.INCLUDE_PATTERN, ConfigurationKeys.INCLUDE_URL_PATTERN_TYPE,
|
|
|
|
|
this.includeUrlPatternMatcherStrategyClass);
|
|
|
|
|
|
|
|
|
|
final Class<? extends GatewayResolver> gatewayStorageClass = getClass(ConfigurationKeys.GATEWAY_STORAGE_CLASS);
|
|
|
|
|
|
|
|
|
|
@ -148,6 +137,12 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isRequestUrlIncluded(request)) {
|
|
|
|
|
logger.debug("Request is not included.");
|
|
|
|
|
filterChain.doFilter(request, response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final HttpSession session = request.getSession(false);
|
|
|
|
|
final Assertion assertion = session != null ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : null;
|
|
|
|
|
|
|
|
|
|
@ -200,6 +195,43 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|
|
|
|
this.gatewayStorage = gatewayStorage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureUrlPatternMatchers(final ConfigurationKey<String> keyName,
|
|
|
|
|
final ConfigurationKey<String> patternTypeKeyName,
|
|
|
|
|
final UrlPatternMatcherStrategy urlPatternMatcherStrategy) {
|
|
|
|
|
final String pattern = getString(keyName);
|
|
|
|
|
final String patternType = getString(patternTypeKeyName);
|
|
|
|
|
|
|
|
|
|
if (pattern != null) {
|
|
|
|
|
final Class<? extends UrlPatternMatcherStrategy> ignoreUrlMatcherClass = PATTERN_MATCHER_TYPES.get(patternType);
|
|
|
|
|
if (ignoreUrlMatcherClass != null) {
|
|
|
|
|
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(ignoreUrlMatcherClass.getName());
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
logger.trace("Assuming {} is a qualified class name...", patternType);
|
|
|
|
|
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(patternType);
|
|
|
|
|
} catch (final IllegalArgumentException e) {
|
|
|
|
|
logger.error("Could not instantiate class [{}]", patternType, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (urlPatternMatcherStrategy != null) {
|
|
|
|
|
urlPatternMatcherStrategy.setPattern(pattern);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isRequestUrlIncluded(final HttpServletRequest request) {
|
|
|
|
|
if (this.includeUrlPatternMatcherStrategyClass == null) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final StringBuffer urlBuffer = request.getRequestURL();
|
|
|
|
|
if (request.getQueryString() != null) {
|
|
|
|
|
urlBuffer.append("?").append(request.getQueryString());
|
|
|
|
|
}
|
|
|
|
|
final String requestUri = urlBuffer.toString();
|
|
|
|
|
return this.includeUrlPatternMatcherStrategyClass.matches(requestUri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isRequestUrlExcluded(final HttpServletRequest request) {
|
|
|
|
|
if (this.ignoreUrlPatternMatcherStrategyClass == null) {
|
|
|
|
|
return false;
|
|
|
|
|
|