Fix Authorization Granted Events sample - #19607
Open
skdas20 wants to merge 1 commit into
Open
Conversation
The sample under "Authorization Granted Events" did not compile. It called a no-arg SpringAuthorizationEventPublisher constructor, but the only constructor takes an ApplicationEventPublisher, and it called setShouldPublishEvent, which is named setShouldPublishResult. The Kotlin sample had three further problems: it destructured the lambda parameter as (result), it referenced an undefined "decision" rather than the parameter, and it used bare returns inside a lambda. The surrounding prose also promised something the class does not do. SpringAuthorizationEventPublisher documents itself as publishing only AuthorizationDeniedEvents, and publishAuthorizationEvent only ever constructs one, so a predicate returning true for a granted result publishes an AuthorizationDeniedEvent carrying a granted result rather than an AuthorizationGrantedEvent. Describe the predicate as selecting which denials are published. Closes spring-projectsgh-19584 Signed-off-by: skdas20 <skdas5405@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The sample under Authorization Granted Events does not compile, and the prose around it describes behaviour
SpringAuthorizationEventPublisherdoes not have.The sample. It calls a no-arg constructor, but the only one is
SpringAuthorizationEventPublisher(ApplicationEventPublisher), and it callssetShouldPublishEvent, which issetShouldPublishResult(Predicate<AuthorizationResult>). The Kotlin version additionally destructures the lambda parameter as(result), refers to an undefineddecisioninstead of the parameter, and uses barereturninside a lambda, none of which compile.The prose. It says the publisher "only publishes authorization grants where
ROLE_ADMINwas required", but the class javadoc states the opposite:and
publishAuthorizationEventbears that out — it only ever constructs anAuthorizationDeniedEvent;AuthorizationGrantedEventis imported solely for that javadoc reference. So a predicate returningtruefor a granted result publishes anAuthorizationDeniedEventcarrying a grantedAuthorizationResult, which is not what a reader following this section would expect.I have taken the implementation as correct and fixed the documentation to match it, describing the predicate as selecting which denials are published. The default is
(result) -> !result.isGranted(), so that reading seems consistent with the intended design.If the team would rather
SpringAuthorizationEventPublishergain the ability to publish granted events, then this section is describing a feature request instead and the fix belongs in the class rather than the docs — happy to redo it that way.Closes gh-19584