|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2020 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2021 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,6 +16,7 @@
|
|
|
|
|
|
package org.springframework.security.config.annotation.web.configurers;
|
|
package org.springframework.security.config.annotation.web.configurers;
|
|
|
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
@@ -46,6 +47,9 @@ import org.springframework.util.Assert;
|
|
public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder<H>>
|
|
public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder<H>>
|
|
extends AbstractHttpConfigurer<AuthorizeHttpRequestsConfigurer<H>, H> {
|
|
extends AbstractHttpConfigurer<AuthorizeHttpRequestsConfigurer<H>, H> {
|
|
|
|
|
|
|
|
+ static final AuthorizationManager<RequestAuthorizationContext> permitAllAuthorizationManager = (a,
|
|
|
|
+ o) -> new AuthorizationDecision(true);
|
|
|
|
+
|
|
private final AuthorizationManagerRequestMatcherRegistry registry;
|
|
private final AuthorizationManagerRequestMatcherRegistry registry;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -81,6 +85,12 @@ public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder
|
|
return this.registry;
|
|
return this.registry;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ AuthorizationManagerRequestMatcherRegistry addFirst(RequestMatcher matcher,
|
|
|
|
+ AuthorizationManager<RequestAuthorizationContext> manager) {
|
|
|
|
+ this.registry.addFirst(matcher, manager);
|
|
|
|
+ return this.registry;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Registry for mapping a {@link RequestMatcher} to an {@link AuthorizationManager}.
|
|
* Registry for mapping a {@link RequestMatcher} to an {@link AuthorizationManager}.
|
|
*
|
|
*
|
|
@@ -106,6 +116,19 @@ public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder
|
|
this.mappingCount++;
|
|
this.mappingCount++;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void addFirst(RequestMatcher matcher, AuthorizationManager<RequestAuthorizationContext> manager) {
|
|
|
|
+ this.unmappedMatchers = null;
|
|
|
|
+ this.managerBuilder.mappings((m) -> {
|
|
|
|
+ LinkedHashMap<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> reorderedMap = new LinkedHashMap<>(
|
|
|
|
+ m.size() + 1);
|
|
|
|
+ reorderedMap.put(matcher, manager);
|
|
|
|
+ reorderedMap.putAll(m);
|
|
|
|
+ m.clear();
|
|
|
|
+ m.putAll(reorderedMap);
|
|
|
|
+ });
|
|
|
|
+ this.mappingCount++;
|
|
|
|
+ }
|
|
|
|
+
|
|
private AuthorizationManager<HttpServletRequest> createAuthorizationManager() {
|
|
private AuthorizationManager<HttpServletRequest> createAuthorizationManager() {
|
|
Assert.state(this.unmappedMatchers == null,
|
|
Assert.state(this.unmappedMatchers == null,
|
|
() -> "An incomplete mapping was found for " + this.unmappedMatchers
|
|
() -> "An incomplete mapping was found for " + this.unmappedMatchers
|
|
@@ -209,7 +232,7 @@ public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder
|
|
* customizations
|
|
* customizations
|
|
*/
|
|
*/
|
|
public AuthorizationManagerRequestMatcherRegistry permitAll() {
|
|
public AuthorizationManagerRequestMatcherRegistry permitAll() {
|
|
- return access((a, o) -> new AuthorizationDecision(true));
|
|
|
|
|
|
+ return access(permitAllAuthorizationManager);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|