Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UseSsl LDAP setting to support LDAPS #6655

Merged
merged 1 commit into from Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Abp.Zero.Ldap/Ldap/Authentication/LdapAuthenticationSource.cs
Expand Up @@ -147,15 +147,33 @@ protected virtual Task<PrincipalContext> CreatePrincipalContext(TTenant tenant,

protected virtual async Task<PrincipalContext> CreatePrincipalContext(TTenant tenant)
{
var useSsl = await _settings.GetUseSsl(tenant?.Id);
var contextType = await _settings.GetContextType(tenant?.Id);

var options = useSsl
? ContextOptions.SecureSocketLayer | ContextOptions.Negotiate
: GetDefaultOptionForStore(contextType);

return new PrincipalContext(
await _settings.GetContextType(tenant?.Id),
contextType,
ConvertToNullIfEmpty(await _settings.GetDomain(tenant?.Id)),
ConvertToNullIfEmpty(await _settings.GetContainer(tenant?.Id)),
options,
ConvertToNullIfEmpty(await _settings.GetUserName(tenant?.Id)),
ConvertToNullIfEmpty(await _settings.GetPassword(tenant?.Id))
);
}

private ContextOptions GetDefaultOptionForStore(ContextType contextType)
{
if (contextType == ContextType.Machine)
{
return ContextOptions.Negotiate;
}

return ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing;
}

protected virtual async Task CheckIsEnabled(TTenant tenant)
{
if (!_ldapModuleConfig.IsEnabled)
Expand All @@ -178,4 +196,4 @@ protected static string ConvertToNullIfEmpty(string str)
: str;
}
}
}
}
2 changes: 2 additions & 0 deletions src/Abp.Zero.Ldap/Ldap/Configuration/ILdapSettings.cs
Expand Up @@ -20,5 +20,7 @@ public interface ILdapSettings
Task<string> GetUserName(int? tenantId);

Task<string> GetPassword(int? tenantId);

Task<bool> GetUseSsl(int? tenantId);
}
}
5 changes: 5 additions & 0 deletions src/Abp.Zero.Ldap/Ldap/Configuration/LdapSettingNames.cs
Expand Up @@ -34,5 +34,10 @@ public static class LdapSettingNames
/// Abp.Zero.Ldap.Password
/// </summary>
public const string Password = "Abp.Zero.Ldap.Password";

/// <summary>
/// Abp.Zero.Ldap.UseSsl
/// </summary>
public const string UseSsl = "Abp.Zero.Ldap.UseSsl";
}
}
7 changes: 7 additions & 0 deletions src/Abp.Zero.Ldap/Ldap/Configuration/LdapSettings.cs
Expand Up @@ -60,5 +60,12 @@ public virtual Task<string> GetPassword(int? tenantId)
? SettingManager.GetSettingValueForTenantAsync(LdapSettingNames.Password, tenantId.Value)
: SettingManager.GetSettingValueForApplicationAsync(LdapSettingNames.Password);
}

public Task<bool> GetUseSsl(int? tenantId)
{
return tenantId.HasValue
? SettingManager.GetSettingValueForTenantAsync<bool>(LdapSettingNames.UseSsl, tenantId.Value)
: SettingManager.GetSettingValueForApplicationAsync<bool>(LdapSettingNames.UseSsl);
}
}
}