Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/v2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbannov authored Mar 4, 2024
2 parents 28a2084 + 6418591 commit 811ea9f
Show file tree
Hide file tree
Showing 1,485 changed files with 93,305 additions and 72,438 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ dotnet_style_qualification_for_event = false:silent
dotnet_diagnostic.CA1715.severity = warning
dotnet_diagnostic.CA1716.severity = silent
dotnet_diagnostic.CA5397.severity = warning
dotnet_diagnostic.ASP0023.severity = none


file_header_template = (c) Copyright Ascensio System SIA 2010-2023\n\nThis program is a free software product.\nYou can redistribute it and/or modify it under the terms\nof the GNU Affero General Public License (AGPL) version 3 as published by the Free Software\nFoundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended\nto the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of\nany third-party rights.\n\nThis program is distributed WITHOUT ANY WARRANTY, without even the implied warranty\nof MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see\nthe GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html\n\nYou can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.\n\nThe interactive user interfaces in modified source and object code versions of the Program must\ndisplay Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.\n\nPursuant to Section 7(b) of the License you must retain the original Product logo when\ndistributing the program. Pursuant to Section 7(e) we decline to grant you any rights under\ntrademark law for use of our trademarks.\n\nAll the Product's GUI elements, including illustrations and icon sets, as well as technical writing\ncontent are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0\nInternational. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
Binary file not shown.
3 changes: 2 additions & 1 deletion common/ASC.ActiveDirectory/ASC.ActiveDirectory.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,21 @@ public static int[] GetLdapCertProblems(X509Certificate certificate, X509Chain c

if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch))
{
if (log != null)
{
log.WarnGetLdapCertProblems(Enum.GetName(typeof(SslPolicyErrors), LdapCertificateProblem.CertCnNoMatch));
}
log?.WarnGetLdapCertProblems(Enum.GetName(typeof(SslPolicyErrors), LdapCertificateProblem.CertCnNoMatch));

certificateErrors.Add((int)LdapCertificateProblem.CertCnNoMatch);
}

if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable))
{
if (log != null)
{
log.WarnGetLdapCertProblems(Enum.GetName(typeof(SslPolicyErrors), LdapCertificateProblem.CertCnNoMatch));
}
log?.WarnGetLdapCertProblems(Enum.GetName(typeof(SslPolicyErrors), LdapCertificateProblem.CertCnNoMatch));

certificateErrors.Add((int)LdapCertificateProblem.CertUntrustedCa);
}
}
catch (Exception ex)
{
if (log != null)
{
log.ErrorGetLdapCertProblems(ex);
}
log?.ErrorGetLdapCertProblems(ex);

certificateErrors.Add((int)LdapCertificateProblem.CertUnrecognizedError);
}
Expand Down Expand Up @@ -156,10 +147,7 @@ public static LdapCertificateConfirmRequest FromCert(X509Certificate certificate
}
catch (Exception ex)
{
if (log != null)
{
log.ErrorLdapCertificateConfirmRequest(ex);
}
log?.ErrorLdapCertificateConfirmRequest(ex);

return null;
}
Expand Down
16 changes: 5 additions & 11 deletions common/ASC.ActiveDirectory/Base/Data/LdapLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode

namespace ASC.ActiveDirectory.Base.Data;
public class LdapLogin
public class LdapLogin(string username, string domain)
{
public string Username { get; private set; }
public string Domain { get; private set; }

public LdapLogin(string username, string domain)
{
Username = username;
Domain = domain;
}
public string Username { get; private set; } = username;
public string Domain { get; private set; } = domain;

public override string ToString()
{
Expand All @@ -55,7 +49,7 @@ public static LdapLogin ParseLogin(string login)
{
var splited = login.Split('\\');

if (!splited.Any() || splited.Length != 2)
if (splited.Length == 0 || splited.Length != 2)
{
return null;
}
Expand All @@ -68,7 +62,7 @@ public static LdapLogin ParseLogin(string login)
{
var splited = login.Split('@');

if (!splited.Any() || splited.Length != 2)
if (splited.Length == 0 || splited.Length != 2)
{
return null;
}
Expand Down
46 changes: 16 additions & 30 deletions common/ASC.ActiveDirectory/Base/Data/LdapObjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,8 @@ namespace ASC.ActiveDirectory.Base.Data;
/// LDAP object extensions class
/// </summary>
[Scope]
public class LdapObjectExtension
public class LdapObjectExtension(TenantUtil tenantUtil, SettingsManager settingsManager, ILogger<LdapObjectExtension> logger)
{
private readonly TenantUtil _tenantUtil;
private readonly SettingsManager _settingsManager;
private readonly ILogger<LdapObjectExtension> _logger;

public LdapObjectExtension(TenantUtil tenantUtil, SettingsManager settingsManager, ILogger<LdapObjectExtension> logger)
{
_tenantUtil = tenantUtil;
_settingsManager = settingsManager;
_logger = logger;
}
public string GetAttribute(LdapObject ldapObject, string attribute)
{
if (string.IsNullOrEmpty(attribute))
Expand All @@ -56,7 +46,7 @@ public string GetAttribute(LdapObject ldapObject, string attribute)
}
catch (Exception e)
{
_logger.ErrorCanNotGetAttribute(attribute, ldapObject.DistinguishedName, e);
logger.ErrorCanNotGetAttribute(attribute, ldapObject.DistinguishedName, e);

return string.Empty;
}
Expand All @@ -78,7 +68,7 @@ public List<string> GetAttributes(LdapObject ldapObject, string attribute)
catch (Exception e)
{

_logger.ErrorCanNotGetAttributes(attribute, ldapObject.DistinguishedName, e);
logger.ErrorCanNotGetAttributes(attribute, ldapObject.DistinguishedName, e);

return list;
}
Expand Down Expand Up @@ -107,23 +97,21 @@ private List<string> GetContacts(LdapObject ldapUser, Mapping key, LdapSettings
}
return list;
}
else
{
return GetAttributes(ldapUser, bindings[0]);
}

return GetAttributes(ldapUser, bindings[0]);
}

private void PopulateContacts(List<string> Contacts, string type, List<string> values)
private void PopulateContacts(ICollection<string> contacts, string type, List<string> values)
{
if (values == null || !values.Any())
if (values == null || values.Count == 0)
{
return;
}

foreach (var val in values)
{
Contacts.Add(type);
Contacts.Add(val);
contacts.Add(type);
contacts.Add(val);
}
}

Expand All @@ -148,8 +136,8 @@ public async Task<UserInfo> ToUserInfoAsync(LdapObject ldapUser, LdapUserImporte
var emails = GetContacts(ldapUser, Mapping.AdditionalMail, settings);
var skype = GetContacts(ldapUser, Mapping.Skype, settings);

var quotaSettings = await _settingsManager.LoadAsync<TenantUserQuotaSettings>();
var quota = settings.LdapMapping.TryGetValue(Mapping.UserQuotaLimit, out var value8) ? ByteConverter.ConvertSizeToBytes(GetAttribute(ldapUser, value8)) : quotaSettings.DefaultUserQuota;
var quotaSettings = await settingsManager.LoadAsync<TenantUserQuotaSettings>();
var quota = settings.LdapMapping.TryGetValue(Mapping.UserQuotaLimit, out var value8) ? ByteConverter.ConvertSizeToBytes(GetAttribute(ldapUser, value8)) : quotaSettings.DefaultQuota;

if (string.IsNullOrEmpty(userName))
{
Expand All @@ -172,15 +160,15 @@ public async Task<UserInfo> ToUserInfoAsync(LdapObject ldapUser, LdapUserImporte
Status = ldapUser.IsDisabled ? EmployeeStatus.Terminated : EmployeeStatus.Active,
Title = !string.IsNullOrEmpty(title) ? title : string.Empty,
Location = !string.IsNullOrEmpty(location) ? location : string.Empty,
WorkFromDate = _tenantUtil.DateTimeNow(),
WorkFromDate = tenantUtil.DateTimeNow(),
ContactsList = contacts,
LdapQouta = quota
};

if (!string.IsNullOrEmpty(firstName))
{
user.FirstName = firstName.Length > MAX_NUMBER_OF_SYMBOLS
? firstName.Substring(0, MAX_NUMBER_OF_SYMBOLS)
? firstName[..MAX_NUMBER_OF_SYMBOLS]
: firstName;
}
else
Expand All @@ -191,7 +179,7 @@ public async Task<UserInfo> ToUserInfoAsync(LdapObject ldapUser, LdapUserImporte
if (!string.IsNullOrEmpty(secondName))
{
user.LastName = secondName.Length > MAX_NUMBER_OF_SYMBOLS
? secondName.Substring(0, MAX_NUMBER_OF_SYMBOLS)
? secondName[..MAX_NUMBER_OF_SYMBOLS]
: secondName;
}
else
Expand All @@ -201,17 +189,15 @@ public async Task<UserInfo> ToUserInfoAsync(LdapObject ldapUser, LdapUserImporte

if (!string.IsNullOrEmpty(birthDay))
{
DateTime date;
if (DateTime.TryParse(birthDay, out date))
if (DateTime.TryParse(birthDay, out var date))
{
user.BirthDate = date;
}
}

if (!string.IsNullOrEmpty(gender))
{
bool b;
if (bool.TryParse(gender, out b))
if (bool.TryParse(gender, out var b))
{
user.Sex = b;
}
Expand Down
20 changes: 5 additions & 15 deletions common/ASC.ActiveDirectory/Base/DbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,15 @@
namespace ASC.ActiveDirectory.Base;

[Scope]
public class DbHelper
public class DbHelper(IDbContextFactory<WebstudioDbContext> activeDirectoryDbContextFactory,
LdapSettings ldapSettings)
{
private readonly IDbContextFactory<WebstudioDbContext> _activeDirectoryDbContextFactory;
private readonly LdapSettings _ldapSettings;

public DbHelper(
IDbContextFactory<WebstudioDbContext> activeDirectoryDbContextFactory,
LdapSettings ldapSettings)
{
_activeDirectoryDbContextFactory = activeDirectoryDbContextFactory;
_ldapSettings = ldapSettings;
}

public async Task<List<int>> TenantsAsync()
{
var id = _ldapSettings.ID;
var enableLdapAuthentication = _ldapSettings.EnableLdapAuthentication;
var id = ldapSettings.ID;
var enableLdapAuthentication = ldapSettings.EnableLdapAuthentication;

await using var activeDirectoryDbContext = await _activeDirectoryDbContextFactory.CreateDbContextAsync();
await using var activeDirectoryDbContext = await activeDirectoryDbContextFactory.CreateDbContextAsync();
var data = await activeDirectoryDbContext.WebstudioSettings
.Where(r => r.Id == id)
.Join(activeDirectoryDbContext.Tenants, r => r.TenantId, r => r.Id, (settings, tenant) => new { settings, tenant })
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.ActiveDirectory/Base/Expressions/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ public static Expression Parse(string origin)
return null;
}

var attributeName = origin.Substring(0, index);
var attributeValue = origin.Substring(index + 1);
var attributeName = origin[..index];
var attributeValue = origin[(index + 1)..];

if (string.IsNullOrEmpty(attributeName) || string.IsNullOrEmpty(attributeValue))
{
Expand Down
40 changes: 16 additions & 24 deletions common/ASC.ActiveDirectory/Base/LdapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,15 @@
namespace ASC.ActiveDirectory.Base;

[Scope]
public abstract class LdapHelper : IDisposable
public abstract class LdapHelper(ILogger<LdapHelper> logger,
InstanceCrypto instanceCrypto)
: IDisposable
{
public LdapSettings Settings { get; private set; }
public abstract bool IsConnected { get; }

protected readonly ILogger<LdapHelper> _logger;
protected readonly InstanceCrypto _instanceCrypto;

protected LdapHelper(
ILogger<LdapHelper> logger,
InstanceCrypto instanceCrypto)
{
_logger = logger;
_instanceCrypto = instanceCrypto;
}
protected readonly ILogger<LdapHelper> _logger = logger;
protected readonly InstanceCrypto _instanceCrypto = instanceCrypto;

public void Init(LdapSettings settings)
{
Expand Down Expand Up @@ -95,20 +89,18 @@ public bool UserExistsInGroup(LdapObject domainGroup, LdapObject domainUser, Lda
// Domain Users found
return true;
}
else

var members = domainGroup.GetValues(groupAttribute);

if (members.Count == 0)
{
return false;
}

if (members.Any(member => memberString.Equals(member, StringComparison.InvariantCultureIgnoreCase)
|| member.Equals(domainUser.DistinguishedName, StringComparison.InvariantCultureIgnoreCase)))
{
var members = domainGroup.GetValues(groupAttribute);

if (members.Count == 0)
{
return false;
}

if (members.Any(member => memberString.Equals(member, StringComparison.InvariantCultureIgnoreCase)
|| member.Equals(domainUser.DistinguishedName, StringComparison.InvariantCultureIgnoreCase)))
{
return true;
}
return true;
}
}
catch (Exception e)
Expand Down
Loading

0 comments on commit 811ea9f

Please sign in to comment.