17
17
package org .springframework .security .web .access ;
18
18
19
19
import java .util .Collections ;
20
+ import java .util .HashMap ;
20
21
import java .util .List ;
22
+ import java .util .Map ;
21
23
22
24
import jakarta .servlet .ServletContext ;
23
25
import jakarta .servlet .http .HttpServletRequest ;
26
+ import jakarta .servlet .http .HttpServletRequestWrapper ;
24
27
25
28
import org .springframework .security .core .Authentication ;
26
29
import org .springframework .security .web .FilterInvocation ;
27
30
import org .springframework .security .web .util .matcher .RequestMatcherEntry ;
28
31
import org .springframework .util .Assert ;
29
32
import org .springframework .web .context .ServletContextAware ;
33
+ import org .springframework .web .util .ServletRequestPathUtils ;
30
34
31
35
/**
32
36
* A {@link WebInvocationPrivilegeEvaluator} which delegates to a list of
@@ -116,8 +120,10 @@ public boolean isAllowed(String contextPath, String uri, String method, Authenti
116
120
117
121
private List <WebInvocationPrivilegeEvaluator > getDelegate (String contextPath , String uri , String method ) {
118
122
FilterInvocation filterInvocation = new FilterInvocation (contextPath , uri , method , this .servletContext );
123
+ HttpServletRequest request = new AttributesSupportingHttpServletRequest (filterInvocation .getHttpRequest ());
124
+ ServletRequestPathUtils .parseAndCache (request );
119
125
for (RequestMatcherEntry <List <WebInvocationPrivilegeEvaluator >> delegate : this .delegates ) {
120
- if (delegate .getRequestMatcher ().matches (filterInvocation . getHttpRequest () )) {
126
+ if (delegate .getRequestMatcher ().matches (request )) {
121
127
return delegate .getEntry ();
122
128
}
123
129
}
@@ -129,4 +135,29 @@ public void setServletContext(ServletContext servletContext) {
129
135
this .servletContext = servletContext ;
130
136
}
131
137
138
+ private static final class AttributesSupportingHttpServletRequest extends HttpServletRequestWrapper {
139
+
140
+ private final Map <String , Object > attributes = new HashMap <>();
141
+
142
+ AttributesSupportingHttpServletRequest (HttpServletRequest request ) {
143
+ super (request );
144
+ }
145
+
146
+ @ Override
147
+ public Object getAttribute (String name ) {
148
+ return this .attributes .get (name );
149
+ }
150
+
151
+ @ Override
152
+ public void setAttribute (String name , Object value ) {
153
+ this .attributes .put (name , value );
154
+ }
155
+
156
+ @ Override
157
+ public void removeAttribute (String name ) {
158
+ this .attributes .remove (name );
159
+ }
160
+
161
+ }
162
+
132
163
}
0 commit comments