Package cool.mqtt.hooks
Class SimpleCoolHook
java.lang.Object
cool.mqtt.hooks.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
Modifier and Type Method Description booleancanConnect(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttConnectOptions connectOptions)This implementation always returnstrue.booleancanOpenSession(java.lang.String sessionId, java.lang.String user, java.lang.String password, java.util.Map clientContext, java.lang.String clientPrincipal)This implementation always returnstrue.booleancanPublish(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttMessage message)This implementation always returnstrue.booleancanSubscribe(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttSubscription subscription)This implementation always returnstrue.voidinit(java.io.File configDir)This implementation is void.voidonDisconnection(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress)This implementation is void.voidonSessionClose(java.lang.String sessionId)This implementation is void.voidonUnsubscribe(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, java.lang.String topicFilter)This implementation is void.MqttBrokerConfigresolveAlias(java.lang.String alias)This implementation always returnsnull.
-
Constructor Details
-
SimpleCoolHook
public SimpleCoolHook()
-
-
Method Details
-
init
This implementation is void.- Specified by:
initin interfaceMQTTCoolHook- Parameters:
configDir- the<MQTT.COOL_HOME>/mqtt_connectorsdirectory- Throws:
HookException- if the the initialization can't complete successfully; in this case the MQTT.Cool server process will abort
-
resolveAlias
This implementation always returnsnull.- Specified by:
resolveAliasin interfaceMQTTCoolHook- Parameters:
alias- the connection alias provided by a client to address a specific MQTT broker- Returns:
- an
MqttBrokerConfigobject, ornullif 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 HookExceptionThis implementation always returnstrue.- Specified by:
canOpenSessionin interfaceMQTTCoolHook- Parameters:
sessionId- the unique identifier of client sessionuser- the username of the user trying to opening a session; it can benullif no username has been providedpassword- the password of the user trying to opening a session; it can benullif no password has been providedclientContext- 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 theX-Forwarded-For HTTPheader, 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 theskip_local_forwardsconfiguration 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 thehttp_serverorhttps_serverelement."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 benullif client has not authenticated itself or the authentication has failed- Returns:
trueif 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:
onSessionClosein interfaceMQTTCoolHook- 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 HookExceptionThis implementation always returnstrue.- Specified by:
canConnectin interfaceMQTTCoolHook- Parameters:
sessionId- the unique identifier of the client sessionclientId- 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.xmlfile, or by theMqttBrokerConfiginstance provided by theMQTTCoolHook.resolveAlias(String)method.
brokerAddress- the address of the MQTT broker to connect toconnectOptions- the set of options being used to connect to the target MQTT broker- Returns:
trueif 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
-
onDisconnection
public void onDisconnection(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress)This implementation is void.- Specified by:
onDisconnectionin interfaceMQTTCoolHook- Parameters:
sessionId- the unique identifier of the client sessionclientId- the client identifier as sent by the client (and detailed inMQTTCoolHook.canConnect(java.lang.String, java.lang.String, java.lang.String, cool.mqtt.hooks.MqttConnectOptions))brokerAddress- the address of the MQTT broker disconnected from
-
canPublish
public boolean canPublish(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttMessage message) throws HookExceptionThis implementation always returnstrue.- Specified by:
canPublishin interfaceMQTTCoolHook- Parameters:
sessionId- the unique identifier of the client sessionclientId- the client identifier as sent by the client (and detailed inMQTTCoolHook.canConnect(java.lang.String, java.lang.String, java.lang.String, cool.mqtt.hooks.MqttConnectOptions))brokerAddress- the address of the MQTT broker connected tomessage- the message being requested to be published to the specified MQTT broker- Returns:
trueif this Hook authorizes the client to publish the given message- Throws:
HookException- if this Hook runs against a specific issue while performing authorization checks
-
canSubscribe
public boolean canSubscribe(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, MqttSubscription subscription) throws HookExceptionThis implementation always returnstrue.- Specified by:
canSubscribein interfaceMQTTCoolHook- Parameters:
sessionId- the unique identifier of the client sessionclientId- the client identifier as sent by the client (and detailed inMQTTCoolHook.canConnect(java.lang.String, java.lang.String, java.lang.String, cool.mqtt.hooks.MqttConnectOptions))brokerAddress- the address of the MQTT broker connected tosubscription- the subscription being requested to be sent to the specified MQTT broker- Returns:
trueif this Hook authorizes the client to send the given subscription- Throws:
HookException- if this Hook runs against a specific issue while performing authorization checks
-
onUnsubscribe
public void onUnsubscribe(java.lang.String sessionId, java.lang.String clientId, java.lang.String brokerAddress, java.lang.String topicFilter)This implementation is void.- Specified by:
onUnsubscribein interfaceMQTTCoolHook- Parameters:
sessionId- the unique identifier of the client sessionclientId- the client identifier as sent by the client (and detailed inMQTTCoolHook.canConnect(java.lang.String, java.lang.String, java.lang.String, cool.mqtt.hooks.MqttConnectOptions))brokerAddress- the address of the MQTT broker connected totopicFilter- the topic filter unsubscribed from
-