|
|
|
@ -16,8 +16,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.security.web.access.intercept; |
|
|
|
package org.springframework.security.web.access.intercept; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.List; |
|
|
|
import java.util.function.Consumer; |
|
|
|
import java.util.function.Consumer; |
|
|
|
import java.util.function.Supplier; |
|
|
|
import java.util.function.Supplier; |
|
|
|
|
|
|
|
|
|
|
|
@ -31,6 +31,7 @@ import org.springframework.security.authorization.AuthorizationManager; |
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.security.web.util.matcher.RequestMatcher; |
|
|
|
import org.springframework.security.web.util.matcher.RequestMatcher; |
|
|
|
import org.springframework.security.web.util.matcher.RequestMatcher.MatchResult; |
|
|
|
import org.springframework.security.web.util.matcher.RequestMatcher.MatchResult; |
|
|
|
|
|
|
|
import org.springframework.security.web.util.matcher.RequestMatcherEntry; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -45,10 +46,10 @@ public final class RequestMatcherDelegatingAuthorizationManager implements Autho |
|
|
|
|
|
|
|
|
|
|
|
private final Log logger = LogFactory.getLog(getClass()); |
|
|
|
private final Log logger = LogFactory.getLog(getClass()); |
|
|
|
|
|
|
|
|
|
|
|
private final Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings; |
|
|
|
private final List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings; |
|
|
|
|
|
|
|
|
|
|
|
private RequestMatcherDelegatingAuthorizationManager( |
|
|
|
private RequestMatcherDelegatingAuthorizationManager( |
|
|
|
Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings) { |
|
|
|
List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings) { |
|
|
|
Assert.notEmpty(mappings, "mappings cannot be empty"); |
|
|
|
Assert.notEmpty(mappings, "mappings cannot be empty"); |
|
|
|
this.mappings = mappings; |
|
|
|
this.mappings = mappings; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -67,13 +68,12 @@ public final class RequestMatcherDelegatingAuthorizationManager implements Autho |
|
|
|
if (this.logger.isTraceEnabled()) { |
|
|
|
if (this.logger.isTraceEnabled()) { |
|
|
|
this.logger.trace(LogMessage.format("Authorizing %s", request)); |
|
|
|
this.logger.trace(LogMessage.format("Authorizing %s", request)); |
|
|
|
} |
|
|
|
} |
|
|
|
for (Map.Entry<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mapping : this.mappings |
|
|
|
for (RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>> mapping : this.mappings) { |
|
|
|
.entrySet()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RequestMatcher matcher = mapping.getKey(); |
|
|
|
RequestMatcher matcher = mapping.getRequestMatcher(); |
|
|
|
MatchResult matchResult = matcher.matcher(request); |
|
|
|
MatchResult matchResult = matcher.matcher(request); |
|
|
|
if (matchResult.isMatch()) { |
|
|
|
if (matchResult.isMatch()) { |
|
|
|
AuthorizationManager<RequestAuthorizationContext> manager = mapping.getValue(); |
|
|
|
AuthorizationManager<RequestAuthorizationContext> manager = mapping.getEntry(); |
|
|
|
if (this.logger.isTraceEnabled()) { |
|
|
|
if (this.logger.isTraceEnabled()) { |
|
|
|
this.logger.trace(LogMessage.format("Checking authorization on %s using %s", request, manager)); |
|
|
|
this.logger.trace(LogMessage.format("Checking authorization on %s using %s", request, manager)); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -98,7 +98,7 @@ public final class RequestMatcherDelegatingAuthorizationManager implements Autho |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static final class Builder { |
|
|
|
public static final class Builder { |
|
|
|
|
|
|
|
|
|
|
|
private final Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>> mappings = new LinkedHashMap<>(); |
|
|
|
private final List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>> mappings = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Maps a {@link RequestMatcher} to an {@link AuthorizationManager}. |
|
|
|
* Maps a {@link RequestMatcher} to an {@link AuthorizationManager}. |
|
|
|
@ -109,7 +109,7 @@ public final class RequestMatcherDelegatingAuthorizationManager implements Autho |
|
|
|
public Builder add(RequestMatcher matcher, AuthorizationManager<RequestAuthorizationContext> manager) { |
|
|
|
public Builder add(RequestMatcher matcher, AuthorizationManager<RequestAuthorizationContext> manager) { |
|
|
|
Assert.notNull(matcher, "matcher cannot be null"); |
|
|
|
Assert.notNull(matcher, "matcher cannot be null"); |
|
|
|
Assert.notNull(manager, "manager cannot be null"); |
|
|
|
Assert.notNull(manager, "manager cannot be null"); |
|
|
|
this.mappings.put(matcher, manager); |
|
|
|
this.mappings.add(new RequestMatcherEntry<>(matcher, manager)); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -122,7 +122,7 @@ public final class RequestMatcherDelegatingAuthorizationManager implements Autho |
|
|
|
* @since 5.7 |
|
|
|
* @since 5.7 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Builder mappings( |
|
|
|
public Builder mappings( |
|
|
|
Consumer<Map<RequestMatcher, AuthorizationManager<RequestAuthorizationContext>>> mappingsConsumer) { |
|
|
|
Consumer<List<RequestMatcherEntry<AuthorizationManager<RequestAuthorizationContext>>>> mappingsConsumer) { |
|
|
|
Assert.notNull(mappingsConsumer, "mappingsConsumer cannot be null"); |
|
|
|
Assert.notNull(mappingsConsumer, "mappingsConsumer cannot be null"); |
|
|
|
mappingsConsumer.accept(this.mappings); |
|
|
|
mappingsConsumer.accept(this.mappings); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
|