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
ConstructorDescriptionConstructor 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 authenticatedSecurityContext
or an error.protected abstract reactor.util.context.ContextView
getContextToWrite
(org.springframework.security.core.context.SecurityContext securityContext) Subclasses implement this to decide how to insert theSecurityContext
into the Reactor context of theWebSocketGraphQlInterceptor
chain.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, wait
Methods inherited from interface org.springframework.graphql.server.WebGraphQlInterceptor
andThen, apply
Methods 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: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 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 authenticatedSecurityContext
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 aExecutionGraphQlService
.- Specified by:
intercept
in interfaceWebGraphQlInterceptor
- Specified by:
intercept
in interfaceWebSocketGraphQlInterceptor
- Parameters:
request
- the request which may be aWebSocketGraphQlRequest
when intercepting a GraphQL request over WebSocketchain
- 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 theSecurityContext
into the Reactor context of theWebSocketGraphQlInterceptor
chain.- Parameters:
securityContext
- theSecurityContext
to write to the context
-