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 (var dictionary in urmFilter.GetFilterCollection().Values) { foreach (var 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; } } var 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; } var 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 (var 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; } } } } } } }
private void GetGroups() { 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]; RunUMGetGroups(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 code is a copy/paste from reflected code with some modifications as we can't do anything else. string name = GetStringProperty(Constants.SOProperties.URM.Name); string email = GetStringProperty(Constants.SOProperties.URM.Email); string description = GetStringProperty(Constants.SOProperties.URM.Description); DataTable dtResults = ServiceBroker.ServicePackage.ResultTable; URMFilter urmFilter = new URMFilter(ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter); foreach (Dictionary <string, string> filterCollectionValues in urmFilter.GetFilterCollection().Values) { foreach (KeyValuePair <string, string> keyValuePair in filterCollectionValues) { switch (keyValuePair.Key) { case Constants.SOProperties.URM.Name: name = keyValuePair.Value.Replace("'", ""); continue; case Constants.SOProperties.URM.Description: description = keyValuePair.Value.Replace("'", ""); continue; case Constants.SOProperties.URM.Email: email = keyValuePair.Value.Replace("'", ""); continue; default: continue; } } Dictionary <string, object> dictionary2 = new Dictionary <string, object>() { { "Name", name }, { "Description", description }, { "Email", email } }; if (!string.IsNullOrEmpty(securityLabel)) { dictionary2["Label"] = securityLabel as object; } ICollection <ICachedIdentity> identities = base.ServiceBroker.IdentityService.FindIdentities(dictionary2, IdentitySearchOptions.Groups); if (identities == null) { return; } foreach (ICachedIdentity cachedIdentity in identities) { if (cachedIdentity.Type == IdentityType.Group) { DataRow dRow = dtResults.NewRow(); dRow[Constants.SOProperties.URM.FQN] = cachedIdentity.FullyQualifiedName.FQN; dRow[Constants.SOProperties.URM.GroupName] = cachedIdentity.FullyQualifiedName.FullName; dRow[Constants.SOProperties.URM.Saml] = cachedIdentity.FullyQualifiedName.FullName; if (cachedIdentity.Properties.ContainsKey("Name") && cachedIdentity.Properties["Name"] != null) { dRow[Constants.SOProperties.URM.Name] = 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(); } dtResults.Rows.Add(dRow); } } } } }
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; } } } } } } }
private void GetFilters(string xml, ref Dictionary<string, Dictionary<string, string>> retList) { if (string.IsNullOrEmpty(xml)) { return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(xml); if (xmlDocument.FirstChild.ChildNodes.Count != 1) { foreach (XmlNode xmlNode in xmlDocument.FirstChild.ChildNodes) { this.GetFilters(xmlNode.OuterXml, ref retList); } } else if (xmlDocument.FirstChild.InnerXml.Contains("<or>")) { this.GetFilters(xmlDocument.FirstChild.InnerXml, ref retList); } else { StringBuilder filterExpression = new StringBuilder(); filterExpression.Append("<filterexp>"); filterExpression.Append(xmlDocument.FirstChild.InnerXml); filterExpression.Append("</filterexp>"); URMFilter urmFilter = new URMFilter(filterExpression.ToString()); if (string.Compare(xmlDocument.FirstChild.FirstChild.Name,"and") == 0) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); StringBuilder stringBuilder2 = new StringBuilder(); foreach (KeyValuePair<string, string> fil in urmFilter.filter) { dictionary.Add(fil.Key, fil.Value); stringBuilder2.Append(fil.Key); stringBuilder2.Append(fil.Value); } if (retList.ContainsKey(stringBuilder2.ToString())) { return; } retList.Add(stringBuilder2.ToString(), dictionary); } else { foreach (KeyValuePair<string, string> fil in urmFilter.filter) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add(fil.Key, fil.Value); StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.Append(fil.Key); stringBuilder2.Append(fil.Value); if (!retList.ContainsKey(stringBuilder2.ToString())) { retList.Add(stringBuilder2.ToString(), dictionary); } } } } }
private void GetFilters(string xml, ref Dictionary <string, Dictionary <string, string> > retList) { if (string.IsNullOrEmpty(xml)) { return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(xml); if (xmlDocument.FirstChild.ChildNodes.Count != 1) { foreach (XmlNode xmlNode in xmlDocument.FirstChild.ChildNodes) { this.GetFilters(xmlNode.OuterXml, ref retList); } } else if (xmlDocument.FirstChild.InnerXml.Contains("<or>")) { this.GetFilters(xmlDocument.FirstChild.InnerXml, ref retList); } else { StringBuilder filterExpression = new StringBuilder(); filterExpression.Append("<filterexp>"); filterExpression.Append(xmlDocument.FirstChild.InnerXml); filterExpression.Append("</filterexp>"); URMFilter urmFilter = new URMFilter(filterExpression.ToString()); if (string.Compare(xmlDocument.FirstChild.FirstChild.Name, "and") == 0) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); StringBuilder stringBuilder2 = new StringBuilder(); foreach (KeyValuePair <string, string> fil in urmFilter.filter) { dictionary.Add(fil.Key, fil.Value); stringBuilder2.Append(fil.Key); stringBuilder2.Append(fil.Value); } if (retList.ContainsKey(stringBuilder2.ToString())) { return; } retList.Add(stringBuilder2.ToString(), dictionary); } else { foreach (KeyValuePair <string, string> fil in urmFilter.filter) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary.Add(fil.Key, fil.Value); StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.Append(fil.Key); stringBuilder2.Append(fil.Value); if (!retList.ContainsKey(stringBuilder2.ToString())) { retList.Add(stringBuilder2.ToString(), dictionary); } } } } }
private void GetGroups() { 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]; RunUMGetGroups(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 code is a copy/paste from reflected code with some modifications as we can't do anything else. string name = GetStringProperty(Constants.SOProperties.URM.Name); string email = GetStringProperty(Constants.SOProperties.URM.Email); string description = GetStringProperty(Constants.SOProperties.URM.Description); DataTable dtResults = ServiceBroker.ServicePackage.ResultTable; URMFilter urmFilter = new URMFilter(ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter); foreach (var filterCollectionValues in urmFilter.GetFilterCollection().Values) { foreach (var keyValuePair in filterCollectionValues) { switch (keyValuePair.Key) { case Constants.SOProperties.URM.Name: name = keyValuePair.Value.Replace("'", ""); continue; case Constants.SOProperties.URM.Description: description = keyValuePair.Value.Replace("'", ""); continue; case Constants.SOProperties.URM.Email: email = keyValuePair.Value.Replace("'", ""); continue; default: continue; } } Dictionary<string, object> dictionary2 = new Dictionary<string, object>() { {"Name", name}, {"Description", description}, {"Email", email} }; if (!string.IsNullOrEmpty(securityLabel)) { dictionary2["Label"] = securityLabel as object; } var identities = base.ServiceBroker.IdentityService.FindIdentities(dictionary2, IdentitySearchOptions.Groups); if (identities == null) { return; } foreach (var cachedIdentity in identities) { if (cachedIdentity.Type == IdentityType.Group) { DataRow dRow = dtResults.NewRow(); dRow[Constants.SOProperties.URM.FQN] = cachedIdentity.FullyQualifiedName.FQN; dRow[Constants.SOProperties.URM.GroupName] = cachedIdentity.FullyQualifiedName.FullName; dRow[Constants.SOProperties.URM.Saml] = cachedIdentity.FullyQualifiedName.FullName; if (cachedIdentity.Properties.ContainsKey("Name") && cachedIdentity.Properties["Name"] != null) { dRow[Constants.SOProperties.URM.Name] = 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(); } dtResults.Rows.Add(dRow); } } } } }