Package io.mats3.matssocket
Interface AuthenticationPlugin.AuthenticationContext
- Enclosing interface:
- AuthenticationPlugin
public static interface AuthenticationPlugin.AuthenticationContext
-
Method Summary
Modifier and TypeMethodDescriptionauthenticated
(Principal principal, String userId) Good Authentication! Return the result from this method fromSessionAuthenticator.initialAuthentication(..)
to denote good authentication, supplying a Principal representing the accessing user, and the UserId of this user.authenticated
(Principal principal, String userId, EnumSet<AuthenticationPlugin.DebugOption> allowedDebugOptions) Good Authentication! Variant ofauthenticated(Principal, String)
that grants the authenticated user special abilities to ask for debug info of the performed call.javax.websocket.server.HandshakeRequest
invalidAuthentication
(String reason) Bad Authentication! Return the result from this method fromSessionAuthenticator.initialAuthentication(..)
orAuthenticationPlugin.SessionAuthenticator.reevaluateAuthentication(AuthenticationContext, String, Principal)
SessionAuthenticator.reevaluateAuthentication(..)} to denote BAD authentication, supplying a reason string which will be sent all the way to the client (so do not include sensitive information).void
setOriginatingRemoteAddr
(String originatingRemoteAddr) Sets the Originating Remote Address, as exposed viaMatsSocketServer.ActiveMatsSocketSession.getOriginatingRemoteAddr()
- read that JavaDoc.void
setRemoteAddr
(String remoteAddr) Sets (or overrides) the Remote Address, as exposed viaMatsSocketServer.ActiveMatsSocketSession.getRemoteAddr()
- read that JavaDoc, in particular that if this server is behind a proxy, this will be the proxy's address.Existing Authentication is still good! Return the result from this method fromAuthenticationPlugin.SessionAuthenticator.reevaluateAuthentication(AuthenticationContext, String, Principal)
if the 'existingPrincipal' (and implicitly the userId) is still good to go.
-
Method Details
-
getHandshakeRequest
javax.websocket.server.HandshakeRequest getHandshakeRequest()- Returns:
- the
HandshakeRequest
that was provided to the JSR 356 WebSocket API's EndpointConfigurator
when the client connected. Do realize that there is only a single HTTP request involved in setting up the WebSocket connection: The initial "Upgrade: WebSocket" request.
-
getMatsSocketSession
MatsSocketServer.LiveMatsSocketSession getMatsSocketSession()- Returns:
- the current MatsSocketSession. Until
Initial Authentication
(happening with the HELLO message from the Client), all theOptional
-returning methods will returnOptional.empty()
- it is basically the responsibility of the authentication mechanism to supply values for these.
-
setRemoteAddr
Sets (or overrides) the Remote Address, as exposed viaMatsSocketServer.ActiveMatsSocketSession.getRemoteAddr()
- read that JavaDoc, in particular that if this server is behind a proxy, this will be the proxy's address. Also seesetOriginatingRemoteAddr(String)
where any X-Forwarded-For resolved address should be set. Note that if the MatsSocketServer handles getting the remote address itself (via hacks, since JSR 356 Java API for WebSockets does not expose it), it will already be available in thegetMatsSocketSession()
.- Parameters:
remoteAddr
- what should be replied byMatsSocketServer.ActiveMatsSocketSession.getRemoteAddr()
.- See Also:
-
setOriginatingRemoteAddr
Sets the Originating Remote Address, as exposed viaMatsSocketServer.ActiveMatsSocketSession.getOriginatingRemoteAddr()
- read that JavaDoc.- Parameters:
originatingRemoteAddr
- what should be replied byMatsSocketServer.ActiveMatsSocketSession.getOriginatingRemoteAddr()
.- See Also:
-
invalidAuthentication
Bad Authentication! Return the result from this method fromSessionAuthenticator.initialAuthentication(..)
orAuthenticationPlugin.SessionAuthenticator.reevaluateAuthentication(AuthenticationContext, String, Principal)
SessionAuthenticator.reevaluateAuthentication(..)} to denote BAD authentication, supplying a reason string which will be sent all the way to the client (so do not include sensitive information).- Parameters:
reason
- a String which will be sent all the way to the client (so do not include sensitive information).- Returns:
- an
AuthenticationPlugin.AuthenticationResult
that can be returned by the methods ofAuthenticationPlugin.SessionAuthenticator
.
-
authenticated
Good Authentication! Return the result from this method fromSessionAuthenticator.initialAuthentication(..)
to denote good authentication, supplying a Principal representing the accessing user, and the UserId of this user. You can also return the result from this method fromSessionAuthenticator.reevaluateAuthentication(..)
if you want to change the Principal, typically just to update some meta data values, as it would be strange if such reevaluation of authentication resulted in a different user than last time.- Parameters:
principal
- the Principal that will be supplied to allMatsSocketServer.IncomingAuthorizationAndAdapter.handleIncoming(MatsSocketEndpointIncomingContext, Principal, Object)
calls, for the MatsSocket endpoints to evaluate for authorization or to get needed user specific data from (typically thus casting the Principal to a specific class for thisAuthenticationPlugin
).userId
- the user id for the Principal - this is needed separately from the Principal so that it is possible to target a specific user via a send or request from server to client.- Returns:
- an
AuthenticationPlugin.AuthenticationResult
that can be returned by the methods ofAuthenticationPlugin.SessionAuthenticator
.
-
authenticated
AuthenticationPlugin.AuthenticationResult authenticated(Principal principal, String userId, EnumSet<AuthenticationPlugin.DebugOption> allowedDebugOptions) Good Authentication! Variant ofauthenticated(Principal, String)
that grants the authenticated user special abilities to ask for debug info of the performed call.- Parameters:
principal
- the Principal that will be supplied to allMatsSocketServer.IncomingAuthorizationAndAdapter.handleIncoming(MatsSocketEndpointIncomingContext, Principal, Object)
calls, for the MatsSocket endpoints to evaluate for authorization or to get needed user specific data from (typically thus casting the Principal to a specific class for thisAuthenticationPlugin
).userId
- the user id for the Principal - this is needed separately from the Principal so that it is possible to target a specific user via a send or request from server to client.allowedDebugOptions
- Which types of Debug stuff the user is allowed to ask for. The resulting debug options is the "logical AND" between these, and what the client requests.- Returns:
- an
AuthenticationPlugin.AuthenticationResult
that can be returned by the methods ofAuthenticationPlugin.SessionAuthenticator
.
-
stillValid
AuthenticationPlugin.AuthenticationResult stillValid()Existing Authentication is still good! Return the result from this method fromAuthenticationPlugin.SessionAuthenticator.reevaluateAuthentication(AuthenticationContext, String, Principal)
if the 'existingPrincipal' (and implicitly the userId) is still good to go.- Returns:
- an
AuthenticationPlugin.AuthenticationResult
that can be returned by the methodAuthenticationPlugin.SessionAuthenticator.reevaluateAuthentication(AuthenticationContext, String, Principal)
, stating that the existing authorization is still valid.
-