Class SecurityContextChannelInterceptor

java.lang.Object
org.springframework.security.messaging.context.SecurityContextChannelInterceptor
All Implemented Interfaces:
org.springframework.messaging.support.ChannelInterceptor, org.springframework.messaging.support.ExecutorChannelInterceptor

public final class SecurityContextChannelInterceptor extends Object implements org.springframework.messaging.support.ExecutorChannelInterceptor, org.springframework.messaging.support.ChannelInterceptor

Creates a ExecutorChannelInterceptor that will obtain the Authentication from the specified Message.getHeaders().

Since:
4.0
  • Constructor Details

    • SecurityContextChannelInterceptor

      public SecurityContextChannelInterceptor()
      Creates a new instance using the header of the name SimpMessageHeaderAccessor.USER_HEADER.
    • SecurityContextChannelInterceptor

      public SecurityContextChannelInterceptor(String authenticationHeaderName)
      Creates a new instance that uses the specified header to obtain the Authentication.
      Parameters:
      authenticationHeaderName - the header name to obtain the Authentication. Cannot be null.
  • Method Details

    • setAnonymousAuthentication

      public void setAnonymousAuthentication(Authentication authentication)
      Allows setting the 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.
    • preSend

      public org.springframework.messaging.Message<?> preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel)
      Specified by:
      preSend in interface org.springframework.messaging.support.ChannelInterceptor
    • afterSendCompletion

      public void afterSendCompletion(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, boolean sent, Exception ex)
      Specified by:
      afterSendCompletion in interface org.springframework.messaging.support.ChannelInterceptor
    • beforeHandle

      public org.springframework.messaging.Message<?> beforeHandle(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler)
      Specified by:
      beforeHandle in interface org.springframework.messaging.support.ExecutorChannelInterceptor
    • afterMessageHandled

      public void afterMessageHandled(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler, Exception ex)
      Specified by:
      afterMessageHandled in interface org.springframework.messaging.support.ExecutorChannelInterceptor
    • setSecurityContextHolderStrategy

      public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy strategy)