代码优化

This commit is contained in:
zc
2025-12-16 09:34:37 +08:00
parent 510d9f3af0
commit c9baa6a89e
3 changed files with 37 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
package org.dromara.mica.mqtt.server.auth;
import org.dromara.mica.mqtt.core.server.auth.IMqttServerAuthHandler;
import org.dromara.mica.mqtt.spring.server.config.MqttServerProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.tio.core.ChannelContext;
@@ -12,10 +14,27 @@ import org.tio.core.ChannelContext;
@Configuration(proxyBeanMethods = false)
public class MqttAuthHandler implements IMqttServerAuthHandler {
@Value("${mqtt.server.auth.enable}")
private boolean enable;
@Value("${mqtt.server.auth.username}")
private String username;
@Value("${mqtt.server.auth.password}")
private String password;
@Override
public boolean authenticate(ChannelContext context, String uniqueId, String clientId, String username, String password) {
// 客户端认证逻辑实现
if (enable) {
if (username.equals(this.username) && password.equals(this.password)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}

View File

@@ -0,0 +1,12 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.33.96:3306/xa_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: Xahg2024.
data:
redis:
host: 192.168.33.96
port: 6379
password:
database: 1

View File

@@ -6,8 +6,8 @@ spring:
name: mica-mqtt-server
# 环境 dev|test|prod
profiles:
active: dev
# active: prod
# active: dev
active: prod
messages:
encoding: UTF-8
basename: i18n/messages
@@ -57,9 +57,9 @@ mqtt:
read-buffer-size: 8KB # 接收数据的 buffer size默认8k
max-bytes-in-message: 10MB # 消息解析最大 bytes 长度默认10M
auth:
enable: false # 是否开启 mqtt 认证
username: mica # mqtt 认证用户名
password: mica # mqtt 认证密码
enable: true # 是否开启 mqtt 认证
username: admin # mqtt 认证用户名
password: admin@123 # mqtt 认证密码
debug: true # 如果开启 prometheus 指标收集建议关闭
stat-enable: true # 开启指标收集debug 和 prometheus 开启时需要打开,默认开启,关闭节省内存
mqtt-listener: # mqtt 监听器