代码优化
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package org.dromara.mica.mqtt.server.auth;
|
package org.dromara.mica.mqtt.server.auth;
|
||||||
|
|
||||||
import org.dromara.mica.mqtt.core.server.auth.IMqttServerAuthHandler;
|
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.springframework.context.annotation.Configuration;
|
||||||
import org.tio.core.ChannelContext;
|
import org.tio.core.ChannelContext;
|
||||||
|
|
||||||
@@ -12,10 +14,27 @@ import org.tio.core.ChannelContext;
|
|||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class MqttAuthHandler implements IMqttServerAuthHandler {
|
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
|
@Override
|
||||||
public boolean authenticate(ChannelContext context, String uniqueId, String clientId, String username, String password) {
|
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;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -6,8 +6,8 @@ spring:
|
|||||||
name: mica-mqtt-server
|
name: mica-mqtt-server
|
||||||
# 环境 dev|test|prod
|
# 环境 dev|test|prod
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
# active: dev
|
||||||
# active: prod
|
active: prod
|
||||||
messages:
|
messages:
|
||||||
encoding: UTF-8
|
encoding: UTF-8
|
||||||
basename: i18n/messages
|
basename: i18n/messages
|
||||||
@@ -57,9 +57,9 @@ mqtt:
|
|||||||
read-buffer-size: 8KB # 接收数据的 buffer size,默认:8k
|
read-buffer-size: 8KB # 接收数据的 buffer size,默认:8k
|
||||||
max-bytes-in-message: 10MB # 消息解析最大 bytes 长度,默认:10M
|
max-bytes-in-message: 10MB # 消息解析最大 bytes 长度,默认:10M
|
||||||
auth:
|
auth:
|
||||||
enable: false # 是否开启 mqtt 认证
|
enable: true # 是否开启 mqtt 认证
|
||||||
username: mica # mqtt 认证用户名
|
username: admin # mqtt 认证用户名
|
||||||
password: mica # mqtt 认证密码
|
password: admin@123 # mqtt 认证密码
|
||||||
debug: true # 如果开启 prometheus 指标收集建议关闭
|
debug: true # 如果开启 prometheus 指标收集建议关闭
|
||||||
stat-enable: true # 开启指标收集,debug 和 prometheus 开启时需要打开,默认开启,关闭节省内存
|
stat-enable: true # 开启指标收集,debug 和 prometheus 开启时需要打开,默认开启,关闭节省内存
|
||||||
mqtt-listener: # mqtt 监听器
|
mqtt-listener: # mqtt 监听器
|
||||||
|
|||||||
Reference in New Issue
Block a user