Skip to content
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

MessageMatcherDelegatingAuthorizationManager not extracting path variables for authorization context #12540

Closed
mstawick opened this issue Jan 13, 2023 · 1 comment
Assignees
Labels
in: messaging An issue in spring-security-messaging type: bug A general bug
Milestone

Comments

@mstawick
Copy link

Describe the bug
In authorizationContext of MessageMatcherDelegatingAuthorizationManager path variables are only extracted if the matcher is of type SimpDestinationMessageMatcher:

private MessageAuthorizationContext<?> authorizationContext(MessageMatcher<?> matcher, Message<?> message) {
        if (!matcher.matches((Message) message)) {
            return null;
        }
        if (matcher instanceof SimpDestinationMessageMatcher) {
            SimpDestinationMessageMatcher simp = (SimpDestinationMessageMatcher) matcher;
            return new MessageAuthorizationContext<>(message, simp.extractPathVariables(message));
        }     

        return new MessageAuthorizationContext<>(message);
    }

However, the matcher can be a SupplierMessageMatcher, with it's delegate being SimpDestinationMessageMatcher. In this case the variables are not extracted. As a quick fix, I've changed it to:

    private MessageAuthorizationContext<?> authorizationContext(MessageMatcher<?> matcher, Message<?> message) {
        if (!matcher.matches((Message) message)) {
            return null;
        }
        if (matcher instanceof SimpDestinationMessageMatcher) {
            SimpDestinationMessageMatcher simp = (SimpDestinationMessageMatcher) matcher;
            return new MessageAuthorizationContext<>(message, simp.extractPathVariables(message));
        }
        else if (matcher instanceof Builder.SupplierMessageMatcher && ((Builder.SupplierMessageMatcher) matcher).delegate instanceof SimpDestinationMessageMatcher) {
            SimpDestinationMessageMatcher simp = (SimpDestinationMessageMatcher) ((Builder.SupplierMessageMatcher) matcher).delegate;
            return new MessageAuthorizationContext<>(message, simp.extractPathVariables(message));
        }

        return new MessageAuthorizationContext<>(message);
    }

Though I'm not sure if there is another, existing way of handling this.

This popped up when I was migrating to v6, and switched to using:

    @Bean
    fun configureInbound(reg: MessageMatcherDelegatingAuthorizationManager.Builder): AuthorizationManager<Message<*>> {
        ...
    }

for configurting ws security, and migrating rules like:

            reg.simpSubscribeDestMatchers("/topic/path/{variable}/something")
                    .access("@bean.canihazcheezburger(#variable)")

to the new syntax using AuthorizationManager.

@mstawick mstawick added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Jan 13, 2023
@sjohnr sjohnr added the in: messaging An issue in spring-security-messaging label Jan 13, 2023
@jzheaux jzheaux removed the status: waiting-for-triage An issue we've not yet triaged label Jan 17, 2023
@jzheaux jzheaux added this to the 6.0.2 milestone Jan 17, 2023
@jzheaux jzheaux moved this to Planning in Spring Security Team Jan 17, 2023
@marcusdacoregio marcusdacoregio modified the milestones: 6.0.2, 6.0.3 Feb 17, 2023
@jzheaux jzheaux removed the status in Spring Security Team Mar 21, 2023
jzheaux added a commit that referenced this issue Mar 23, 2023
@jzheaux
Copy link
Contributor

jzheaux commented Mar 23, 2023

Thanks for reporting this, @mstawick. It's been scheduled for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging An issue in spring-security-messaging type: bug A general bug
Projects
Status: Done
Development

No branches or pull requests

4 participants