Class SecureWebsocket<T extends BaseWebsocket>

java.lang.Object
ch.tocco.nice2.web.core.api.websocket.SecureWebsocket<T>
All Implemented Interfaces:
WebSocket<T>
Direct Known Subclasses:
AnonymousWebsocket, NotificationWebsocketDefinition

public abstract class SecureWebsocket<T extends BaseWebsocket> extends Object implements WebSocket<T>
Base implementation of WebSocket that verifies the authentication during the handshake request and supports sending messages to specific users.

The actual implementation must extend BaseWebsocket.

  • Field Details

  • Constructor Details

    • SecureWebsocket

      protected SecureWebsocket(WebsocketFactory websocketFactory)
  • Method Details

    • allowAnonymous

      protected abstract boolean allowAnonymous()
      Returns:
      true if unauthenticated users are supported by this web socket
    • createWebSocketInstance

      public final T createWebSocketInstance()
      Description copied from interface: WebSocket
      Create an instance of the WebSocket implementation. This method allows custom initialization of the WebSocket class.

      A new instance will be created for every new WebSocket connection.

      Specified by:
      createWebSocketInstance in interface WebSocket<T extends BaseWebsocket>
    • onLogout

      @EventListener public void onLogout(LogoutEvent event)
    • doCreateWebSocketInstance

      protected abstract T doCreateWebSocketInstance()
    • getSecurityContext

      protected SecurityContext getSecurityContext()
    • onHandshake

      public final void onHandshake(Map<String,Object> userProperties)
      Description copied from interface: WebSocket
      Called when the WebSocket connection is initialized. This is called from a normal HTTP Request, so authentication data is still available at this point.

      Data stored in the given map will later be available from the WebSocket session.

      Specified by:
      onHandshake in interface WebSocket<T extends BaseWebsocket>
    • sendMessage

      public void sendMessage(Callable<Optional<String>> message)
      Description copied from interface: WebSocket
      Sends a message to all clients that are connected to this endpoint.

      The given callable will be evaluated using the security and business unit contexts of the client.

      Specified by:
      sendMessage in interface WebSocket<T extends BaseWebsocket>
    • sendMessageToOrigin

      public void sendMessageToOrigin(String originId, Callable<Optional<String>> message)
      Description copied from interface: WebSocket
      Sends a message to a certain client.

      The given callable will be evaluated using the security and business unit contexts of the client.

      Specified by:
      sendMessageToOrigin in interface WebSocket<T extends BaseWebsocket>
    • sendMessageToUser

      public void sendMessageToUser(String username, Callable<Optional<String>> message)
      Specified by:
      sendMessageToUser in interface WebSocket<T extends BaseWebsocket>