2626import org .apache .commons .logging .LogFactory ;
2727
2828import org .springframework .core .log .LogMessage ;
29+ import org .springframework .http .server .PathContainer ;
2930import org .springframework .messaging .Message ;
3031import org .springframework .messaging .simp .SimpMessageType ;
3132import org .springframework .security .authorization .AuthenticatedAuthorizationManager ;
3233import org .springframework .security .authorization .AuthorityAuthorizationManager ;
3334import org .springframework .security .authorization .AuthorizationDecision ;
3435import org .springframework .security .authorization .AuthorizationManager ;
3536import org .springframework .security .core .Authentication ;
36- import org .springframework .security .messaging .util .matcher .DestinationPathPatternMessageMatcher ;
3737import org .springframework .security .messaging .util .matcher .MessageMatcher ;
38+ import org .springframework .security .messaging .util .matcher .PathPatternMessageMatcher ;
3839import org .springframework .security .messaging .util .matcher .SimpDestinationMessageMatcher ;
3940import org .springframework .security .messaging .util .matcher .SimpMessageTypeMatcher ;
4041import org .springframework .util .AntPathMatcher ;
4142import org .springframework .util .Assert ;
4243import org .springframework .util .PathMatcher ;
4344import org .springframework .util .function .SingletonSupplier ;
45+ import org .springframework .web .util .pattern .PathPatternParser ;
4446
4547public final class MessageMatcherDelegatingAuthorizationManager implements AuthorizationManager <Message <?>> {
4648
@@ -136,7 +138,7 @@ public Builder.Constraint anyMessage() {
136138 * @return the Expression to associate
137139 */
138140 public Builder .Constraint nullDestMatcher () {
139- return matchers (DestinationPathPatternMessageMatcher .NULL_DESTINATION_MATCHER );
141+ return matchers (PathPatternMessageMatcher .NULL_DESTINATION_MATCHER );
140142 }
141143
142144 /**
@@ -172,9 +174,9 @@ public Builder.Constraint simpDestMatchers(String... patterns) {
172174 * destinations match the provided {@code patterns}.
173175 * <p>
174176 * The matching of each pattern is performed by a
175- * {@link DestinationPathPatternMessageMatcher } instance that matches
176- * irrespectively of {@link SimpMessageType}. If no destination is found on the
177- * {@code Message}, then each {@code Matcher} returns false.
177+ * {@link PathPatternMessageMatcher } instance that matches irrespectively of
178+ * {@link SimpMessageType}. If no destination is found on the {@code Message},
179+ * then each {@code Matcher} returns false.
178180 * </p>
179181 * @param patterns the destination path patterns to which the security
180182 * {@code Constraint} will be applicable
@@ -204,10 +206,9 @@ public Builder.Constraint simpMessageDestMatchers(String... patterns) {
204206 * {@code patterns}.
205207 * <p>
206208 * The matching of each pattern is performed by a
207- * {@link DestinationPathPatternMessageMatcher }. If no destination is found on the
209+ * {@link PathPatternMessageMatcher }. If no destination is found on the
208210 * {@code Message}, then each {@code Matcher} returns false.
209- * @param patterns the patterns to create
210- * {@link DestinationPathPatternMessageMatcher} from.
211+ * @param patterns the patterns to create {@link PathPatternMessageMatcher} from.
211212 * @since 6.5
212213 */
213214 public Builder .Constraint simpTypeMessageDestinationPatterns (String ... patterns ) {
@@ -234,10 +235,9 @@ public Builder.Constraint simpSubscribeDestMatchers(String... patterns) {
234235 * provided {@code patterns}.
235236 * <p>
236237 * The matching of each pattern is performed by a
237- * {@link DestinationPathPatternMessageMatcher }. If no destination is found on the
238+ * {@link PathPatternMessageMatcher }. If no destination is found on the
238239 * {@code Message}, then each {@code Matcher} returns false.
239- * @param patterns the patterns to create
240- * {@link DestinationPathPatternMessageMatcher} from.
240+ * @param patterns the patterns to create {@link PathPatternMessageMatcher} from.
241241 * @since 6.5
242242 */
243243 public Builder .Constraint simpTypeSubscribeDestinationPatterns (String ... patterns ) {
@@ -272,13 +272,12 @@ private Builder.Constraint simpDestMatchers(SimpMessageType type, String... patt
272272 * {@code patterns}.
273273 * <p>
274274 * The matching of each pattern is performed by a
275- * {@link DestinationPathPatternMessageMatcher }. If no destination is found on the
275+ * {@link PathPatternMessageMatcher }. If no destination is found on the
276276 * {@code Message}, then each {@code Matcher} returns false.
277277 * </p>
278278 * @param type the {@link SimpMessageType} to match on. If null, the
279279 * {@link SimpMessageType} is not considered for matching.
280- * @param patterns the patterns to create
281- * {@link DestinationPathPatternMessageMatcher} from.
280+ * @param patterns the patterns to create {@link PathPatternMessageMatcher} from.
282281 * @return the {@link Builder.Constraint} that is associated to the
283282 * {@link MessageMatcher}s
284283 * @since 6.5
@@ -515,19 +514,21 @@ Map<String, String> extractPathVariables(Message<?> message) {
515514
516515 private static final class LazySimpDestinationPatternMessageMatcher implements MessageMatcher <Object > {
517516
518- private final Supplier <DestinationPathPatternMessageMatcher > delegate ;
517+ private final Supplier <PathPatternMessageMatcher > delegate ;
519518
520519 private LazySimpDestinationPatternMessageMatcher (String pattern , SimpMessageType type ,
521520 boolean useHttpPathSeparator ) {
522521 this .delegate = SingletonSupplier .of (() -> {
523- DestinationPathPatternMessageMatcher .Builder builder = (useHttpPathSeparator )
524- ? DestinationPathPatternMessageMatcher .withDefaults ()
525- : DestinationPathPatternMessageMatcher .messageRoute ();
522+ PathPatternParser dotSeparatedPathParser = new PathPatternParser ();
523+ dotSeparatedPathParser .setPathOptions (PathContainer .Options .MESSAGE_ROUTE );
524+ PathPatternMessageMatcher .Builder builder = (useHttpPathSeparator )
525+ ? PathPatternMessageMatcher .withDefaults ()
526+ : PathPatternMessageMatcher .withPathPatternParser (dotSeparatedPathParser );
526527 if (type == null ) {
527528 return builder .matcher (pattern );
528529 }
529530 if (SimpMessageType .MESSAGE == type || SimpMessageType .SUBSCRIBE == type ) {
530- return builder .messageType ( type ). matcher (pattern );
531+ return builder .matcher (pattern , type );
531532 }
532533 throw new IllegalStateException (type + " is not supported since it does not have a destination" );
533534 });
@@ -539,7 +540,8 @@ public boolean matches(Message<?> message) {
539540 }
540541
541542 Map <String , String > extractPathVariables (Message <?> message ) {
542- return this .delegate .get ().extractPathVariables (message );
543+ MatchResult matchResult = this .delegate .get ().matcher (message );
544+ return matchResult .getVariables ();
543545 }
544546
545547 }
0 commit comments