parent
17cfc6ade3
commit
df6ebc7051
|
@ -40,13 +40,13 @@ import org.springframework.util.Assert;
|
|||
* @author Evgeniy Cheban
|
||||
* @since 5.5
|
||||
*/
|
||||
public final class DelegatingAuthorizationManager implements AuthorizationManager<HttpServletRequest> {
|
||||
public final class RequestMatcherDelegatingAuthorizationManager implements AuthorizationManager<HttpServletRequest> {
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings;
|
||||
|
||||
private DelegatingAuthorizationManager(
|
||||
private RequestMatcherDelegatingAuthorizationManager(
|
||||
Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings) {
|
||||
Assert.notEmpty(mappings, "mappings cannot be empty");
|
||||
this.mappings = mappings;
|
||||
|
@ -85,7 +85,7 @@ public final class DelegatingAuthorizationManager implements AuthorizationManage
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a builder for {@link DelegatingAuthorizationManager}.
|
||||
* Creates a builder for {@link RequestMatcherDelegatingAuthorizationManager}.
|
||||
* @return the new {@link Builder} instance
|
||||
*/
|
||||
public static Builder builder() {
|
||||
|
@ -93,7 +93,7 @@ public final class DelegatingAuthorizationManager implements AuthorizationManage
|
|||
}
|
||||
|
||||
/**
|
||||
* A builder for {@link DelegatingAuthorizationManager}.
|
||||
* A builder for {@link RequestMatcherDelegatingAuthorizationManager}.
|
||||
*/
|
||||
public static final class Builder {
|
||||
|
||||
|
@ -113,11 +113,11 @@ public final class DelegatingAuthorizationManager implements AuthorizationManage
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DelegatingAuthorizationManager} instance.
|
||||
* @return the {@link DelegatingAuthorizationManager} instance
|
||||
* Creates a {@link RequestMatcherDelegatingAuthorizationManager} instance.
|
||||
* @return the {@link RequestMatcherDelegatingAuthorizationManager} instance
|
||||
*/
|
||||
public DelegatingAuthorizationManager build() {
|
||||
return new DelegatingAuthorizationManager(this.mappings);
|
||||
public RequestMatcherDelegatingAuthorizationManager build() {
|
||||
return new RequestMatcherDelegatingAuthorizationManager(this.mappings);
|
||||
}
|
||||
|
||||
}
|
|
@ -30,36 +30,38 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingAuthorizationManager}.
|
||||
* Tests for {@link RequestMatcherDelegatingAuthorizationManager}.
|
||||
*
|
||||
* @author Evgeniy Cheban
|
||||
*/
|
||||
public class DelegatingAuthorizationManagerTests {
|
||||
public class RequestMatcherDelegatingAuthorizationManagerTests {
|
||||
|
||||
@Test
|
||||
public void buildWhenMappingsEmptyThenException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> DelegatingAuthorizationManager.builder().build())
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RequestMatcherDelegatingAuthorizationManager.builder().build())
|
||||
.withMessage("mappings cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addWhenMatcherNullThenException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> DelegatingAuthorizationManager.builder()
|
||||
.isThrownBy(() -> RequestMatcherDelegatingAuthorizationManager.builder()
|
||||
.add(null, (a, o) -> new AuthorizationDecision(true)).build())
|
||||
.withMessage("matcher cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addWhenManagerNullThenException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> DelegatingAuthorizationManager.builder().add(new MvcRequestMatcher(null, "/grant"), null).build())
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RequestMatcherDelegatingAuthorizationManager.builder()
|
||||
.add(new MvcRequestMatcher(null, "/grant"), null).build())
|
||||
.withMessage("manager cannot be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWhenMultipleMappingsConfiguredThenDelegatesMatchingManager() {
|
||||
DelegatingAuthorizationManager manager = DelegatingAuthorizationManager.builder()
|
||||
RequestMatcherDelegatingAuthorizationManager manager = RequestMatcherDelegatingAuthorizationManager.builder()
|
||||
.add(new MvcRequestMatcher(null, "/grant"), (a, o) -> new AuthorizationDecision(true))
|
||||
.add(new MvcRequestMatcher(null, "/deny"), (a, o) -> new AuthorizationDecision(false))
|
||||
.add(new MvcRequestMatcher(null, "/neutral"), (a, o) -> null).build();
|
Loading…
Reference in New Issue