参照Hunter的ABP-Zero模块中用户管理部分。

  由于我们公司的各系统基本都是AD帐号登录的,所以我们需扩展ABP的AuthenticationSource。

  • 添加MyLdapAuthenticationSource.cs及MyLdapSettings.cs

  Core层的Authorization目录下新建Ldap目录,并新建两个MyLdapAuthenticationSource.csMyLdapSettings.cs,代码如下:

  MyLdapAuthenticationSource.cs

public  class MyLdapAuthenticationSource : LdapAuthenticationSource<Tenant, User>
{
public MyLdapAuthenticationSource(ILdapSettings settings, IAbpZeroLdapModuleConfig ldapModuleConfig)
: base(settings, ldapModuleConfig)
{
}
}

  

  LdapAuthenticationSource的构造函数需要两个参数:ILdapSettings及IAbpZeroLdapModuleConfig,我们构造自己的MyLdapSettings:

  MyLdapSettings.cs

public class MyLdapSettings : ILdapSettings
{
private const string DomainName = "XXXX.com";
private const string Container = "OU=XXX,DC=XXXX,DC=com";
private const string UserName = "XXXX";
private const string Password = "XXXX";
private const string ADPath = "LDAP://XXXXX"; public async Task<bool> GetIsEnabled(int? tenantId)
{
return true;
} public async Task<ContextType> GetContextType(int? tenantId)
{ return ContextType.Domain;
} public async Task<string> GetContainer(int? tenantId)
{
return Container;
} public async Task<string> GetDomain(int? tenantId)
{
return DomainName;
} public async Task<string> GetUserName(int? tenantId)
{
return UserName;
} public async Task<string> GetPassword(int? tenantId)
{
return Password;
}
}

  

  • 在CoreModule中启用

  这里ILdapSettings我们使用MyLdapSettings来注册,但是IAbpZeroLdapModuleConfig使用默认的即可。

[DependsOn(typeof(AbpZeroCoreModule))]
public class CeciCoreModule : AbpModule
{
public override void PreInitialize()
{
Configuration.Auditing.IsEnabledForAnonymousUsers = true; IocManager.Register<IAbpZeroLdapModuleConfig, AbpZeroLdapModuleConfig>();
IocManager.Register<ILdapSettings, MyLdapSettings>(); //change default setting source
Configuration.Modules.ZeroLdap().Enable(typeof(MyLdapAuthenticationSource));
  • 重载认证逻辑

  目前我们只使用了Ldap最简逻辑,如需要复杂逻辑(如从AD中获得用户部门职位等),需重载LdapAuthenticationSource的方法来自定义实现。

  

最新文章

  1. UVa 112 - Tree Summing(树的各路径求和,递归)
  2. [排错] Status error 2850
  3. 淘宝PHPSDK2.0 剔除 lotusphp框架---兄弟连教程
  4. 零基础Android学习笔记-02 安卓程序生命周期
  5. sourceTree添加git密钥步骤
  6. MongoDB的数据类型
  7. 51cto运维培训课程
  8. CSS3 三角形运用
  9. [Swift]LeetCode796. 旋转字符串 | Rotate String
  10. TT-付款方式
  11. 【转载】 强化学习(八)价值函数的近似表示与Deep Q-Learning
  12. MySQL记录-Lost Connect MySQL Server during query解决方案
  13. (转) 干货 | 图解LSTM神经网络架构及其11种变体(附论文)
  14. 2018 Multi-University Training Contest 6 Solution
  15. Java中23种经典设计模式详解
  16. 设计模式--访问者模式C++实现
  17. 解决问题:zipimport.ZipImportError: can't decompress data; zlib not available
  18. Vee-validate学习
  19. TCP粘包处理通用框架--C代码
  20. 【原创】最有效解决IE8 position兼容性问题

热门文章

  1. 团队项目(HCL队)第二周
  2. EBS查找当前Form文件
  3. 使用 Project Siena 生成一个 Windows Store 应用
  4. mac下的抓包工具 -- Charles
  5. RabbitMQ 消息队列 DEMO
  6. C# 32位程序,申请大内存,附dome(wpf),亲测可用
  7. 《ASP.NET MVC 5 破境之道》:第一境 ASP.Net MVC5项目初探 — 第二节:MVC5项目结构
  8. JS时间戳转时间格式
  9. java入门——面向对象
  10. grafana 运行