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

Make Volo.Abp.Ldap support multi-tenancy. #4984

Merged
merged 6 commits into from
Aug 9, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions framework/src/Volo.Abp.Ldap/Volo.Abp.Ldap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="2.3.8" />
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="3.2.0" />
</ItemGroup>


<ItemGroup>
<Content Remove="Volo\Abp\Ldap\Localization\*.json" />
<EmbeddedResource Include="Volo\Abp\Ldap\Localization\*.json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" />
<ProjectReference Include="..\Volo.Abp.Settings\Volo.Abp.Settings.csproj" />
<ProjectReference Include="..\Volo.Abp.VirtualFileSystem\Volo.Abp.VirtualFileSystem.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.Options;
using Volo.Abp.Settings;
using Volo.Abp.Threading;

namespace Volo.Abp.Ldap
{
public class AbpAbpLdapOptionsFactory : AbpOptionsFactory<AbpLdapOptions>
{
protected ISettingProvider SettingProvider { get; }

public AbpAbpLdapOptionsFactory(
IEnumerable<IConfigureOptions<AbpLdapOptions>> setups,
IEnumerable<IPostConfigureOptions<AbpLdapOptions>> postConfigures,
ISettingProvider settingProvider)
: base(setups, postConfigures)
{
SettingProvider = settingProvider;
}

public override AbpLdapOptions Create(string name)
{
var options = base.Create(name);

AsyncHelper.RunSync(() => OverrideOptionsAsync(options));

return options;
}

protected virtual async Task OverrideOptionsAsync(AbpLdapOptions options)
{
options.ServerHost = await GetSettingOrDefaultValue(LdapSettingNames.ServerHost, options.ServerHost);
options.ServerPort = await SettingProvider.GetAsync(LdapSettingNames.ServerPort, options.ServerPort);
options.UserName = await GetSettingOrDefaultValue(LdapSettingNames.UserName, options.UserName);
options.Password = await GetSettingOrDefaultValue(LdapSettingNames.Password, options.Password);
}

protected virtual async Task<string> GetSettingOrDefaultValue(string name, string defaultValue)
{
var value = await SettingProvider.GetOrNullAsync(name);
return value.IsNullOrWhiteSpace() ? defaultValue : value;
}
}
}
38 changes: 32 additions & 6 deletions framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapModule.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Volo.Abp.Ldap.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Settings;
using Volo.Abp.VirtualFileSystem;

namespace Volo.Abp.Ldap
{
[DependsOn(
typeof(AbpAutofacModule)
)]
typeof(AbpSettingsModule),
typeof(AbpVirtualFileSystemModule),
typeof(AbpLocalizationModule))]
public class AbpLdapModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.Replace(ServiceDescriptor.Transient<IOptionsFactory<AbpLdapOptions>, AbpAbpLdapOptionsFactory>());
context.Services.Replace(ServiceDescriptor.Scoped<IOptions<AbpLdapOptions>, OptionsManager<AbpLdapOptions>>());

var configuration = context.Services.GetConfiguration();
Configure<AbpLdapOptions>(configuration.GetSection("LDAP"));
var ldapConfiguration = configuration["Ldap"];
if (!ldapConfiguration.IsNullOrEmpty())
{
Configure<AbpLdapOptions>(configuration.GetSection("Ldap"));
}

Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpLdapModule>();
});

Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Add<LdapResource>("en")
.AddVirtualJson("/Volo/Abp/Ldap/Localization");
});
}
}
}
}
17 changes: 3 additions & 14 deletions framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpLdapOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@ public class AbpLdapOptions

public int ServerPort { get; set; }

public bool UseSsl { get; set; }
public string UserName { get; set; }

public string SearchBase { get; set; }

public string DomainName { get; set; }

public string DomainDistinguishedName { get; set; }

public LdapCredentials Credentials { get; set; }

public AbpLdapOptions()
{
Credentials = new LdapCredentials();
}
public string Password { get; set; }
}
}
}

This file was deleted.

67 changes: 6 additions & 61 deletions framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/ILdapManager.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,17 @@
using System.Collections.Generic;
using Volo.Abp.Ldap.Modeling;

namespace Volo.Abp.Ldap
namespace Volo.Abp.Ldap
{
public interface ILdapManager
{
/// <summary>
/// query the specified organizations.
///
/// filter: (&(name=xxx)(objectClass=organizationalUnit)) when name is not null
/// filter: (&(name=*)(objectClass=organizationalUnit)) when name is null
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
IList<LdapOrganization> GetOrganizations(string name = null);

/// <summary>
/// query the specified organization.
///
/// filter: (&(distinguishedName=xxx)(objectClass=organizationalUnit)) when organizationName is not null
///
/// Authenticate with default username/password
/// </summary>
/// <param name="distinguishedName"></param>
/// <returns></returns>
LdapOrganization GetOrganization(string distinguishedName);

void AddSubOrganization(string organizationName, LdapOrganization parentOrganization);
void AddSubOrganization(string organizationName, string parentDistinguishedName);

/// <summary>
/// query the specified users.
///
/// filter: (&(name=xxx)(objectCategory=person)(objectClass=user)) when name is not null
/// filter: (&(name=*)(objectCategory=person)(objectClass=user)) when name is null
///
/// filter: (&(displayName=xxx)(objectCategory=person)(objectClass=user)) when displayName is not null
/// filter: (&(displayName=*)(objectCategory=person)(objectClass=user)) when displayName is null
///
/// filter: (&(cn=xxx)(objectCategory=person)(objectClass=user)) when commonName is not null
/// filter: (&(cn=*)(objectCategory=person)(objectClass=user)) when commonName is null
///
/// </summary>
/// <param name="name"></param>
/// <param name="displayName"></param>
/// <param name="commonName"></param>
/// <returns></returns>
IList<LdapUser> GetUsers(string name = null, string displayName = null, string commonName = null);

/// <summary>
/// query the specified User.
///
/// filter: (&(distinguishedName=xxx)(objectCategory=person)(objectClass=user)) when distinguishedName is not null
///
/// </summary>
/// <param name="distinguishedName"></param>
/// <returns></returns>
LdapUser GetUser(string distinguishedName);

void AddUserToOrganization(string userName, string password, LdapOrganization parentOrganization);
void AddUserToOrganization(string userName, string password, string parentDistinguishedName);
bool Authenticate();

/// <summary>
/// Authenticate
/// Authenticate with specified username/password
/// </summary>
/// <param name="userDomainName">E.g [email protected] </param>
/// <param name="password"></param>
/// <returns></returns>
bool Authenticate(string userDomainName, string password);
bool Authenticate(string username, string password);
}
}
}
9 changes: 0 additions & 9 deletions framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapCredentials.cs

This file was deleted.

34 changes: 0 additions & 34 deletions framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapHelps.cs

This file was deleted.

Loading