CASC-219: allowed extensions for ignoring urls
This commit is contained in:
parent
3773fc9e54
commit
511bce2471
|
|
@ -96,13 +96,20 @@ public class AuthenticationFilter extends AbstractCasFilter {
|
|||
final String ignoreUrlPatternType = getPropertyFromInitParams(filterConfig, "ignoreUrlPatternType", "REGEX");
|
||||
logger.trace("Loaded ignoreUrlPatternType parameter: {}", ignoreUrlPatternType);
|
||||
|
||||
if (ignorePattern != null ) {
|
||||
if (ignorePattern != null) {
|
||||
final Class<? extends UrlPatternMatcherStrategy> ignoreUrlMatcherClass = this.PATTERN_MATCHER_TYPES.get(ignoreUrlPatternType);
|
||||
if (ignoreUrlMatcherClass != null) {
|
||||
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(ignoreUrlMatcherClass.getName());
|
||||
this.ignoreUrlPatternMatcherStrategyClass.setPattern(ignorePattern);
|
||||
} else {
|
||||
logger.trace("Could not find and load: {}", ignoreUrlMatcherClass);
|
||||
try {
|
||||
logger.trace("Assuming {} is a qualfiied class name...", ignoreUrlPatternType);
|
||||
this.ignoreUrlPatternMatcherStrategyClass = ReflectUtils.newInstance(ignoreUrlPatternType);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
logger.warn("Could not instantiate class [{}]: [{}]", ignoreUrlPatternType, e.getMessage());
|
||||
}
|
||||
}
|
||||
if (this.ignoreUrlPatternMatcherStrategyClass != null) {
|
||||
this.ignoreUrlPatternMatcherStrategyClass.setPattern(ignorePattern);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,6 +118,13 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -272,4 +272,62 @@ public final class AuthenticationFilterTests {
|
|||
f.doFilter(request, response, filterChain);
|
||||
assertNull(response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnorePatternsWithExactClassname() throws Exception {
|
||||
final AuthenticationFilter f = new AuthenticationFilter();
|
||||
final MockServletContext context = new MockServletContext();
|
||||
context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
|
||||
|
||||
context.addInitParameter("ignorePattern", "=valueToIgnore");
|
||||
context.addInitParameter("ignoreUrlPatternType", ExactUrlPatternMatcherStrategy.class.getName());
|
||||
context.addInitParameter("service", CAS_SERVICE_URL);
|
||||
f.init(new MockFilterConfig(context));
|
||||
|
||||
final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
final String URL = CAS_SERVICE_URL + "?param=valueToIgnore";
|
||||
request.setRequestURI(URL);
|
||||
|
||||
final MockHttpSession session = new MockHttpSession();
|
||||
request.setSession(session);
|
||||
|
||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
final FilterChain filterChain = new FilterChain() {
|
||||
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
|
||||
}
|
||||
};
|
||||
|
||||
f.doFilter(request, response, filterChain);
|
||||
assertNull(response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnorePatternsWithInvalidClassname() throws Exception {
|
||||
final AuthenticationFilter f = new AuthenticationFilter();
|
||||
final MockServletContext context = new MockServletContext();
|
||||
context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
|
||||
|
||||
context.addInitParameter("ignorePattern", "=valueToIgnore");
|
||||
context.addInitParameter("ignoreUrlPatternType", "unknown.class.name");
|
||||
context.addInitParameter("service", CAS_SERVICE_URL);
|
||||
f.init(new MockFilterConfig(context));
|
||||
|
||||
final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
final String URL = CAS_SERVICE_URL + "?param=valueToIgnore";
|
||||
request.setRequestURI(URL);
|
||||
|
||||
final MockHttpSession session = new MockHttpSession();
|
||||
request.setSession(session);
|
||||
|
||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
final FilterChain filterChain = new FilterChain() {
|
||||
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
|
||||
}
|
||||
};
|
||||
|
||||
f.doFilter(request, response, filterChain);
|
||||
System.out.println(response.getRedirectedUrl());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue