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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.graphql.server.WebGraphQlInterceptor
WebGraphQlInterceptor.Chain -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with the strategy to use to extract the authentication value from the"connection_init"message. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract reactor.core.publisher.Mono<org.springframework.security.core.Authentication> authenticate(org.springframework.security.core.Authentication authentication) Subclasses implement this method to return an authenticatedSecurityContextor an error.protected abstract reactor.util.context.ContextViewgetContextToWrite(org.springframework.security.core.context.SecurityContext securityContext) Subclasses implement this to decide how to insert theSecurityContextinto the Reactor context of theWebSocketGraphQlInterceptorchain.reactor.core.publisher.Mono<Object> handleConnectionInitialization(WebSocketSessionInfo info, Map<String, Object> payload) 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.reactor.core.publisher.Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebGraphQlInterceptor.Chain chain) Intercept a request and delegate to the rest of the chain including other interceptors and aExecutionGraphQlService.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.graphql.server.WebGraphQlInterceptor
andThen, applyMethods inherited from interface org.springframework.graphql.server.WebSocketGraphQlInterceptor
handleCancelledSubscription, handleConnectionClosed
-
Constructor Details
-
AbstractAuthenticationWebSocketInterceptor
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:WebSocketGraphQlInterceptorHandle 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:
handleConnectionInitializationin interfaceWebSocketGraphQlInterceptor- Parameters:
info- information about the underlying WebSocket sessionpayload- 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 authenticatedSecurityContextor 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:WebGraphQlInterceptorIntercept a request and delegate to the rest of the chain including other interceptors and aExecutionGraphQlService.- Specified by:
interceptin interfaceWebGraphQlInterceptor- Specified by:
interceptin interfaceWebSocketGraphQlInterceptor- Parameters:
request- the request which may be aWebSocketGraphQlRequestwhen intercepting a GraphQL request over WebSocketchain- the rest of the chain to execute the request- Returns:
- a
Monowith 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 theSecurityContextinto the Reactor context of theWebSocketGraphQlInterceptorchain.- Parameters:
securityContext- theSecurityContextto write to the context
-