From 310b2e1016171c35eef52462cef5567d9503296e Mon Sep 17 00:00:00 2001 From: imhao183 Date: Tue, 24 Mar 2020 16:37:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B0=81=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=99=BB=E5=BD=95=E8=BF=94=E5=9B=9E=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../io/moquette/spi/impl/ProtocolProcessor.java | 16 ++++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5e54709d..a9a517df 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ sdk/target moments/target monitor wildfire_jmeter +git.properties diff --git a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java index 7dbf4852..35728368 100755 --- a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java +++ b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java @@ -109,8 +109,6 @@ public class ProtocolProcessor { protected ConnectionDescriptorStore connectionDescriptors; - private boolean allowAnonymous; - private boolean allowZeroByteClientId; private IAuthorizator m_authorizator; private IMessagesStore m_messagesStore; @@ -147,8 +145,6 @@ public class ProtocolProcessor { LOG.info("Initializing MQTT protocol processor..."); this.connectionDescriptors = connectionDescriptors; this.m_interceptor = interceptor; - this.allowAnonymous = false; - this.allowZeroByteClientId = false; m_authorizator = authorizator; m_authenticator = authenticator; m_messagesStore = storageService; @@ -199,9 +195,7 @@ public class ProtocolProcessor { MqttVersion mqttVersion = MqttVersion.fromProtocolLevel(msg.variableHeader().version()); if (!login(channel, msg, clientId, mqttVersion)) { - MqttConnAckMessage badId = connAck(CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD); - - channel.writeAndFlush(badId); + channel.flush(); channel.close(); LOG.error("The MQTT login failure. Username={}", payload.userName()); return; @@ -303,6 +297,7 @@ public class ProtocolProcessor { if (session == null) { ErrorCode errorCode = m_sessionsStore.loadActiveSession(msg.payload().userName(), clientId); if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) { + failedNoSession(channel); return false; } session = m_sessionsStore.getSession(clientId); @@ -310,6 +305,7 @@ public class ProtocolProcessor { if (session.getDeleted() != 0) { LOG.error("user {} session {} is deleted. login failure", msg.payload().userName(), clientId); + failedNoSession(channel); return false; } @@ -327,7 +323,7 @@ public class ProtocolProcessor { return false; } session.setMqttVersion(mqttVersion); - } else if (!this.allowAnonymous) { + } else { LOG.error("Client didn't supply any password and MQTT anonymous mode is disabled CId={}", clientId); failedCredentials(channel); return false; @@ -339,12 +335,12 @@ public class ProtocolProcessor { return false; } NettyUtils.userName(channel, msg.payload().userName()); - } else if (!this.allowAnonymous) { + return true; + } else { LOG.error("Client didn't supply any credentials and MQTT anonymous mode is disabled. CId={}", clientId); failedCredentials(channel); return false; } - return true; } private boolean sendAck(ConnectionDescriptor descriptor, MqttConnectMessage msg, final String clientId) {