连接鉴权
quickmsg
# main启动指定用户名密码(不检验clientIdentifier)
BootstrapConfig
.TcpConfig
.builder()
.port(8888)
.username("smqtt")
.password("smqtt")
.build()
1
2
3
4
5
6
7
2
3
4
5
6
7
# 配置文件指定用户名密码(不检验clientIdentifier)
smqtt:
logLevel: DEBUG # 系统日志
tcp: # tcp配置
username: smqtt # mqtt连接默认用户名 生产环境建议spi去注入PasswordAuthentication接口
password: smqtt # mqtt连接默认密码 生产环境建议spi去注入PasswordAuthentication接口
1
2
3
4
5
2
3
4
5
# 自定义认证类
PasswordAuthentication
接口参数参数 说明 必传 username 用户名 是 password 密码 是 clientIdentifier 客户端id 是 自定义实现
PasswordAuthentication
接口启动时候SPI注入接口
具体参考java SPI注入
resources/META-INF/services 目录下新建 名为io.github.quickmsg.common.auth.PasswordAuthentication文件, 将自定义实现类全限定名写入文件中即可完成注入。
注意 如果是自定义实现PasswordAuthentication接口,然后通过Bootstrap模块打包成jar 那则会覆盖config.yaml中的配置项,默认配置文件中是不检验客户端id,仅仅是校验用户名密码,所以生产环境推荐自定义实现PasswordAuthentication接口