diff --git a/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/AdapterResponseSender.cs b/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/AdapterResponseSender.cs index b9addb6..ecc404a 100644 --- a/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/AdapterResponseSender.cs +++ b/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/AdapterResponseSender.cs @@ -176,14 +176,27 @@ private static void CopyAttributes(RadiusPacket? source, RadiusPacket? target) private void AddProxyStateAttribute(RadiusPacket source, RadiusPacket target) { - if (!source.Attributes.TryGetValue(ProxyStateAttribute, out var proxyStateAttribute)) return; - if (target.Attributes.ContainsKey(ProxyStateAttribute)) return; - var value = proxyStateAttribute.Values.FirstOrDefault(); - if (value != null) + if (!source.Attributes.TryGetValue(ProxyStateAttribute, out var proxyStateAttribute)) + { + + _logger.LogDebug("Source Attribute '{attrname:l}' is empty", ProxyStateAttribute); + return; + } + if (target.Attributes.ContainsKey(ProxyStateAttribute)) + { + _logger.LogDebug("Target already contains attribute '{attrname:l}'", ProxyStateAttribute); + return; + } + var value = proxyStateAttribute.Values; + if (value is { Count: > 0 }) { _logger.LogDebug("Added/replaced attribute '{attrname:l}' to reply", ProxyStateAttribute); target.AddAttributeValue(ProxyStateAttribute, value); } + else + { + _logger.LogDebug("Attribute '{attrname:l}' is empty", ProxyStateAttribute); + } } private static void AddMessageAuthenticatorIfMissing(RadiusPacket packet) diff --git a/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/Radius/RadiusPacketBuilder.cs b/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/Radius/RadiusPacketBuilder.cs index a9e81d1..6e17813 100644 --- a/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/Radius/RadiusPacketBuilder.cs +++ b/src/Multifactor.Radius.Adapter.v2.Infrastructure/Features/PacketHandler/Adapters/Radius/RadiusPacketBuilder.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Net; using System.Text; using Multifactor.Radius.Adapter.v2.Application.Core.Enum; @@ -210,10 +211,22 @@ private static byte[] GetAttributeValueBytes(object value) contentBytes = BitConverter.GetBytes(val); Array.Reverse(contentBytes); return contentBytes; + case long val: + contentBytes = BitConverter.GetBytes(val); + Array.Reverse(contentBytes); + return contentBytes; + case ulong val: + contentBytes = BitConverter.GetBytes(val); + Array.Reverse(contentBytes); + return contentBytes; case byte[] val: return val; case IPAddress val: return val.GetAddressBytes(); + case IEnumerable val: + return val.Cast() + .SelectMany(GetAttributeValueBytes) + .ToArray(); default: throw new NotImplementedException(); }