Rename DelegatingAuthorizationManager

Closes gh-9692
This commit is contained in:
Josh Cummings 2021-04-28 09:27:04 -06:00
parent 17cfc6ade3
commit df6ebc7051
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
2 changed files with 17 additions and 15 deletions

View File

@ -40,13 +40,13 @@ import org.springframework.util.Assert;
* @author Evgeniy Cheban * @author Evgeniy Cheban
* @since 5.5 * @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 Log logger = LogFactory.getLog(getClass());
private final Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings; private final Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings;
private DelegatingAuthorizationManager( private RequestMatcherDelegatingAuthorizationManager(
Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings) { Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings) {
Assert.notEmpty(mappings, "mappings cannot be empty"); Assert.notEmpty(mappings, "mappings cannot be empty");
this.mappings = mappings; 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 * @return the new {@link Builder} instance
*/ */
public static Builder builder() { 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 { public static final class Builder {
@ -113,11 +113,11 @@ public final class DelegatingAuthorizationManager implements AuthorizationManage
} }
/** /**
* Creates a {@link DelegatingAuthorizationManager} instance. * Creates a {@link RequestMatcherDelegatingAuthorizationManager} instance.
* @return the {@link DelegatingAuthorizationManager} instance * @return the {@link RequestMatcherDelegatingAuthorizationManager} instance
*/ */
public DelegatingAuthorizationManager build() { public RequestMatcherDelegatingAuthorizationManager build() {
return new DelegatingAuthorizationManager(this.mappings); return new RequestMatcherDelegatingAuthorizationManager(this.mappings);
} }
} }

View File

@ -30,36 +30,38 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/** /**
* Tests for {@link DelegatingAuthorizationManager}. * Tests for {@link RequestMatcherDelegatingAuthorizationManager}.
* *
* @author Evgeniy Cheban * @author Evgeniy Cheban
*/ */
public class DelegatingAuthorizationManagerTests { public class RequestMatcherDelegatingAuthorizationManagerTests {
@Test @Test
public void buildWhenMappingsEmptyThenException() { public void buildWhenMappingsEmptyThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> DelegatingAuthorizationManager.builder().build()) assertThatIllegalArgumentException()
.isThrownBy(() -> RequestMatcherDelegatingAuthorizationManager.builder().build())
.withMessage("mappings cannot be empty"); .withMessage("mappings cannot be empty");
} }
@Test @Test
public void addWhenMatcherNullThenException() { public void addWhenMatcherNullThenException() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> DelegatingAuthorizationManager.builder() .isThrownBy(() -> RequestMatcherDelegatingAuthorizationManager.builder()
.add(null, (a, o) -> new AuthorizationDecision(true)).build()) .add(null, (a, o) -> new AuthorizationDecision(true)).build())
.withMessage("matcher cannot be null"); .withMessage("matcher cannot be null");
} }
@Test @Test
public void addWhenManagerNullThenException() { public void addWhenManagerNullThenException() {
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException()
() -> DelegatingAuthorizationManager.builder().add(new MvcRequestMatcher(null, "/grant"), null).build()) .isThrownBy(() -> RequestMatcherDelegatingAuthorizationManager.builder()
.add(new MvcRequestMatcher(null, "/grant"), null).build())
.withMessage("manager cannot be null"); .withMessage("manager cannot be null");
} }
@Test @Test
public void checkWhenMultipleMappingsConfiguredThenDelegatesMatchingManager() { 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, "/grant"), (a, o) -> new AuthorizationDecision(true))
.add(new MvcRequestMatcher(null, "/deny"), (a, o) -> new AuthorizationDecision(false)) .add(new MvcRequestMatcher(null, "/deny"), (a, o) -> new AuthorizationDecision(false))
.add(new MvcRequestMatcher(null, "/neutral"), (a, o) -> null).build(); .add(new MvcRequestMatcher(null, "/neutral"), (a, o) -> null).build();