1717package org .springframework .security .web .access ;
1818
1919import java .io .IOException ;
20+ import java .util .ArrayList ;
2021import java .util .Collection ;
2122import java .util .LinkedHashMap ;
2223import java .util .List ;
4041import org .springframework .security .web .util .ThrowableAnalyzer ;
4142import org .springframework .security .web .util .matcher .AnyRequestMatcher ;
4243import org .springframework .security .web .util .matcher .RequestMatcher ;
44+ import org .springframework .security .web .util .matcher .RequestMatcherEntry ;
4345
4446public final class DelegatingMissingAuthorityAccessDeniedHandler implements AccessDeniedHandler {
4547
@@ -114,7 +116,7 @@ public static Builder builder() {
114116
115117 public static final class Builder {
116118
117- private final Map <String , Map < RequestMatcher , AuthenticationEntryPoint >> entryPointByRequestMatcherByAuthority = new LinkedHashMap <>();
119+ private final Map <String , List < RequestMatcherEntry < AuthenticationEntryPoint > >> entryPointByRequestMatcherByAuthority = new LinkedHashMap <>();
118120
119121 private Builder () {
120122
@@ -123,9 +125,9 @@ private Builder() {
123125 Builder entryPointFor (RequestMatcher requestMatcher , AuthenticationEntryPoint entryPoint ,
124126 String ... authorities ) {
125127 for (String authority : authorities ) {
126- Map < RequestMatcher , AuthenticationEntryPoint > requestMatcherByAuthority = this .entryPointByRequestMatcherByAuthority
127- .computeIfAbsent (authority , (k ) -> new LinkedHashMap <>());
128- requestMatcherByAuthority . put ( requestMatcher , entryPoint );
128+ List < RequestMatcherEntry < AuthenticationEntryPoint >> entryPointByRequestMatcher = this .entryPointByRequestMatcherByAuthority
129+ .computeIfAbsent (authority , (k ) -> new ArrayList <>());
130+ entryPointByRequestMatcher . add ( new RequestMatcherEntry <>( requestMatcher , entryPoint ) );
129131 }
130132 return this ;
131133 }
@@ -137,16 +139,15 @@ public EntryPoint authorities(String... authorities) {
137139 public DelegatingMissingAuthorityAccessDeniedHandler build () {
138140 Map <String , AuthenticationEntryPoint > entryPointByAuthority = new LinkedHashMap <>();
139141 for (String authority : this .entryPointByRequestMatcherByAuthority .keySet ()) {
140- Map < RequestMatcher , AuthenticationEntryPoint > entryPointByRequestMatcher = this .entryPointByRequestMatcherByAuthority
142+ List < RequestMatcherEntry < AuthenticationEntryPoint > > entryPointByRequestMatcher = this .entryPointByRequestMatcherByAuthority
141143 .get (authority );
142- AuthenticationEntryPoint defaultEntryPoint = entryPointByRequestMatcher .values ().iterator ().next ();
144+ AuthenticationEntryPoint defaultEntryPoint = entryPointByRequestMatcher .iterator ().next ().getEntry ();
143145 if (entryPointByRequestMatcher .size () == 1 ) {
144146 entryPointByAuthority .put (authority , defaultEntryPoint );
145147 }
146148 else {
147149 DelegatingAuthenticationEntryPoint entryPoint = new DelegatingAuthenticationEntryPoint (
148- new LinkedHashMap <>(entryPointByRequestMatcher ));
149- entryPoint .setDefaultEntryPoint (defaultEntryPoint );
150+ defaultEntryPoint , entryPointByRequestMatcher );
150151 entryPointByAuthority .put (authority , entryPoint );
151152 }
152153 }
0 commit comments