예제 #1
0
 internal void AddLdapAttribut(LdapAttribut ldapAttribut)
 {
     if (ldapAttributs.ContainsKey(ldapAttribut.name))
     {
         ldapAttributs[ldapAttribut.name].AddRange(ldapAttribut.values.ToArray());
     }
     else
     {
         ldapAttributs.Add(ldapAttribut.name, ldapAttribut);
     }
 }
예제 #2
0
        internal String[] GetTabString(String attributName)
        {
            List <String> lstV = new List <string>();

            if (ldapAttributs.ContainsKey(attributName))
            {
                LdapAttribut ldapAttribut = ldapAttributs[attributName];
                return(ldapAttribut.GetTabString());
            }
            return(null);
        }
예제 #3
0
        internal String GetJoinString(String attributName)
        {
            List <String> lstV = new List <string>();

            if (ldapAttributs.ContainsKey(attributName))
            {
                LdapAttribut ldapAttribut = ldapAttributs[attributName];
                return(ldapAttribut.GetJoinString());
            }
            return(String.Empty);
        }
예제 #4
0
 public void AddLdapAttribut(string name, List <string> values)
 {
     if (ldapAttributs != null && !ldapAttributs.ContainsKey(name))
     {
         LdapAttribut ldapAttribut = new LdapAttribut(name, values);
         ldapAttributs.Add(name, ldapAttribut);
     }
     else
     {
         ldapAttributs[name].Add(values);
     }
 }
예제 #5
0
        protected bool IsGroupMember(string dnGroup, string dnUser, string member)
        {
            LdapAttribut ldapAttribut = GetAttributs(dnGroup, member);

            if (ldapAttribut != null)
            {
                List <String> lstValues = ldapAttribut.ExistWithValue(dnUser);
                if (lstValues != null)
                {
                    return(lstValues.Contains(dnUser, StringComparer.OrdinalIgnoreCase));
                }
            }
            return(false);
        }
예제 #6
0
        internal List <string> ExistAttributWithValue(string dn, string attribut, string valeur)
        {
            List <string> lstValue     = new List <string>();
            LdapAttribut  ldapAttribut = GetAttributs(dn, attribut);

            if (ldapAttribut != null)
            {
                return(ldapAttribut.ExistWithValue(valeur));
            }
            else
            {
                return(null);
            }
        }
예제 #7
0
 public void DeleteAttribut(String dn, LdapAttribut ldapAttribut, bool allValues = false)
 {
     if (allValues)
     {
         DeleteAttribut(dn, ldapAttribut.name);
     }
     else
     {
         foreach (byte[] b in ldapAttribut.values)
         {
             DeleteAttribut(dn, ldapAttribut.name, b);
         }
     }
 }
예제 #8
0
 public void ReplaceAttribut(String dn, LdapAttribut ldapAttribut)
 {
     DeleteAttribut(dn, ldapAttribut.name);
     AddAttribut(dn, ldapAttribut);
 }
예제 #9
0
 public void AddAttribut(String dn, LdapAttribut ldapAttribut)
 {
     AddAttribut(dn, ldapAttribut.name, ldapAttribut.values.ToArray());
 }
예제 #10
0
        private List <LdapObj> SearchDn(String baseDn, String ldapFilter, System.DirectoryServices.Protocols.SearchScope scope, String[] attribs)
        {
            List <LdapObj> lstLdapObj = null;

            try
            {
                if (!bindingSuccess)
                {
                    Connect();
                }
                if (attribs != null)
                {
                    for (int i = 0; i < attribs.Length; i++)
                    {
                        attribs[i] = attribs[i].Trim();
                    }
                }
                SearchRequest request;
                if (attribs == null)
                {
                    request = new SearchRequest(baseDn, ldapFilter, scope);
                }
                else
                {
                    request = new SearchRequest(baseDn, ldapFilter, scope, attribs);
                }

                SearchResponse result = (SearchResponse)ldapConnexion.SendRequest(request);
                if ((result != null) && result.Entries.Count > 0)
                {
                    lstLdapObj = new List <LdapObj>();

                    foreach (SearchResultEntry sResult in result.Entries)
                    {
                        String  dn      = sResult.DistinguishedName;
                        LdapObj ldapObj = new LdapObj(dn);
                        if (attribs != null)
                        {
                            foreach (String attr in attribs)
                            {
                                ldapObj.AddLdapAttribut(new LdapAttribut(attr));
                            }
                        }

                        foreach (DirectoryAttribute attribute in sResult.Attributes.Values)
                        {
                            /*Console.WriteLine(attribute.Name + " ==> " + attribute.Count);
                             * if (attribute.Name.Equals("objectClass"))
                             *  Console.WriteLine(attribute.Name + " ==> " + attribute.Count);
                             */
                            LdapAttribut ldapAttribut = new LdapAttribut(attribute.Name);
                            ldapAttribut.AddRange((byte[][])attribute.GetValues(typeof(byte[])));
                            ldapObj.AddLdapAttribut(ldapAttribut);
                        }
                        lstLdapObj.Add(ldapObj);
                    }
                }
                return(lstLdapObj);
            }
            catch (LdapException ex)
            {
                Console.WriteLine(String.Format("Error LdapException FindPeDateMajCert {0}...", ex.Message));
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
            catch (DirectoryOperationException ex)
            {
                Console.WriteLine(String.Format("Error DirectoryOperationException FindPeDateMajCert {0}...", ex.Message));
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Error Exception FindPeDateMajCert {0}...", ex.Message));
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
        }