Exemplo n.º 1
0
        private void GetUsers()
        {
            string[] ldaps         = LDAPPaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] netbioses     = NetBiosNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string   securityLabel = GetStringParameter(Constants.SOProperties.URM.Label, true);

            ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();

            if (string.Compare(securityLabel, "K2", true) == 0)
            {
                List <Thread> threads = new List <Thread>();
                string        ldap, net;
                Parallel.For(0, ldaps.Length, i =>
                {
                    ldap = ldaps[i];
                    net  = netbioses[i];
                    RunUMGetUsers(ldap, net);
                });
                //This line of code is needed so that the received items are not filtered again by K2 internal filtering of SMO.
                ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter = null;
            }
            else
            {
                // The below is basically copy/pasted code from the URM service. We don't really have a better way of calling that service instance code.

                string fqn         = GetStringProperty(Constants.SOProperties.URM.FQN);
                string name        = GetStringProperty(Constants.SOProperties.URM.Name);
                string email       = GetStringProperty(Constants.SOProperties.URM.Email);
                string description = GetStringProperty(Constants.SOProperties.URM.Description);
                string manager     = GetStringProperty(Constants.SOProperties.URM.Manager);
                string displayName = GetStringProperty(Constants.SOProperties.URM.DisplayName);
                string userName    = GetStringProperty(Constants.SOProperties.URM.UserName);
                string objectSid   = GetStringProperty(Constants.SOProperties.URM.ObjectSid);
                string saml        = GetStringProperty(Constants.SOProperties.URM.Saml);

                DataTable dtResults = ServiceBroker.ServicePackage.ResultTable;
                URMFilter urmFilter = new URMFilter(ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter);

                foreach (Dictionary <string, string> dictionary in urmFilter.GetFilterCollection().Values)
                {
                    foreach (KeyValuePair <string, string> keyValuePair in dictionary)
                    {
                        switch (keyValuePair.Key)
                        {
                        case Constants.SOProperties.URM.FQN:
                            fqn = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Name:
                            name = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Email:
                            email = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Description:
                            description = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Manager:
                            manager = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.DisplayName:
                            displayName = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.UserName:
                            userName = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.ObjectSid:
                            objectSid = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Saml:
                            saml = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        default:
                            continue;
                        }
                    }
                    Dictionary <string, object> properties = new Dictionary <string, object>()
                    {
                        { Constants.SOProperties.URM.Name, name == String.Empty ? (object)(string)null : (object)name },
                        {
                            Constants.SOProperties.URM.Description,
                            description == String.Empty ? (object)(string)null : (object)description
                        },
                        {
                            Constants.SOProperties.URM.Email, email == String.Empty ? (object)(string)null : (object)email
                        },
                        {
                            Constants.SOProperties.URM.Manager,
                            manager == String.Empty ? (object)(string)null : (object)manager
                        },
                        {
                            Constants.SOProperties.URM.DisplayName,
                            displayName == String.Empty ? (object)(string)null : (object)displayName
                        }
                    };
                    Helper.AddNonStandardProperties(properties, base.ServiceBroker.IdentityService.QueryUserProperties(securityLabel));

                    if (!string.IsNullOrEmpty(securityLabel))
                    {
                        properties[Constants.SOProperties.URM.Label] = (object)securityLabel;
                    }

                    if (ADMaxResultSize != -1)
                    {
                        properties["RowCount"]   = (object)(ADMaxResultSize);
                        properties["PageNumber"] = (object)1;
                    }
                    ICollection <ICachedIdentity> collection = base.ServiceBroker.IdentityService.FindIdentities((IDictionary <string, object>)properties, IdentitySearchOptions.Users);


                    bool flag   = properties.ContainsKey("RowCount");
                    int  result = 0;
                    if (flag)
                    {
                        int.TryParse((string)properties["RowCount"], out result);
                    }
                    if (collection != null)
                    {
                        foreach (ICachedIdentity cachedIdentity in collection)
                        {
                            if (cachedIdentity.Type == IdentityType.User)
                            {
                                DataRow dRow = dtResults.NewRow();
                                dRow[Constants.SOProperties.URM.FQN] = cachedIdentity.FullyQualifiedName.FQN;
                                if (cachedIdentity.Properties.ContainsKey("Name") && cachedIdentity.Properties["Name"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.UserName] = cachedIdentity.Properties["Name"].ToString();
                                    dRow[Constants.SOProperties.URM.Name]     = cachedIdentity.Properties["Name"].ToString();
                                    dRow[Constants.SOProperties.URM.Saml]     = LdapHelper.GetSAMAccountName(cachedIdentity.Properties["Name"].ToString());
                                }
                                if (cachedIdentity.Properties.ContainsKey("Description") && cachedIdentity.Properties["Description"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.Description] = cachedIdentity.Properties["Description"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("Email") && !string.IsNullOrEmpty(cachedIdentity.Properties["Email"].ToString()))
                                {
                                    dRow[Constants.SOProperties.URM.Email] = cachedIdentity.Properties["Email"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("Manager") && cachedIdentity.Properties["Manager"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.Manager] = cachedIdentity.Properties["Manager"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("ObjectSID") && cachedIdentity.Properties["ObjectSID"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.ObjectSid] = cachedIdentity.Properties["ObjectSID"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("DisplayName") && cachedIdentity.Properties["DisplayName"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.DisplayName] = cachedIdentity.Properties["DisplayName"].ToString();
                                }
                                dtResults.Rows.Add(dRow);


                                if (flag && dtResults.Rows.Count == result)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }