CASC-219: updated javadocs and added map to keep track of pattern matchers
This commit is contained in:
parent
b97d03d126
commit
3773fc9e54
|
|
@ -19,6 +19,8 @@
|
|||
package org.jasig.cas.client.authentication;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
@ -66,10 +68,18 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|||
|
||||
private GatewayResolver gatewayStorage = new DefaultGatewayResolverImpl();
|
||||
|
||||
private AuthenticationRedirectStrategy authenticationRedirectStrategy = new DefaultAuthenticationRedirectStrategy();
|
||||
|
||||
private UrlPatternMatcherStrategy ignoreUrlPatternMatcherStrategyClass = null;
|
||||
|
||||
private AuthenticationRedirectStrategy authenticationRedirectStrategy = new DefaultAuthenticationRedirectStrategy();
|
||||
|
||||
private final Map<String, Class<? extends UrlPatternMatcherStrategy>> PATTERN_MATCHER_TYPES =
|
||||
new HashMap<String, Class<? extends UrlPatternMatcherStrategy>>();
|
||||
|
||||
public AuthenticationFilter() {
|
||||
this.PATTERN_MATCHER_TYPES.put("EXACT", ExactUrlPatternMatcherStrategy.class);
|
||||
this.PATTERN_MATCHER_TYPES.put("REGEX", RegexUrlPatternMatcherStrategy.class);
|
||||
}
|
||||
|
||||
protected void initInternal(final FilterConfig filterConfig) throws ServletException {
|
||||
if (!isIgnoreInitConfiguration()) {
|
||||
super.initInternal(filterConfig);
|
||||
|
|
@ -83,16 +93,17 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|||
final String ignorePattern = getPropertyFromInitParams(filterConfig, "ignorePattern", null);
|
||||
logger.trace("Loaded ignorePattern parameter: {}", ignorePattern);
|
||||
|
||||
final String ignoreUrlMatcherClass = getPropertyFromInitParams(filterConfig, "ignoreUrlPatternMatcherStrategyClass", null);
|
||||
logger.trace("Loaded ignoreUrlPatternMatcherStrategyClass parameter: {}", ignoreUrlMatcherClass);
|
||||
final String ignoreUrlPatternType = getPropertyFromInitParams(filterConfig, "ignoreUrlPatternType", "REGEX");
|
||||
logger.trace("Loaded ignoreUrlPatternType parameter: {}", ignoreUrlPatternType);
|
||||
|
||||
if (ignorePattern != null ) {
|
||||
final Class<? extends UrlPatternMatcherStrategy> ignoreUrlMatcherClass = this.PATTERN_MATCHER_TYPES.get(ignoreUrlPatternType);
|
||||
if (ignoreUrlMatcherClass != null) {
|
||||
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(ignoreUrlMatcherClass);
|
||||
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(ignoreUrlMatcherClass.getName());
|
||||
this.ignoreUrlPatternMatcherStrategyClass.setPattern(ignorePattern);
|
||||
} else {
|
||||
this.ignoreUrlPatternMatcherStrategyClass = new RegexUrlPatternMatcherStrategy();
|
||||
logger.trace("Could not find and load: {}", ignoreUrlMatcherClass);
|
||||
}
|
||||
this.ignoreUrlPatternMatcherStrategyClass.setPattern(ignorePattern);
|
||||
}
|
||||
|
||||
final String gatewayStorageClass = getPropertyFromInitParams(filterConfig, "gatewayStorageClass", null);
|
||||
|
|
@ -100,13 +111,6 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|||
if (gatewayStorageClass != null) {
|
||||
this.gatewayStorage = ReflectUtils.newInstance(gatewayStorageClass);
|
||||
}
|
||||
|
||||
final String authenticationRedirectStrategyClass = getPropertyFromInitParams(filterConfig,
|
||||
"authenticationRedirectStrategyClass", null);
|
||||
|
||||
if (authenticationRedirectStrategyClass != null) {
|
||||
this.authenticationRedirectStrategy = ReflectUtils.newInstance(authenticationRedirectStrategyClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@
|
|||
package org.jasig.cas.client.authentication;
|
||||
/**
|
||||
* Defines an abstraction by which request urls can be matches against a given pattern.
|
||||
*
|
||||
* New instances for all extensions for this strategy interface will be created per
|
||||
* each request. The client will ultimately invoke the {@link #matches(String)} method
|
||||
* having already applied and set the pattern via the {@link #setPattern(String)} method.
|
||||
* The pattern itself will be retrieved via the client configuration.
|
||||
* @author Misagh Moayyed
|
||||
* @since 3.3.1
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -245,13 +245,13 @@ public final class AuthenticationFilterTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIgnorePatternsWithNoRegex() throws Exception {
|
||||
public void testIgnorePatternsWithExactMatching() throws Exception {
|
||||
final AuthenticationFilter f = new AuthenticationFilter();
|
||||
final MockServletContext context = new MockServletContext();
|
||||
context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
|
||||
|
||||
context.addInitParameter("ignorePattern", "=valueToIgnore");
|
||||
context.addInitParameter("ignoreUrlPatternMatcherStrategyClass", ExactUrlPatternMatcherStrategy.class.getName());
|
||||
context.addInitParameter("ignoreUrlPatternType", "EXACT");
|
||||
context.addInitParameter("service", CAS_SERVICE_URL);
|
||||
f.init(new MockFilterConfig(context));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue