我正在尝试配置.Net Core 2.0应用程序,以使用户能够使用Novel LDAP程序包更改密码。但是,LdapConnection.Modify方法将引发以下错误。
错误:LdapException:无效的DN语法(34)无效的DN语法 LdapException:服务器消息:0000208F:NameErr:DSID-03100225, 问题2006(BAD_NAME),数据8349,最佳匹配项:
'(&(objectCategory=Person)(sAMAccountName=*)(memberOf=cn=CaptainPlanet,ou=users,dc=company,dc=com))'
我知道过滤器是可以的,因为我能够在powershell中运行它,如下所示
Get-ADObject –LDAPFilter "(&(objectCategory=Person)(sAMAccountName=*)(memberOf=cn=CaptainPlanet,ou=users,dc=company,dc=com))"
这是我的LDAP代码
public class DomainController
{
...
public static void WithLdapConnection(Action<ILdapConnection> actionOnConnectedLdapConnection)
{
using (var ldapConnection = new LdapConnection())
{
ldapConnection.Connect(_server.Address, _server.Port);
actionOnConnectedLdapConnection(ldapConnection);
}
}
public static void WithAuthenticatedLdapConnection(Action<ILdapConnection> actionOnAuthenticatedLdapConnection)
{
WithLdapConnection(ldapConnection =>
{
ldapConnection.Bind(_server.RootUserDn, _server.RootUserPassword);
actionOnAuthenticatedLdapConnection(ldapConnection);
});
}
}
这是调用方法
public class UpdateUserCommand : ICommand
{
...
public void UpdateActiveDirectory(string newPassword)
{
DomainController.WithAuthenticatedLdapConnection(lc =>
{
LdapAttribute attributePassword = new LdapAttribute( "userPassword", newPassword);
lc.Modify( modifyDN, new LdapModification(
LdapModification.REPLACE, attributePassword) );
});
_logger.LogInformation("AD Account: Updated");
}
...
}
有人可以告诉我这是怎么回事吗?