Skip to content

Refactoring Radius 2.0#129

Open
KotikovAlexander wants to merge 8 commits intomainfrom
feature/refactoring
Open

Refactoring Radius 2.0#129
KotikovAlexander wants to merge 8 commits intomainfrom
feature/refactoring

Conversation

@KotikovAlexander
Copy link
Collaborator

@KotikovAlexander KotikovAlexander commented Feb 5, 2026

What's new:

  • Внесены архитектурные и значительные изменения в кодовой базе
  • Исправлены ошибки соединения с AD
  • Добавлены новые атрибуты ideco
  • Добавлены новые атрибуты вендора Cisco
  • Реализована возможность перечисления LDAP групп при недоступности API в блоке ldapServer
  • Удален неактуальный функционал
  • Актуализирована работа с конфигурацией

@KotikovAlexander KotikovAlexander marked this pull request as ready for review February 5, 2026 09:03
var errorMessage = FlattenException(ex);
StartupLogger.Error(ex, "Unable to start: {Message:l}", errorMessage);
if(ex is InvalidConfigurationException)
StartupLogger.Error(null, "Unable to start: {Message:l}", ex.Message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не прокинута переменная ex?

services.AddSingleton(appVars);
}

private static void AddLdapBindNameFormation(IServiceCollection services)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю эти вещи раскидать по модулям, чтобы сделать честными фичами и избавиться от DI hell

_logger.LogWarning(ex, "Error while processing packet from '{client:l}'", udpPacket.RemoteEndPoint.Address);
}
}
_udpClient = udpClient ?? throw new ArgumentNullException(nameof(udpClient));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверки на null излишни, если аллокацией занимается Service Provider


namespace Multifactor.Radius.Adapter.v2.Server;

public class AdapterServer : IDisposable
public class AdapterServer : IAsyncDisposable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal sealed

@@ -1,47 +1,63 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Multifactor.Core.Ldap.LangFeatures;

namespace Multifactor.Radius.Adapter.v2.Server;

public class ServerHost : IHostedService
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal sealed


namespace Multifactor.Radius.Adapter.v2.Application.Features.Ldap.Ports;

public interface ILdapAdapter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не порт, а толстый неудобный интерфейс. А еще в папке Features/Ldap не нашел собственно фичи. Есть только этот интерфейс имодели


namespace Multifactor.Radius.Adapter.v2.Infrastructure.Configurations.Models;

public class ConfigurationFile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Только не файл, потому что можно читать ото всюду

}
catch (Exception ex)
{
Console.WriteLine($"\n=== Ошибка при Get<ConfigurationFile>(): {ex.Message} ===");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

логгер

try
{
var config = builder.Get<ConfigurationFile>();
config.FileName = Path.GetFileNameWithoutExtension(filePath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет проверки на null, добавить


public static class ConfigurationBuilderExtensions
{
public static IConfigurationBuilder AddLegacyXmlConfig(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не легаси

@@ -0,0 +1,45 @@
namespace Multifactor.Radius.Adapter.v2.Infrastructure.Adapters.Multifactor.Http;

public class ActivityContext
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по хорошему стоит от него отказаться в пользу OpenTelemtry

RadiusAdapterConfigurationFile.ConfigName);
}
var level = rootConfiguration.LoggingLevel;
var skip = string.IsNullOrWhiteSpace(level);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем тут skip?

// {
// throw new InvalidConfigurationException(
// string.Concat("'{prop}' element not found. Config name: '{0}'", "rootConfiguration.ConfigurationName"));
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комменты можно дропнуть

RadiusAdapterConfigurationDescription.Property(x => x.AppSettings.LoggingFormat),
RadiusAdapterConfigurationDescription.Property(x => x.AppSettings.FileLogOutputTemplate));
// Log.Logger.Warning(
// "The {LoggingFormat:l} parameter cannot be used together with the template. The {FileLogOutputTemplate:l} parameter will be ignored.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комменты можно дропнуть

// if (!Directory.Exists(dir))
// {
// Directory.CreateDirectory(dir);
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комменты можно дропнуть

{
contentBytes = RadiusPasswordProtector.Encrypt(sharedSecret, authenticator, contentBytes);
}
else if (attributeDefinition.Code == 80) // Message-Authenticator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

то же самое

{
_radiusDictionary = radiusDictionary ?? throw new ArgumentNullException(nameof(radiusDictionary));
_cryptoProvider = cryptoProvider ?? throw new ArgumentNullException(nameof(cryptoProvider));
// _attributeSerializer = attributeSerializer ?? throw new ArgumentNullException(nameof(attributeSerializer));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комменты можно дропнуть

private readonly IRadiusDictionary _radiusDictionary;
private readonly ILogger<RadiusAttributeParser> _logger;
const int VendorSpecific = 26;
const int MessageAuthenticator = 80;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

снова те же константы

byte vendorType = contentBytes[4];
byte vendorLength = contentBytes[5];

if (vendorLength < 2 || 2 + vendorLength - 2 > contentBytes.Length)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???? 2 + vendorLength - 2 ???? = просто vendorLength > contentBytes.Length

var content = ParseContentBytes(
vendorContentBytes,
vendorAttribute.Type,
26,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants