Skip to content

Fix Authorization Granted Events sample - #19607

Open
skdas20 wants to merge 1 commit into
spring-projects:mainfrom
skdas20:gh-19584-fix-authorization-granted-events-docs
Open

Fix Authorization Granted Events sample#19607
skdas20 wants to merge 1 commit into
spring-projects:mainfrom
skdas20:gh-19584-fix-authorization-granted-events-docs

Conversation

@skdas20

@skdas20 skdas20 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

The sample under Authorization Granted Events does not compile, and the prose around it describes behaviour SpringAuthorizationEventPublisher does not have.

The sample. It calls a no-arg constructor, but the only one is SpringAuthorizationEventPublisher(ApplicationEventPublisher), and it calls setShouldPublishEvent, which is setShouldPublishResult(Predicate<AuthorizationResult>). The Kotlin version additionally destructures the lambda parameter as (result), refers to an undefined decision instead of the parameter, and uses bare return inside a lambda, none of which compile.

The prose. It says the publisher "only publishes authorization grants where ROLE_ADMIN was required", but the class javadoc states the opposite:

Because AuthorizationGrantedEvents typically require additional business logic to decide whether to publish, this implementation only publishes AuthorizationDeniedEvents.

and publishAuthorizationEvent bears that out — it only ever constructs an AuthorizationDeniedEvent; AuthorizationGrantedEvent is imported solely for that javadoc reference. So a predicate returning true for a granted result publishes an AuthorizationDeniedEvent carrying a granted AuthorizationResult, 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 SpringAuthorizationEventPublisher gain 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

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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authorization Granted Events sample cannot work as documented

2 participants