Class AbstractAuthenticationWebSocketInterceptor

java.lang.Object
org.springframework.graphql.server.support.AbstractAuthenticationWebSocketInterceptor
All Implemented Interfaces:
WebGraphQlInterceptor, WebSocketGraphQlInterceptor
Direct Known Subclasses:
AuthenticationWebSocketInterceptor, AuthenticationWebSocketInterceptor

public abstract class AbstractAuthenticationWebSocketInterceptor extends Object implements WebSocketGraphQlInterceptor
Base class for interceptors that extract an Authentication from the payload of a "connection_init" GraphQL over WebSocket message. The authentication is saved in WebSocket attributes from where it is later accessed and propagated to subsequent "subscribe" messages.
Since:
1.3.0
Author:
Joshua Cummings, Rossen Stoyanchev
  • Constructor Details

    • AbstractAuthenticationWebSocketInterceptor

      public AbstractAuthenticationWebSocketInterceptor(AuthenticationExtractor authExtractor)
      Constructor with the strategy to use to extract the authentication value from the "connection_init" message.
      Parameters:
      authExtractor - the extractor to use
  • Method Details

    • handleConnectionInitialization

      public reactor.core.publisher.Mono<Object> handleConnectionInitialization(WebSocketSessionInfo info, Map<String,Object> payload)
      Description copied from interface: WebSocketGraphQlInterceptor
      Handle the "connection_init" message at the start of a GraphQL over WebSocket session and return an optional payload for the "connection_ack" message to send back.
      Specified by:
      handleConnectionInitialization in interface WebSocketGraphQlInterceptor
      Parameters:
      info - information about the underlying WebSocket session
      payload - the payload from the "connection_init" message
      Returns:
      the payload for the "connection_ack", or empty
    • authenticate

      protected abstract reactor.core.publisher.Mono<org.springframework.security.core.Authentication> authenticate(org.springframework.security.core.Authentication authentication)
      Subclasses implement this method to return an authenticated SecurityContext or an error.
      Parameters:
      authentication - the authentication value extracted from the payload
    • intercept

      public reactor.core.publisher.Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebGraphQlInterceptor.Chain chain)
      Description copied from interface: WebGraphQlInterceptor
      Intercept a request and delegate to the rest of the chain including other interceptors and a ExecutionGraphQlService.
      Specified by:
      intercept in interface WebGraphQlInterceptor
      Specified by:
      intercept in interface WebSocketGraphQlInterceptor
      Parameters:
      request - the request which may be a WebSocketGraphQlRequest when intercepting a GraphQL request over WebSocket
      chain - the rest of the chain to execute the request
      Returns:
      a Mono with the response
    • getContextToWrite

      protected abstract reactor.util.context.ContextView getContextToWrite(org.springframework.security.core.context.SecurityContext securityContext)
      Subclasses implement this to decide how to insert the SecurityContext into the Reactor context of the WebSocketGraphQlInterceptor chain.
      Parameters:
      securityContext - the SecurityContext to write to the context