Skip to content

Add DestinationPathPatternMessageMatcher human reviewer #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GuusArts
Copy link
Owner

@GuusArts GuusArts commented Apr 9, 2025

Closes spring-projectsgh-16500

Summary by Sourcery

Add a new DestinationPathPatternMessageMatcher to improve WebSocket message destination matching with more flexible path pattern support

New Features:

  • Introduce DestinationPathPatternMessageMatcher to support more flexible path pattern matching for WebSocket message destinations
  • Add support for both slash-separated and dot-separated path separators in destination matching

Enhancements:

  • Deprecate existing SimpDestinationMessageMatcher in favor of new DestinationPathPatternMessageMatcher
  • Improve path variable extraction for message destinations
  • Add more flexible message type and destination matching

Tests:

  • Add comprehensive test coverage for the new DestinationPathPatternMessageMatcher
  • Update existing tests to use new destination path pattern matching methods

Copy link

sourcery-ai bot commented Apr 9, 2025

Reviewer's Guide by Sourcery

This pull request introduces DestinationPathPatternMessageMatcher to replace the deprecated SimpDestinationMessageMatcher. It also updates MessageMatcherDelegatingAuthorizationManager to use the new matcher and provides builder methods for configuring destination path patterns and path separators.

Class diagram for SimpDestinationMessageMatcher

classDiagram
    class SimpDestinationMessageMatcher {
        -PathMatcher pathMatcher
        -String pattern
        -SimpMessageType type
        +SimpDestinationMessageMatcher(String pattern, PathMatcher pathMatcher)
        +SimpDestinationMessageMatcher(String pattern, PathMatcher pathMatcher, SimpMessageType type)
        +matches(Message<?> message)
        +extractPathVariables(Message<?> message)
    }
Loading

File-Level Changes

Change Details Files
Introduces DestinationPathPatternMessageMatcher to match messages based on destination path patterns, offering more flexible matching capabilities.
  • Added DestinationPathPatternMessageMatcher class.
  • Added DestinationPathPatternMessageMatcherTests class.
  • Deprecated SimpDestinationMessageMatcher.
  • Added destinationPathPatterns method to MessageMatcherDelegatingAuthorizationManager.Builder to use the new matcher.
  • Added messageRouteSeparator method to MessageMatcherDelegatingAuthorizationManager.Builder to configure the path separator.
  • Updated tests to use the new DestinationPathPatternMessageMatcher.
messaging/src/main/java/org/springframework/security/messaging/access/intercept/MessageMatcherDelegatingAuthorizationManager.java
messaging/src/test/java/org/springframework/security/messaging/access/intercept/MessageMatcherDelegatingAuthorizationManagerTests.java
messaging/src/main/java/org/springframework/security/messaging/util/matcher/SimpDestinationMessageMatcher.java
messaging/src/main/java/org/springframework/security/messaging/util/matcher/DestinationPathPatternMessageMatcher.java
messaging/src/test/java/org/springframework/security/messaging/util/matcher/DestinationPathPatternMessageMatcherTests.java
Updates the MessageMatcherDelegatingAuthorizationManager to utilize the new DestinationPathPatternMessageMatcher and provides corresponding builder methods.
  • Replaced usages of SimpDestinationMessageMatcher with DestinationPathPatternMessageMatcher in MessageMatcherDelegatingAuthorizationManager.
  • Added destinationPathPatterns method to the builder to create constraints based on destination path patterns.
  • Deprecated simpDestMatchers and related methods in favor of destinationPathPatterns.
  • Introduced messageRouteSeparator method to configure the path separator used by the destination matcher.
  • Updated the authorizationContext method to handle DestinationPathPatternMessageMatcher and extract path variables.
  • Added a LazySimpDestinationPatternMessageMatcher to lazily initialize the DestinationPathPatternMessageMatcher.
messaging/src/main/java/org/springframework/security/messaging/access/intercept/MessageMatcherDelegatingAuthorizationManager.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@GuusArts GuusArts changed the title Add DestinationPathPatternMessageMatcher Add DestinationPathPatternMessageMatcher human reviewer Apr 9, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @GuusArts - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing the LazySimpDestinationMessageMatcher and LazySimpDestinationPatternMessageMatcher classes and inlining their logic.
  • It might be helpful to provide a usage example in the javadoc for destinationPathPatterns.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

* @since 6.5
*/
public Builder.Constraint destinationPathPatterns(String... patterns) {
return destinationPathPatterns(null, patterns);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider creating a helper method to encapsulate the common matcher-creation logic, reducing code duplication and improving maintainability by avoiding nearly identical code paths in different methods, such as in destinationPathPatterns.

Consider extracting the common matcher‐creation logic into a helper method rather than repeating nearly identical code paths in different methods. For example, you could create a private method that builds a matcher based on the provided pattern and type, and then have your builder methods call that helper. This would reduce duplication and ease maintenance.

Example Suggestion:

private MessageMatcher<Object> createDestinationMatcher(String pattern, SimpMessageType type, boolean useHttpPathSeparator) {
    if (MessageMatcherFactory.usesPathPatterns()) {
        // For new behavior using path patterns
        return new LazySimpDestinationPatternMessageMatcher(pattern, type, useHttpPathSeparator);
    }
    // Fallback to legacy matcher
    return new LazySimpDestinationMessageMatcher(pattern, type);
}

Then, in your builder methods (like destinationPathPatterns), replace the loop with:

private Builder.Constraint destinationPathPatterns(SimpMessageType type, String... patterns) {
    List<MessageMatcher<?>> matchers = new ArrayList<>(patterns.length);
    for (String pattern : patterns) {
        matchers.add(createDestinationMatcher(pattern, type, this.useHttpPathSeparator));
    }
    return new Builder.Constraint(matchers);
}

This consolidation preserves existing behavior while reducing conditional branching and duplicated code paths.

Copy link

sonarqubecloud bot commented Apr 9, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate usages of PathMatcher in Web Socket support
2 participants