Removal of some unused internal methods, plus additional tests for some areas lacking coverage.
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.security.web.util;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
@@ -28,10 +27,10 @@ import org.springframework.security.web.authentication.DelegatingAuthenticationE
|
||||
/**
|
||||
* A RequestMatcher implementation which uses a SpEL expression
|
||||
*
|
||||
* <p>With the default EvalutationContext ({@link ELRequestMatcherContext}) you can use
|
||||
* <p>With the default EvaluationContext ({@link ELRequestMatcherContext}) you can use
|
||||
* <code>hasIpAdress()</code> and <code>hasHeader()</code></p>
|
||||
*
|
||||
* <p>See {@link DelegatingAuthenticationEntryPoint} for a example configuration.</p>
|
||||
* <p>See {@link DelegatingAuthenticationEntryPoint} for an example configuration.</p>
|
||||
*
|
||||
*
|
||||
* @author Mike Wiesner
|
||||
@@ -48,7 +47,7 @@ public class ELRequestMatcher implements RequestMatcher {
|
||||
|
||||
public boolean matches(HttpServletRequest request) {
|
||||
EvaluationContext context = createELContext(request);
|
||||
return evaluateAsBoolean(expression, context);
|
||||
return expression.getValue(context, Boolean.class).booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,11 +59,4 @@ public class ELRequestMatcher implements RequestMatcher {
|
||||
return new StandardEvaluationContext(new ELRequestMatcherContext(request));
|
||||
}
|
||||
|
||||
private boolean evaluateAsBoolean(Expression expr, EvaluationContext ctx) {
|
||||
try {
|
||||
return ((Boolean) expr.getValue(ctx, Boolean.class)).booleanValue();
|
||||
} catch (EvaluationException e) {
|
||||
throw new IllegalArgumentException("Failed to evaluate expression '" + expr.getExpressionString() + "'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class ThrowableAnalyzer {
|
||||
for (Map.Entry<Class<? extends Throwable>, ThrowableCauseExtractor> entry : extractorMap.entrySet()) {
|
||||
Class<? extends Throwable> throwableType = entry.getKey();
|
||||
if (throwableType.isInstance(throwable)) {
|
||||
ThrowableCauseExtractor extractor = (ThrowableCauseExtractor) entry.getValue();
|
||||
ThrowableCauseExtractor extractor = entry.getValue();
|
||||
return extractor.extractCause(throwable);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -94,8 +94,9 @@ public class ExceptionTranslationFilterTests {
|
||||
|
||||
// Test
|
||||
ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint());
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint);
|
||||
filter.setAuthenticationTrustResolver(new AuthenticationTrustResolverImpl());
|
||||
assertNotNull(filter.getAuthenticationTrustResolver());
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
filter.doFilter(request, response, fc);
|
||||
@@ -123,7 +124,7 @@ public class ExceptionTranslationFilterTests {
|
||||
|
||||
// Test
|
||||
ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint());
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint);
|
||||
filter.setAccessDeniedHandler(adh);
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -149,7 +150,7 @@ public class ExceptionTranslationFilterTests {
|
||||
|
||||
// Test
|
||||
ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint());
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint);
|
||||
filter.afterPropertiesSet();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
filter.doFilter(request, response, fc);
|
||||
@@ -175,7 +176,7 @@ public class ExceptionTranslationFilterTests {
|
||||
|
||||
// Test
|
||||
ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint());
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint);
|
||||
HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
|
||||
requestCache.setPortResolver(new MockPortResolver(8080, 8443));
|
||||
filter.setRequestCache(requestCache);
|
||||
@@ -197,7 +198,7 @@ public class ExceptionTranslationFilterTests {
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void startupDetectsMissingRequestCache() throws Exception {
|
||||
ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint());
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint);
|
||||
|
||||
filter.setRequestCache(null);
|
||||
}
|
||||
@@ -210,7 +211,8 @@ public class ExceptionTranslationFilterTests {
|
||||
|
||||
// Test
|
||||
ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint());
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint);
|
||||
assertSame(mockEntryPoint, filter.getAuthenticationEntryPoint());
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
filter.doFilter(request, response, mock(FilterChain.class));
|
||||
@@ -220,7 +222,7 @@ public class ExceptionTranslationFilterTests {
|
||||
public void thrownIOExceptionServletExceptionAndRuntimeExceptionsAreRethrown() throws Exception {
|
||||
ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
|
||||
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint());
|
||||
filter.setAuthenticationEntryPoint(mockEntryPoint);
|
||||
filter.afterPropertiesSet();
|
||||
Exception[] exceptions = {new IOException(), new ServletException(), new RuntimeException()};
|
||||
for (Exception e : exceptions) {
|
||||
@@ -237,12 +239,10 @@ public class ExceptionTranslationFilterTests {
|
||||
}
|
||||
}
|
||||
|
||||
private AuthenticationEntryPoint mockEntryPoint() {
|
||||
return new AuthenticationEntryPoint() {
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response,
|
||||
private final AuthenticationEntryPoint mockEntryPoint = new AuthenticationEntryPoint() {
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response,
|
||||
AuthenticationException authException) throws IOException, ServletException {
|
||||
response.sendRedirect(request.getContextPath() + "/login.jsp");
|
||||
}
|
||||
};
|
||||
}
|
||||
response.sendRedirect(request.getContextPath() + "/login.jsp");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
||||
* @author Mike Wiesner
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public class ELRequestMatcherTest {
|
||||
public class ELRequestMatcherTests {
|
||||
|
||||
@Test
|
||||
public void testHasIpAddressTrue() throws Exception {
|
||||
Reference in New Issue
Block a user