private static HtmlDescriptionsCache.AttributeDescription GetAttributeDescription(string shortName)
 {
     HtmlDescriptionsCache.AttributeDescription attributeDescription;
     if (shortName.StartsWith("data-"))
     {
         shortName = shortName.Substring("data-".Length);
     }
     AttributeDescriptions.TryGetValue(shortName, out attributeDescription);
     return(attributeDescription);
 }
        /*
         * first time running this by just changing the filter a little i got this message.
         * There was an error generating the XML document. ---> System.InvalidOperationException:
         * Value of ItemElementName mismatches the type of DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.SubstringFilter;
         * you need to set it to DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.ItemChoiceType.@substrings.
         *
         *
         * System.InvalidOperationException: There was an error generating the XML document. --->
         * System.InvalidOperationException: Value of ItemElementName mismatches the type of DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.SubstringFilter;
         * you need to set it to DirectorySearchBusinessLogicLayer.gov.ny.svc.daws.ItemChoiceType.@substrings.
         *
         *
         * The next time I changed out the ava filter for a substring type and got this message
         * Error Response
         * [LDAP: error code 50 - Search filter not permitted (substring too short)]
         */
        public IEnumerable <NyGovUser> GetUsers(String ou)
        {
            GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);
            List <NyGovUser> returnList = new List <NyGovUser>();
            //example OU ||||   dn =”ou = Department of General Services,ou = Government,o = ny,c = us
            BatchRequest     batch  = new BatchRequest();
            SearchRequest    search = new SearchRequest();
            Filter           filter = new Filter();
            dsmlQueryService client = new dsmlQueryService();

            client.Url          = "https://qadaws.svc.ny.gov/daws/services/dsmlSoapQuery";
            batch.searchRequest = new SearchRequest[1] {
                search
            };
            client.Credentials = new NetworkCredential("prxwsTL1HESC", "sfvwRMnB7N");
            search.dn          = "'ou = Department of General Services,ou = Government,o = ny,c = us'";
            //search.dn = ou;

            //can't use attribute value assertion for substring choice.  instead make substring filter
            //AttributeValueAssertion ava = new AttributeValueAssertion();
            //ava.name = "nyacctgovernment";
            //ava.value = "Y";
            SubstringFilter[] substrings = new SubstringFilter[4];
            SubstringFilter   substring  = new SubstringFilter();

            substring.name    = "nyacctgovernment";
            substring.initial = "Y";
            substrings[0]     = substring;
            SubstringFilter substring1 = new SubstringFilter();

            substring1.name    = "nyacctlevel1";
            substring1.initial = "Y";
            substrings[1]      = substring1;
            SubstringFilter substring2 = new SubstringFilter();

            substring2.name    = "sn";
            substring2.initial = "smith";
            substrings[2]      = substring2;
            SubstringFilter substring3 = new SubstringFilter();

            substring3.name    = "ou";
            substring3.initial = "Department of General Services";
            substrings[3]      = substring3;
            //FilterSet fSet = new FilterSet();
            //ItemsChoiceType[] chioceTypes = new ItemsChoiceType[4];
            //fSet.ItemsElementName = chioceTypes;



            filter.ItemElementName = ItemChoiceType.substrings;
            filter.Item            = substring2;
            search.filter          = filter;
            search.scope           = SearchRequestScope.wholeSubtree;

            AttributeDescriptions attrBucket = new AttributeDescriptions();

            AttributeDescription[] attributeDescriptionList = new AttributeDescription[7];
            attributeDescriptionList[0] = new AttributeDescription()
            {
                name = "nyacctgovernment"
            };
            attributeDescriptionList[1] = new AttributeDescription()
            {
                name = "sn"
            };
            attributeDescriptionList[2] = new AttributeDescription()
            {
                name = "givenname"
            };
            attributeDescriptionList[3] = new AttributeDescription()
            {
                name = "mail"
            };
            attributeDescriptionList[4] = new AttributeDescription()
            {
                name = "uid"
            };
            attributeDescriptionList[5] = new AttributeDescription()
            {
                name = "nyacctpersonal"
            };
            attributeDescriptionList[6] = new AttributeDescription()
            {
                name = "nyacctbusiness"
            };
            attrBucket.attribute = attributeDescriptionList;

            search.attributes = attrBucket;
            //client.PreAuthenticate = true;
            //client.AllowAutoRedirect = true;



            BatchResponse response = null;

            try
            {
                //WebProxy myproxy = new WebProxy("proxy-internet.cio.state.nyenet", 80);
                //myproxy.BypassProxyOnLocal = false;
                //myproxy.Credentials = new NetworkCredential("mjordan", "fuckU023$6");
                //client.Proxy = myproxy;
                response = client.directoryRequest(batch);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Dang it.  probably a 502 from the server and even more probable about async.  " + e);
            }
            System.Diagnostics.Debug.WriteLine("just sent the request for a batch seach to directory request");
            System.Diagnostics.Debug.WriteLine("Response: " + response);

            if (response != null)
            {
                SearchResponse[] sResponses = response.searchResponse;
                System.Diagnostics.Debug.WriteLine("Search Response: " + sResponses);
                if (sResponses != null)
                {
                    System.Diagnostics.Debug.WriteLine("Got " + sResponses.Length + " responses");
                    for (int i = 0; i < sResponses.Length; i++)
                    {
                        System.Diagnostics.Debug.WriteLine("Search Response #" + i + " requestID: " + sResponses[i].requestID);
                        SearchResultEntry[] srEntries = sResponses[i].searchResultEntry;
                        LDAPResult          srd       = sResponses[i].searchResultDone;
                        if (srd != null)
                        {
                            System.Diagnostics.Debug.WriteLine("LDAP Result AKA search result done");
                            System.Diagnostics.Debug.WriteLine(srd.resultCode.descr);
                        }
                        if (srEntries != null)
                        {
                            System.Diagnostics.Debug.WriteLine("Search Result Entries Cycle");
                            for (int r = 0; r < srEntries.Length; r++)
                            {
                                NyGovUser user = new NyGovUser();
                                user.NysSogUid = srEntries[r].dn;
                                System.Diagnostics.Debug.WriteLine(srEntries[r].dn);
                                System.Diagnostics.Debug.WriteLine(srEntries[r].attr);
                                DsmlAttr[] attributeList = srEntries[r].attr;
                                if (attributeList != null)
                                {
                                    for (int a = 0; a < attributeList.Length; a++)
                                    {
                                        System.Diagnostics.Debug.WriteLine("name: " + attributeList[a].name);
                                        String        attName      = attributeList[a].name;
                                        StringBuilder valueBuilder = new StringBuilder();
                                        if (attributeList[a].value != null)
                                        {
                                            for (int x = 0; x < attributeList[a].value.Length; x++)
                                            {
                                                System.Diagnostics.Debug.WriteLine("value: " + attributeList[a].value[x]);
                                                valueBuilder.Append(attributeList[a].value[x]);
                                            }
                                        }

                                        if (attName.Equals("uid"))
                                        {
                                            user.Uid = valueBuilder.ToString();
                                        }
                                        else if (attName.Equals("cn"))
                                        {
                                            user.CommonName = valueBuilder.ToString();
                                        }
                                        else if (attName.Equals("nyacctgovernment"))
                                        {
                                            user.IsGovernmentAccount = Convert.ToBoolean(valueBuilder.ToString());
                                        }
                                        else if (attName.Equals("sn"))
                                        {
                                            user.Surname = valueBuilder.ToString();
                                        }
                                        else if (attName.Equals("givenname"))
                                        {
                                            user.Firstname = valueBuilder.ToString();
                                        }
                                        else if (attName.Equals("mail"))
                                        {
                                            user.EmailAddress = valueBuilder.ToString();
                                        }
                                        else if (attName.Equals("nyacctbusiness"))
                                        {
                                            user.IsBusinessPartnerAccount = Convert.ToBoolean(valueBuilder.ToString());
                                        }
                                        else if (attName.Equals("nyacctpersonal"))
                                        {
                                            user.IsCitizenAccount = Convert.ToBoolean(valueBuilder.ToString());
                                        }
                                    }
                                }
                                returnList.Add(user);
                            }
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("Search results list is null for some reason");
                        }
                    }
                }



                ErrorResponse[] eResponses = response.errorResponse;

                if (eResponses != null)
                {
                    System.Diagnostics.Debug.WriteLine("Checking out errors from the batch response");
                    System.Diagnostics.Debug.WriteLine("Errors Count: " + eResponses.Length);
                    //After adding a attribute value assertion and fitler to the search the error response ends up null so make a check for that
                    if (eResponses != null)
                    {
                        if (eResponses.Length > 0)
                        {
                            System.Diagnostics.Debug.WriteLine("Error Response");
                            for (int i = 0; i < eResponses.Length; i++)
                            {
                                ErrorResponse error = eResponses[i];
                                System.Diagnostics.Debug.WriteLine(error.message);
                                System.Diagnostics.Debug.WriteLine(error.detail);
                                System.Diagnostics.Debug.WriteLine(error.type);
                            }
                        }
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("No errors from the response");
                }
            }

            return(returnList);
        }
Esempio n. 3
0
        public directoryRequestResponse findUser(String uid, String ou)
        {
            System.Diagnostics.Debug.WriteLine("Going to find a specific user with the service reference proxy");
            //fiddler
            GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);
            dsmlSoapClient           client       = this.proxyfactory.createClient();
            directoryRequestRequest  mainRequest  = proxyfactory.createDirReq(ProxyFactory.BatchRequestTypes.searchRequest);
            directoryRequestResponse mainResponse = new directoryRequestResponse();
            DsmlMessage sReq = mainRequest.batchRequest.Items[0];

            if (sReq is SearchRequest)
            {
                SearchRequest search = (SearchRequest)sReq;
                //ou=People,ou=NYS Office of Information Technology Services,ou=Government,o=ny,c=us
                search.dn = "ou=People,ou=" + ou + ",ou=Government,o=ny,c=us";
                System.Diagnostics.Debug.WriteLine("search.dn");
                System.Diagnostics.Debug.WriteLine(search.dn);
                Filter filter = new Filter();

                AttributeValueAssertion ava = new AttributeValueAssertion();
                ava.name  = "uid";
                ava.value = uid;
                filter.ItemElementName = ItemChoiceType.equalityMatch;
                filter.Item            = ava;
                search.scope           = SearchRequestScope.wholeSubtree;
                search.filter          = filter;

                AttributeDescriptions  attrBucket = new AttributeDescriptions();
                AttributeDescription[] attributeDescriptionList = new AttributeDescription[9];
                attributeDescriptionList[0] = new AttributeDescription()
                {
                    name = "nyacctgovernment"
                };
                attributeDescriptionList[1] = new AttributeDescription()
                {
                    name = "sn"
                };
                attributeDescriptionList[2] = new AttributeDescription()
                {
                    name = "givenname"
                };
                attributeDescriptionList[3] = new AttributeDescription()
                {
                    name = "mail"
                };
                attributeDescriptionList[4] = new AttributeDescription()
                {
                    name = "uid"
                };
                attributeDescriptionList[5] = new AttributeDescription()
                {
                    name = "nyacctpersonal"
                };
                attributeDescriptionList[6] = new AttributeDescription()
                {
                    name = "nyacctbusiness"
                };
                attributeDescriptionList[7] = new AttributeDescription()
                {
                    name = "telephonenumber"
                };
                attributeDescriptionList[8] = new AttributeDescription()
                {
                    name = "nydob"
                };
                attrBucket.attribute = attributeDescriptionList;
                search.attributes    = attrBucket;

                mainResponse = callClient(client, mainRequest);
            }

            return(mainResponse);
        }