Class SpringAuthorizationEventPublisher
java.lang.Object
org.springframework.security.authorization.SpringAuthorizationEventPublisher
- All Implemented Interfaces:
AuthorizationEventPublisher
public final class SpringAuthorizationEventPublisher
extends Object
implements AuthorizationEventPublisher
An implementation of
AuthorizationEventPublisher that uses Spring's event
publishing support.
Because AuthorizationGrantedEvents typically require additional business logic
to decide whether to publish, this implementation only publishes
AuthorizationDeniedEvents.- Since:
- 5.7
-
Constructor Summary
ConstructorsConstructorDescriptionSpringAuthorizationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher) Construct this publisher using Spring'sApplicationEventPublisher -
Method Summary
Modifier and TypeMethodDescription<T> voidpublishAuthorizationEvent(Supplier<Authentication> authentication, T object, @Nullable AuthorizationResult result) Publish the given details in the form of an event, typicallyAuthorizationGrantedEventorAuthorizationDeniedEvent.voidsetShouldPublishResult(Predicate<AuthorizationResult> shouldPublishResult) Use this predicate to test whether to publish an event.
-
Constructor Details
-
SpringAuthorizationEventPublisher
public SpringAuthorizationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher) Construct this publisher using Spring'sApplicationEventPublisher- Parameters:
eventPublisher-
-
-
Method Details
-
publishAuthorizationEvent
public <T> void publishAuthorizationEvent(Supplier<Authentication> authentication, T object, @Nullable AuthorizationResult result) Publish the given details in the form of an event, typicallyAuthorizationGrantedEventorAuthorizationDeniedEvent. Note that success events can be very noisy if enabled by default. Because of this implementations may choose to drop success events by default.- Specified by:
publishAuthorizationEventin interfaceAuthorizationEventPublisher- Type Parameters:
T- the secured object's type- Parameters:
authentication- aSupplierfor the current userobject- the secured objectresult-AuthorizationResultthe result about whether the user may access the secured object
-
setShouldPublishResult
Use this predicate to test whether to publish an event.Since you cannot publish a
nullevent, checking for null is already performed before this test is run- Parameters:
shouldPublishResult- the test to perform on non-nullevents- Since:
- 7.0
-