Cosmokey.Helper.LDAP
1.0.0
dotnet add package Cosmokey.Helper.LDAP --version 1.0.0
NuGet\Install-Package Cosmokey.Helper.LDAP -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cosmokey.Helper.LDAP" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cosmokey.Helper.LDAP --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Cosmokey.Helper.LDAP, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Cosmokey.Helper.LDAP as a Cake Addin
#addin nuget:?package=Cosmokey.Helper.LDAP&version=1.0.0
// Install Cosmokey.Helper.LDAP as a Cake Tool
#tool nuget:?package=Cosmokey.Helper.LDAP&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
1.配置
1.1.基础配置
LDAPSetting setting = new LDAPSetting();
setting.Connection.Add("172.0.0.1");
setting.Connection.Add("172.0.0.2");
setting.Connection.Add("172.0.0.3");
setting.HasSSL = true;
setting.AdminDN = "cn=AdAdmin,dc=mydomain,dc=com";
setting.AdminPassword = "P@ssword";
setting.DomainDN = "dc=mydomain,dc=com";
setting.DefaultGroup = "500";
setting.UserHomeDirectory = "/home/users/{0}";
setting.ConnectionTimeout = 500;
setting.GroupMemberAttributeName = "memberUid";
1.2.实体与AD映射关系
setting.OUMapping.Add("Name", new List<string>() { "ou" });
setting.OUMapping.Add("ObjectClass", new List<string>() { "organizationalUnit" });
setting.OUMapping.Add("Prefix", new List<string>() { "ou" });
setting.OUMapping.Add("DN", new List<string>() { "dn" });
setting.OUMapping.Add("Description", new List<string>() { "description" });
setting.UserMapping.Add("Name", new List<string>() { "cn", "uid", "sn" });
setting.UserMapping.Add("ObjectClass", new List<string>() { "posixAccount", "inetOrgPerson" });
setting.UserMapping.Add("Prefix", new List<string>() { "cn" });
setting.UserMapping.Add("UserID", new List<string>() { "uidNumber" });
setting.UserMapping.Add("Password", new List<string>() { "userPassword" });
setting.UserMapping.Add("Description", new List<string>() { "description" });
setting.GroupMapping.Add("Name", new List<string>() { "cn" });
setting.GroupMapping.Add("ObjectClass", new List<string>() { "posixGroup" });
setting.GroupMapping.Add("Prefix", new List<string>() { "cn" });
setting.GroupMapping.Add("Gid", new List<string>() { "gidNumber" });
setting.GroupMapping.Add("Description", new List<string>() { "description" });
1.3.日志
LDAPLogEvent logEvent = new LDAPLogEvent();
logEvent.LogDebugEvent += (arg1, arg2) => { Console.WriteLine("Debug:" + arg1); };
logEvent.LogInfoEvent += (arg1, arg2) => { Console.WriteLine("Info:" + arg1); };
logEvent.LogWarningEvent += (arg1, arg2) => { Console.WriteLine("Warning:" + arg1); };
logEvent.LogErrorEvent += (arg1, arg2) => { Console.WriteLine("Error:" + arg1); };
2.扩展实体
public class LdapOU2 : LDAPOu
{
public string? Description { get; set; }
}
public class LdapUser2 : LDAPUser
{
public string? Description { get; set; }
}
public class LdapGroup2 : LDAPGroup
{
public string? Description { get; set; }
}
3.使用
3.1.构建实例
LDAPHelper helper = new LDAPHelper(setting, logEvent);
3.2.组织操作
3.2.1.创建
helper.CreateOu("OU1", new LdapOU2() { Name = "OUTemp_" + tmp, Description = "OUDescriptionTemp_" + tmp });
3.2.2.移动/改名
helper.RenameOrMoveOu("OU1", "OUTemp_" + tmp, newName: "OU_" + tmp);
helper.RenameOrMoveOu("OU1", "OU_" + tmp, parentNewPath: "OU1/OU11");
3.2.3.修改
helper.UpdateOu("OU1/OU11", "OU_" + tmp, new LdapOU2() { Description = "OUDescription_" + tmp }, new List<string>() { "Description" });
3.2.4.搜索/获取
helper.GetOU("OU1/OU11", "OU111");
helper.SearchOu("OU11", "ou=OU1,dc=mydomain,dc=com");
3.2.5.获取下属部门/用户
helper.GetOu_ScopeOne("OU1/OU11")
helper.GetUser_ScopeOne("OU1/OU11")
3.2.6.删除
helper.DeleteOu("OU1/OU11", "OU_" + tmp);
3.3.用户操作
3.3.1.登录
helper.Login($"cn=ping, ou=OU1,dc=mydomain,dc=com", "p@ssword");
helper.Login("ping", "p@ssword");
3.3.2.创建
LdapUser2 user = new LdapUser2()
{
Name = "UserTemp_" + tmp,
UserID = (long)(DateTime.Now - new DateTime(1900, 1, 1)).TotalSeconds,
Password = new LDAPPassword() { Password = "12!@$%^&()rerwrwe3123" },
Description = "UserDescriptionTemp_" + tmp
};
helper.CreateUser("OU1", user);
3.3.3.移动/改名
helper.RenameOrMoveUser("OU1", "UserTemp_" + tmp, newName: "User_" + tmp);
helper.RenameOrMoveUser("OU1", "User_" + tmp, parentNewPath: "OU1/OU11/OU_" + tmp);
3.3.4.修改
helper.UpdateUser("OU1/OU11/OU_" + tmp, "User_" + tmp, new LdapUser2() { Description = "UserDescription_" + tmp }, new List<string>() { "Description" });
3.3.5.搜索/获取
helper.GetUser("OU1/OU11", "ping");
helper.SearchUser("ping", "ou=OU1,dc=mydomain,dc=com");
3.3.6.删除
helper.DeleteUser("User_" + tmp);
3.4.群组操作
3.4.1.创建
helper.CreateGroup("OU1", new LdapGroup2() { Name = "GroupTemp_" + tmp, Description = "GroupDescriptionTemp_" + tmp, Gid=Convert.ToInt32(tmp)});
3.4.2.移动/改名
helper.RenameOrMoveGroup("OU1", "GroupTemp_" + tmp, newName: "Group_" + tmp);
helper.RenameOrMoveGroup("OU1", "Group_" + tmp, parentNewPath: "OU1/OU11/OU_" + tmp);
3.4.3.修改
helper.UpdateGroup("OU1/OU11/OU_" + tmp, "Group_" + tmp, new LdapGroup2() { Description = "GroupDescription_" + tmp }, new List<string>() { "Description" });
3.4.4.搜索/获取
helper.GetGroup("Group_" + tmp);
helper.SearchGroup("Group_" + tmp);
3.4.5.群组成员操作
helper.GetGroupMember("OU1/OU11/OU_" + tmp + "/Group_" + tmp);
helper.GroupAddUser("OU1/OU11/OU_" + tmp + "/Group_" + tmp, "User_" + tmp);
helper.GroupRemoveUser("OU1/OU11/OU_" + tmp + "/Group_" + tmp, "User_" + tmp);
3.4.6.删除
helper.DeleteGroup("OU1/OU11/OU_" + tmp, "Group_" + tmp);
4.所有接口
4.1.监控
Dictionary<string, LDAPConnectStatus> Monitor()
4.2.组织
4.2.1.组织--泛型
IEnumerable<T>? SearchOu<T>(string search, string targetDn) where T : LDAPOu
IEnumerable<T>? SearchOu<T>(string search) where T : LDAPOu
IEnumerable<T>? GetOu_ScopeOne<T>(string parentPath) where T : LDAPOu
IEnumerable<T>? GetOu_ScopeSub<T>(string parentPath) where T : LDAPOu
T? GetOu<T>(string parentPath, string? name) where T : LDAPOu
T? GetOu<T>(string fullPath) where T : LDAPOu
bool CreateOu<T>(string parentPath, T entity) where T : LDAPOu
bool UpdateOu<T>(string parentPath,string name, T entity, List<string>? change = null) where T : LDAPOu
4.2.2.组织--固定LDAPOu类型
IEnumerable<LDAPOu>? SearchOu(string search)
IEnumerable<LDAPOu>? SearchOu(string search, string targetDn)
IEnumerable<LDAPOu>? GetOu_ScopeOne(string parentPath)
IEnumerable<LDAPOu>? GetOu_ScopeSub(string parentPath)
LDAPOu? GetOu(string parentPath, string? name)
LDAPOu? GetOu(string fullPath)
bool RenameOrMoveOu(string parentOldPath, string oldName, string? parentNewPath = null, string? newName = null)
bool DeleteOu(string parentPath, string name)
4.3.用户
4.3.1.用户--泛型
IEnumerable<T>? SearchUser<T>(string search) where T : LDAPUser
IEnumerable<T>? SearchUser<T>(string search, string targetDn) where T : LDAPUser
IEnumerable<T>? GetUser_ScopeOne<T>(string parentPath) where T : LDAPUser
IEnumerable<T>? GetUser_ScopeSub<T>(string parentPath) where T : LDAPUser
T? GetUser<T>(string parentPath, string? name) where T : LDAPUser
T? GetUser<T>(string fullPath) where T : LDAPUser
bool CreateUser<T>(string parentPath, T entity) where T : LDAPUser
bool UpdateUser<T>(string parentPath, string name, T entity, List<string>? change = null) where T : LDAPUser
4.3.2.用户--固定LDAPUser类型
IEnumerable<LDAPUser>? SearchUser(string search)
IEnumerable<LDAPUser>? SearchUser(string search, string targetDn)
IEnumerable<LDAPUser>? GetUser_ScopeOne(string parentPath)
IEnumerable<LDAPUser>? GetUser_ScopeSub(string parentPath)
LDAPUser? GetUser(string parentPath, string? name)
LDAPUser? GetUser(string fullPath)
bool RenameOrMoveUser(string parentOldPath, string oldName, string? parentNewPath = null, string? newName = null)
bool ChangePassword(string parentPath, string name, string password)
bool DeleteUser(string name)
4.4.群组
4.4.1.群组--泛型
IEnumerable<T>? SearchGroup<T>(string search) where T : LDAPGroup
IEnumerable<T>? SearchGroup<T>(string search, string targetDn) where T : LDAPGroup
T? GetGroup<T>(string parentPath, string? name) where T : LDAPGroup
T? GetGroup<T>(string fullPath) where T : LDAPGroup
bool CreateGroup<T>(string parentPath, T entity) where T : LDAPGroup
bool UpdateGroup<T>(string parentPath, string name, T entity, List<string>? change = null) where T : LDAPGroup
4.4.2.群组--固定LDAPGroup类型
IEnumerable<LDAPGroup>? SearchGroup(string search)
IEnumerable<LDAPGroup>? SearchGroup(string search, string targetDn)
IEnumerable<LDAPGroup>? GetGroup_ScopeOne(string parentPath)
IEnumerable<LDAPGroup>? GetGroup_ScopeSub(string parentPath)
LDAPGroup? GetGroup(string parentPath, string? name)
LDAPGroup? GetGroup(string fullPath)
bool RenameOrMoveGroup(string parentOldPath, string oldName, string? parentNewPath = null, string? newName = null)
bool DeleteGroup(string parentPath, string name)
List<string>? GetGroupMember(string path)
bool GroupAddUser(string path, string user)
bool GroupRemoveUser(string path, string user)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Novell.Directory.Ldap.NETStandard (>= 3.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 518 | 7/6/2022 |