Class SecurityContextPropagationChannelInterceptor
java.lang.Object
org.springframework.security.messaging.context.SecurityContextPropagationChannelInterceptor
- All Implemented Interfaces:
- org.springframework.messaging.support.ChannelInterceptor,- org.springframework.messaging.support.ExecutorChannelInterceptor
public final class SecurityContextPropagationChannelInterceptor
extends Object
implements org.springframework.messaging.support.ExecutorChannelInterceptor
An 
ExecutorChannelInterceptor that takes an Authentication from the
 current SecurityContext (if any) in the
 preSend(Message, MessageChannel) callback and stores it into an
 authenticationHeaderName message header. Then sets the context from this
 header in the beforeHandle(Message, MessageChannel, MessageHandler) and
 postReceive(Message, MessageChannel) both of which typically happen on a
 different thread.
 
 Note: cannot be used in combination with a SecurityContextChannelInterceptor on
 the same channel since both these interceptors modify a security context on a handling
 and receiving operations.
- Since:
- 6.2
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new instance using the header of the nameSimpMessageHeaderAccessor.USER_HEADER.SecurityContextPropagationChannelInterceptor(String authenticationHeaderName) Create a new instance that uses the specified header to populate theAuthentication.
- 
Method SummaryModifier and TypeMethodDescriptionvoidafterMessageHandled(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler, @Nullable Exception ex) org.springframework.messaging.Message<?>beforeHandle(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler) org.springframework.messaging.Message<?>postReceive(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) org.springframework.messaging.Message<?>preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) voidsetAnonymousAuthentication(Authentication authentication) Configure an Authentication used for anonymous authentication.voidMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.messaging.support.ChannelInterceptorafterReceiveCompletion, afterSendCompletion, postSend, preReceive
- 
Constructor Details- 
SecurityContextPropagationChannelInterceptorpublic SecurityContextPropagationChannelInterceptor()Create a new instance using the header of the nameSimpMessageHeaderAccessor.USER_HEADER.
- 
SecurityContextPropagationChannelInterceptorCreate a new instance that uses the specified header to populate theAuthentication.- Parameters:
- authenticationHeaderName- the header name to populate the- Authentication. Cannot be null.
 
 
- 
- 
Method Details- 
setSecurityContextHolderStrategy
- 
setAnonymousAuthenticationConfigure an Authentication used for anonymous authentication. Default is:new AnonymousAuthenticationToken("key", "anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));- Parameters:
- authentication- the Authentication used for anonymous authentication. Cannot be null.
 
- 
preSendpublic org.springframework.messaging.Message<?> preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) - Specified by:
- preSendin interface- org.springframework.messaging.support.ChannelInterceptor
 
- 
beforeHandlepublic org.springframework.messaging.Message<?> beforeHandle(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler) - Specified by:
- beforeHandlein interface- org.springframework.messaging.support.ExecutorChannelInterceptor
 
- 
postReceivepublic org.springframework.messaging.Message<?> postReceive(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) - Specified by:
- postReceivein interface- org.springframework.messaging.support.ChannelInterceptor
 
- 
afterMessageHandledpublic void afterMessageHandled(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler, @Nullable Exception ex) - Specified by:
- afterMessageHandledin interface- org.springframework.messaging.support.ExecutorChannelInterceptor
 
 
-