Propagate exceptions in security matchers

Update `ApplicationContextRequestMatcher` and
`ApplicationContextServerWebExchangeMatcher` to use a supplier for
the context, rather than the context itself.

This allow exceptions to be propagated to subclasses which may choose
to deal with them.

See gh-12238
This commit is contained in:
Phillip Webb
2018-02-27 13:50:01 -08:00
parent 802cd856aa
commit d66496787d
8 changed files with 83 additions and 82 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.security.servlet;
import java.util.function.Supplier;
import javax.servlet.http.HttpServletRequest;
import org.springframework.boot.autoconfigure.h2.H2ConsoleProperties;
@@ -69,14 +71,14 @@ public final class PathRequest {
}
@Override
protected void initialized(H2ConsoleProperties h2ConsoleProperties) {
protected void initialized(Supplier<H2ConsoleProperties> h2ConsoleProperties) {
this.delegate = new AntPathRequestMatcher(
h2ConsoleProperties.getPath() + "/**");
h2ConsoleProperties.get().getPath() + "/**");
}
@Override
protected boolean matches(HttpServletRequest request,
H2ConsoleProperties context) {
Supplier<H2ConsoleProperties> context) {
return this.delegate.matches(request);
}

View File

@@ -20,6 +20,7 @@ import java.util.EnumSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -133,8 +134,9 @@ public final class StaticResourceRequest {
}
@Override
protected void initialized(ServerProperties serverProperties) {
this.delegate = new OrRequestMatcher(getDelegateMatchers(serverProperties));
protected void initialized(Supplier<ServerProperties> serverProperties) {
this.delegate = new OrRequestMatcher(
getDelegateMatchers(serverProperties.get()));
}
private List<RequestMatcher> getDelegateMatchers(
@@ -149,7 +151,8 @@ public final class StaticResourceRequest {
}
@Override
protected boolean matches(HttpServletRequest request, ServerProperties context) {
protected boolean matches(HttpServletRequest request,
Supplier<ServerProperties> context) {
return this.delegate.matches(request);
}