Class SimpleCoolHook

  • All Implemented Interfaces:
    MQTTCoolHook

    public class SimpleCoolHook
    extends java.lang.Object
    implements MQTTCoolHook
    Simple skeletal implementation of the MQTTCoolHook interface, meant as a base class to be extended in order to minimize the effort required to provide a full implementation of a custom Hook.

    All methods provide a trivial implementation, therefore subclasses must override those methods for which a specific behavior is really needed.

    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleCoolHook()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canConnect​(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttConnectOptions connectOptions)
      This implementation always returns true.
      boolean canOpenSession​(java.lang.String sessionId, java.lang.String user, java.lang.String password, java.util.Map clientContext, java.lang.String clientPrincipal)
      This implementation always returns true.
      boolean canPublish​(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttMessage message)
      This implementation always returns true.
      boolean canSubscribe​(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttSubscription subscription)
      This implementation always returns true.
      void init​(java.io.File configDir)
      This implementation is void.
      void onDisconnection​(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress)
      This implementation is void.
      void onSessionClose​(java.lang.String sessionId)
      This implementation is void.
      void onUnsubscribe​(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, java.lang.String topicFilter)
      This implementation is void.
      MqttBrokerConfig resolveAlias​(java.lang.String alias)
      This implementation always returns null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleCoolHook

        public SimpleCoolHook()
    • Method Detail

      • init

        public void init​(java.io.File configDir)
                  throws HookException
        This implementation is void.
        Specified by:
        init in interface MQTTCoolHook
        Parameters:
        configDir - the <MQTT.COOL_HOME>/mqtt_connectors directory
        Throws:
        HookException - if the the initialization can't complete successfully; in this case the MQTT.Cool server process will abort
      • resolveAlias

        public MqttBrokerConfig resolveAlias​(java.lang.String alias)
                                      throws HookException
        This implementation always returns null.
        Specified by:
        resolveAlias in interface MQTTCoolHook
        Parameters:
        alias - the connection alias provided by a client to address a specific MQTT broker
        Returns:
        an MqttBrokerConfig object, or null if this Hook can not supply a valid MQTT broker configuration
        Throws:
        HookException - if this Hook runs against a specific issue while providing an MQTT broker configuration
      • canOpenSession

        public boolean canOpenSession​(java.lang.String sessionId,
                                      java.lang.String user,
                                      java.lang.String password,
                                      java.util.Map clientContext,
                                      java.lang.String clientPrincipal)
                               throws HookException
        This implementation always returns true.
        Specified by:
        canOpenSession in interface MQTTCoolHook
        Parameters:
        sessionId - the unique identifier of client session
        user - the username of the user trying to opening a session; it can be null if no username has been provided
        password - the password of the user trying to opening a session; it can be null if no password has been provided
        clientContext - the key-value map which contains the properties of the client request; available keys are:
        • "REMOTE_IP" - string representation of the remote IP related to the current connection; it may be a proxy address.
        • "REMOTE_PORT" - string representation of the remote port related to the current connection.
        • "USER_AGENT" - the user-agent as declared in the current connection HTTP header.
        • "FORWARDING_INFO" - the comma-separated list of addresses forwarded by intermediaries, obtained from the X-Forwarded-For HTTP header, related to the current connection; intermediate proxies usually set this header to supply connection routing information. Note that if the number of forwards to be considered local to the Server environment has been specified through the skip_local_forwards configuration element, in order to better determine the remote address, then these forwards will not be list.
        • "LOCAL_SERVER" - the name of the specific server socket that handles the current connection, as configured through the http_server or https_server element.
        • "HTTP_HEADERS" - a map object that contains a name-value pair for each header found in the HTTP request that originated the call.
        clientPrincipal - the identification name reported in the client TLS/SSL certificate supplied on the socket connection used to issue the request that originated the call; it can be null if client has not authenticated itself or the authentication has failed
        Returns:
        true if this Hook authorizes the client to open the session
        Throws:
        HookException - if this Hook runs against a specific issue while performing authorization checks (for example, while validating the provided credentials with an external service)
      • onSessionClose

        public void onSessionClose​(java.lang.String sessionId)
        This implementation is void.
        Specified by:
        onSessionClose in interface MQTTCoolHook
        Parameters:
        sessionId - the unique identifier of the client session
      • canConnect

        public boolean canConnect​(java.lang.String sessionId,
                                  java.lang.String clientId,
                                  java.lang.String brokerAddress,
                                  MqttConnectOptions connectOptions)
                           throws HookException
        This implementation always returns true.
        Specified by:
        canConnect in interface MQTTCoolHook
        Parameters:
        sessionId - the unique identifier of the client session
        clientId - the client identifier as sent by the client, namely:
        • For a dedicated connection, it corresponds to the actual client identifier being used to connect to the target MQTT broker.
        • For a shared connection, it is an empty ("") string, as the actual client identifier is determined through the connection parameters specified in the mqtt_master_connector_conf.xml file, or by the MqttBrokerConfig instance provided by the MQTTCoolHook.resolveAlias(String) method.
        brokerAddress - the address of the MQTT broker to connect to
        connectOptions - the set of options being used to connect to the target MQTT broker
        Returns:
        true if this Hook authorizes the client to connect to the target MQTT broker
        Throws:
        HookException - if this Hook runs against a specific issue while performing authorization checks