zoukankan      html  css  js  c++  java
  • csharp

     1 DirectoryEntry de = new DirectoryEntry("LDAP://10.10.10.10:389");
     2             DirectorySearcher searcher = new DirectorySearcher(de, string.Format("(&(objectClass=user)(samAccountName={0}))", "A00106"));
     3             SearchResultCollection src = searcher.FindAll();
     4             foreach (SearchResult rs in src)
     5             {
     6                 if (rs != null)
     7                 {
     8                     string n = (rs.GetDirectoryEntry().Properties["distinguishedName"].Value == null) ? string.Empty : rs.GetDirectoryEntry().Properties["distinguishedName"].Value.ToString();
     9                     if (n.IndexOf("OU") != -1)
    10                     {
    11                         //displayName,sAMAccountName,name,mail
    12                         string email = (rs.GetDirectoryEntry().Properties["mail"].Value == null) ? string.Empty : rs.GetDirectoryEntry().Properties["mail"].Value.ToString();
    13                     }
    14                 }
    15             }
    // verify user / password
    
    private string GetEmployeeIDByLDAP(string userName, string password)
            { // TODO: Extract
                DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://66.66.66.66:389") 
                {
                    Username = userName,
                    Password = password,
                    AuthenticationType = AuthenticationTypes.Secure
                };
                try
                {
                    DirectorySearcher searcher = new DirectorySearcher(directoryEntry)
                    {
                        Filter = string.Format("(&(objectClass=user)(samAccountName={0}))", userName)
                    };
                    SearchResult result = searcher.FindOne();
                    if (result != null)
                    {
                        string empid = result.Properties["name"][0].ToString();
                        return empid;
                    }
                }
                catch (Exception err)
                {
                    _logger.Error(err);
                }
    
                return string.Empty;
            }
  • 相关阅读:
    PythonStudy——greenlet 协程
    PythonStudy——事件 Event
    PythonStudy——单线程并发的实现
    2015年的总结
    kylin一种OLAP的实现
    分布式消息队列的使用kakfa
    第一次听到了docker
    Hive分布式的数据仓库
    dubbo服务框架学习
    Storm实时计算框架的编程模式
  • 原文地址:https://www.cnblogs.com/dufu/p/8436223.html
Copyright © 2011-2022 走看看