CASC-219: added exact-matcher strategy

This commit is contained in:
Misagh Moayyed 2014-03-13 08:26:22 -07:00
parent 0a8fd79a44
commit d2b93a237f
3 changed files with 62 additions and 1 deletions

View File

@ -77,6 +77,7 @@ public class AuthenticationFilter extends AbstractCasFilter {
static {
PATTERN_MATCHER_TYPES.put("CONTAINS", ContainsPatternUrlPatternMatcherStrategy.class);
PATTERN_MATCHER_TYPES.put("REGEX", RegexUrlPatternMatcherStrategy.class);
PATTERN_MATCHER_TYPES.put("EXACT", ExactUrlPatternMatcherStrategy.class);
}
protected void initInternal(final FilterConfig filterConfig) throws ServletException {

View File

@ -0,0 +1,22 @@
package org.jasig.cas.client.authentication;
/**
* A pattern matcher that produces a successful match if the pattern
* specified matches the given url exactly and equally.
*
* @author Misagh Moayyed
* @since 3.3.1
*/
public class ExactUrlPatternMatcherStrategy implements UrlPatternMatcherStrategy {
private String pattern;
public boolean matches(final String url) {
return url.equals(this.pattern);
}
public void setPattern(final String pattern) {
this.pattern = pattern;
}
}

View File

@ -19,13 +19,17 @@
package org.jasig.cas.client.authentication;
import static org.junit.Assert.*;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLEncoder;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.validation.AssertionImpl;
import org.junit.After;
@ -245,7 +249,7 @@ public final class AuthenticationFilterTests {
}
@Test
public void testIgnorePatternsWithExactMatching() throws Exception {
public void testIgnorePatternsWithContainsMatching() throws Exception {
final AuthenticationFilter f = new AuthenticationFilter();
final MockServletContext context = new MockServletContext();
context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
@ -273,6 +277,40 @@ public final class AuthenticationFilterTests {
assertNull(response.getRedirectedUrl());
}
@Test
public void testIgnorePatternsWithExactMatching() throws Exception {
final AuthenticationFilter f = new AuthenticationFilter();
final MockServletContext context = new MockServletContext();
context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
final URL url = new URL(CAS_SERVICE_URL + "?param=valueToIgnore");
context.addInitParameter("ignorePattern", url.toExternalForm());
context.addInitParameter("ignoreUrlPatternType", "EXACT");
context.addInitParameter("service", CAS_SERVICE_URL);
f.init(new MockFilterConfig(context));
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme(url.getProtocol());
request.setServerName(url.getHost());
request.setServerPort(url.getPort());
request.setQueryString(url.getQuery());
request.setRequestURI(url.getPath());
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 testIgnorePatternsWithExactClassname() throws Exception {
final AuthenticationFilter f = new AuthenticationFilter();