Browse Source

Add the adapter Endpoint to the connection validator.

release/3.x.x
Christian Kratky 6 years ago
parent
commit
9fa5e2dc1f
2 changed files with 8 additions and 4 deletions
  1. +4
    -3
      Source/MQTTnet/Server/MqttClientSessionsManager.cs
  2. +4
    -1
      Source/MQTTnet/Server/MqttConnectionValidatorContext.cs

+ 4
- 3
Source/MQTTnet/Server/MqttClientSessionsManager.cs View File

@@ -212,7 +212,7 @@ namespace MQTTnet.Server
// Switch to the required protocol version before sending any response. // Switch to the required protocol version before sending any response.
clientAdapter.PacketSerializer.ProtocolVersion = connectPacket.ProtocolVersion; clientAdapter.PacketSerializer.ProtocolVersion = connectPacket.ProtocolVersion;


var connectReturnCode = ValidateConnection(connectPacket);
var connectReturnCode = ValidateConnection(connectPacket, clientAdapter);
if (connectReturnCode != MqttConnectReturnCode.ConnectionAccepted) if (connectReturnCode != MqttConnectReturnCode.ConnectionAccepted)
{ {
await clientAdapter.SendPacketAsync( await clientAdapter.SendPacketAsync(
@@ -268,7 +268,7 @@ namespace MQTTnet.Server
} }
} }


private MqttConnectReturnCode ValidateConnection(MqttConnectPacket connectPacket)
private MqttConnectReturnCode ValidateConnection(MqttConnectPacket connectPacket, IMqttChannelAdapter clientAdapter)
{ {
if (_options.ConnectionValidator == null) if (_options.ConnectionValidator == null)
{ {
@@ -279,7 +279,8 @@ namespace MQTTnet.Server
connectPacket.ClientId, connectPacket.ClientId,
connectPacket.Username, connectPacket.Username,
connectPacket.Password, connectPacket.Password,
connectPacket.WillMessage);
connectPacket.WillMessage,
clientAdapter.Endpoint);


_options.ConnectionValidator(context); _options.ConnectionValidator(context);
return context.ReturnCode; return context.ReturnCode;


+ 4
- 1
Source/MQTTnet/Server/MqttConnectionValidatorContext.cs View File

@@ -4,12 +4,13 @@ namespace MQTTnet.Server
{ {
public class MqttConnectionValidatorContext public class MqttConnectionValidatorContext
{ {
public MqttConnectionValidatorContext(string clientId, string username, string password, MqttApplicationMessage willMessage)
public MqttConnectionValidatorContext(string clientId, string username, string password, MqttApplicationMessage willMessage, string endpoint)
{ {
ClientId = clientId; ClientId = clientId;
Username = username; Username = username;
Password = password; Password = password;
WillMessage = willMessage; WillMessage = willMessage;
Endpoint = endpoint;
} }


public string ClientId { get; } public string ClientId { get; }
@@ -20,6 +21,8 @@ namespace MQTTnet.Server


public MqttApplicationMessage WillMessage { get; } public MqttApplicationMessage WillMessage { get; }


public string Endpoint { get; }

public MqttConnectReturnCode ReturnCode { get; set; } = MqttConnectReturnCode.ConnectionAccepted; public MqttConnectReturnCode ReturnCode { get; set; } = MqttConnectReturnCode.ConnectionAccepted;
} }
} }

Loading…
Cancel
Save