Install mqtts moquette authencation with database

Step1: Create database name moquette :

Create 1 table and insert  data :

 

DROP TABLE IF EXISTS `account`;

CREATE TABLE `account` (

  `ID` int(11) NOT NULL AUTO_INCREMENT,

  `LOGIN` varchar(255) NOT NULL,

  `PASSWORD` varchar(255) NOT NULL,

  PRIMARY KEY (`ID`)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

INSERT INTO `account` VALUES ('1', 'testuser', '0d6be69b264717f2dd33652e212b173104b4a647b7c11ae72e9885f11cd312fb');

INSERT INTO `account` VALUES ('2', 'testuser1', '0d6be69b264717f2dd33652e212b173104b4a647b7c11ae72e9885f11cd312fb');

INSERT INTO `account` VALUES ('3', 'testuser4', '0d6be69b264717f2dd33652e212b173104b4a647b7c11ae72e9885f11cd312fb');

 

Step 2. Edit file config/moquette.conf

    - Comment line authen file config

   #password_file config/password_file.conf

    - Add code config database

 

authenticator_class io.moquette.spi.impl.security.DBAuthenticator

authenticator.db.driver com.mysql.jdbc.Driver

authenticator.db.url jdbc:mysql://localhost:3306/moquette?user=root&password=

authenticator.db.query SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?

authenticator.db.digest SHA-256

 

Step 3. Restart mqtts broker.

If have error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

download library mysql-connector-java-6.0.6.jar

Step 4. mqtts client connect with addres: ssl:localhost:8883 check mqtts broker

With  username/password: 

 

- testuser/ passwd

- testuser1/ passwd

- testuser4/ passwd