Ejemplo n.º 1
0
        public NovellUser Connect(string login, string password)
        {
            bool       res  = false;
            NovellUser user = new NovellUser();

            foreach (var serverAddress in ServerAddresses)
            {
                message += serverAddress;
                try
                {
                    using (NovellProvider novell = new NovellProvider(serverAddress, 636))
                    {
                        novell.Connect();
                        novell.Bind(Properties.Settings.Default.NovellDN, Properties.Settings.Default.NovellPassword);
                        user = novell.Search(login);
                        res  = novell.VerifyPassword(user.DN, password);
                        break;
                        //res = novell.CheckWorldPassword(login, password);

                        //if (res == false)
                        //{
                        //    res = novell.CheckAlienPassword(login, password);

                        //    if (res == false)
                        //    {
                        //        break;
                        //    }
                        //}
                        //if (res == true)
                        //{
                        //    novell.Bind();
                        //    user = novell.Find(login);
                        //    break;
                        //}


                        //novell.Connect()
                    }
                }
                catch (Exception e)
                {
                    //  message += " exc in novell provider, continue ";
                    //when ip address doesn't response - there will be exception
                    //continue;
                    //throw new NovelleDirectoryException("Cannot connect to Novell eDirectory");
                }
            }
            if (res == false)
            {
                throw new NovelleDirectoryException(message);
            }
            if (user.CN == null || user.CN == "")
            {
                throw new NovelleDirectoryException(message);
            }
            return(user);
        }
Ejemplo n.º 2
0
            public NovellUser Search(string login)
            {
                //NovellUser user = new NovellUser();
                //LdapSearchResults lsc = Connection.Search(searchBase,
                //                                    LdapConnection.SCOPE_SUB,
                //                                    searchFilter,
                //                                    null,
                //                                    false);
                //while (lsc.hasMore())
                //{
                //    LdapEntry nextEntry = null;
                //    try
                //    {
                //        nextEntry = lsc.next();
                //    }
                //    catch (LdapException e)
                //    {
                //        Console.WriteLine("Error: " + e.LdapErrorMessage);
                //        // Exception is thrown, go for next entry
                //        continue;
                //    }
                //    user.DN = nextEntry.DN;
                //    user.CN = nextEntry.getAttribute("cn").StringValue;

                //    user.Attributes = new Dictionary<string, string[]>();

                //    LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
                //    System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
                //    while (ienum.MoveNext())
                //    {
                //        LdapAttribute attribute = (LdapAttribute)ienum.Current;
                //        string attributeName = attribute.Name;
                //        string attributeVal = attribute.StringValue;
                //        if (!Base64.isLDIFSafe(attributeVal))
                //        {
                //            byte[] tbyte = SupportClass.ToByteArray(attributeVal);
                //            attributeVal = Base64.encode(SupportClass.ToSByteArray(tbyte));
                //        }
                //        user.Attributes.Add(attributeName, new string[] { attributeVal });
                //    }
                //}



                //return user;


                //search base должен быть заполнен
                //как сделать ИЛИ или И (o=world && o=alien) не знаю

                NovellUser user = new NovellUser();

                user.Attributes = new Dictionary <string, string[]>();
                SearchRequest r = new SearchRequest(
                    "o=world",
                    "cn=" + login,
                    System.DirectoryServices.Protocols.SearchScope.Subtree,
                    "*");
                SearchResponse re = (SearchResponse)connection.SendRequest(r);

                if (re.Entries.Count == 0)
                {
                    r = new SearchRequest(
                        "o=alien",
                        "cn=" + login,
                        System.DirectoryServices.Protocols.SearchScope.Subtree,
                        "*");

                    re = (SearchResponse)connection.SendRequest(r);
                }
                user.DN = re.Entries[0].DistinguishedName;
                foreach (byte[] item in re.Entries[0].Attributes["cn"])
                {
                    user.CN = System.Text.Encoding.Default.GetString(item);
                }

                foreach (SearchResultEntry i in re.Entries)
                {
                    foreach (string attrName in i.Attributes.AttributeNames)
                    {
                        List <String> attrs = new List <string>();
                        foreach (byte[] item in re.Entries[0].Attributes["cn"])
                        {
                            attrs.Add(System.Text.Encoding.Default.GetString(item));
                        }
                        user.Attributes.Add(attrName, attrs.ToArray());
                    }
                }


                //while (lsc.hasMore())
                //{
                //    LdapEntry nextEntry = null;
                //    try
                //    {
                //        nextEntry = lsc.next();
                //    }
                //    catch (LdapException e)
                //    {
                //        Console.WriteLine("Error: " + e.LdapErrorMessage);
                //        // Exception is thrown, go for next entry
                //        continue;
                //    }
                //    user.DN = nextEntry.DN;
                //    user.CN = nextEntry.getAttribute("cn").StringValue;

                //    user.Attributes = new Dictionary<string, string[]>();

                //    LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
                //    System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
                //    while (ienum.MoveNext())
                //    {
                //        LdapAttribute attribute = (LdapAttribute)ienum.Current;
                //        string attributeName = attribute.Name;
                //        string attributeVal = attribute.StringValue;
                //        if (!Base64.isLDIFSafe(attributeVal))
                //        {
                //            byte[] tbyte = SupportClass.ToByteArray(attributeVal);
                //            attributeVal = Base64.encode(SupportClass.ToSByteArray(tbyte));
                //        }
                //        user.Attributes.Add(attributeName, new string[] { attributeVal });
                //    }
                //}
                return(user);
            }