private object GetValue(ResultPropertyValueCollection p) { object val = null; if (p != null) { IEnumerator iEnu = p.GetEnumerator(); while (iEnu.MoveNext()) { val = iEnu.Current; } } return(val); }
private static string GetSingleStringPropertyCollectionValue(System.DirectoryServices.ResultPropertyCollection props, string name) { if (!props.Contains(name)) { return(string.Empty); } ResultPropertyValueCollection pvc = props[name]; if (pvc == null || pvc.Count == 0) { return(string.Empty); } return(pvc[0] as string); }
public MultipleLineAdapter(ResultPropertyValueCollection resultPropertyValueCollection) { this.Value = new List <string>(); if (resultPropertyValueCollection.Count == 0) { // N/A. } else { foreach (var resultPropertyValue in resultPropertyValueCollection) { this.Value.Add(resultPropertyValue.ToString()); } } }
/// <summary> /// 从搜索结果中定位用户 /// </summary> /// <param name="objs"></param> /// <param name="account"></param> /// <returns></returns> public static SearchResult LocateUser(IList <SearchResult> objs, string account) { foreach (SearchResult p in objs) { ResultPropertyValueCollection temp = (ResultPropertyValueCollection)p.Properties["samaccountname"]; if ((temp != null) && (temp.Count > 0)) { if (temp[0].ToString().ToLower() == account.ToLower()) { return(p); } } } return(null); }
public static object GetSearchResultPropertyValue(SearchResult res, string propertyName) { Debug.Assert(res != null, "PropertyManager::GetSearchResultPropertyValue - res is null"); Debug.Assert(propertyName != null, "PropertyManager::GetSearchResultPropertyValue - propertyName is null"); ResultPropertyValueCollection propertyValues = null; propertyValues = res.Properties[propertyName]; if ((propertyValues == null) || (propertyValues.Count < 1)) { throw new ProviderException(string.Format("La propiedad {0} no se encuentra", propertyName)); } return(propertyValues[0]); }
/// <summary> /// Gets the property value. /// </summary> /// <remarks>The internal exception may be thrown directly.</remarks> /// <param name="properties">The user properties collection.</param> /// <param name="propertyName">The name of the property to get.</param> /// <returns>The property value.</returns> private string GetPropertyValue(ResultPropertyCollection properties, string propertyName) { string adPropertyName = ADPropertyNameMapping[propertyName]; if (properties.Contains(adPropertyName)) { ResultPropertyValueCollection values = properties[adPropertyName]; if (values.Count > 0) { return(values[0].ToString()); } } return(null); }
/// <summary> /// Gets the maximum password age on the specified domain. /// </summary> /// <param name="domain">The active directory domain to check.</param> /// <returns>The max password age, if set.</returns> public static TimeSpan?GetMaxPasswordAge(Domain domain) { ArgumentNullException.ThrowIfNull(domain); using (DirectoryEntry directoryEntry = domain.GetDirectoryEntry()) { using (DirectorySearcher ds = new( directoryEntry, "(objectClass=*)", null, SearchScope.Base )) { var sr = ds.FindOne(); if (sr == null) { return(null); } foreach (DictionaryEntry dictionaryEntry in sr.Properties) { if (dictionaryEntry.Key is not string keyName) { continue; } if (!keyName.Equals("maxPwdAge", StringComparison.Ordinal)) { continue; } if (dictionaryEntry.Value == null) { return(null); } ResultPropertyValueCollection valueCollection = (ResultPropertyValueCollection)dictionaryEntry.Value; var resultAsObject = valueCollection[0]; var resultAsLong = (long)resultAsObject; return(TimeSpan.FromTicks(resultAsLong).Duration()); } return(null); } } }
// CollectionContainsExactValue // This function checks the contents of a ResultPropertyValueCollection // for a specific value. // // Parameters: // collection: The ResultPropertyValueCollection to check. // value: The value to look for. // // Returns: // True if the collection contains the value; otherwise, false. // private static bool CollectionContainsExactValue(ResultPropertyValueCollection collection, string value) { foreach (object obj in collection) { string entry = obj as string; if (entry != null) { if (string.Compare(value, entry, true) == 0) { return(true); } } } return(false); }
// CollectionContainsPrefixValue // This function checks the contents of a ResultPropertyValueCollection // for a value that begins with a specific value. // // Parameters: // collection: The ResultPropertyValueCollection to check. // value: The value to look for. // // Return: // True if the collection contains the value; otherwise, false. // private static bool CollectionContainsPrefixValue(ResultPropertyValueCollection collection, string value) { foreach (object obj in collection) { string entry = obj as string; if (entry != null) { if (entry.StartsWith(value)) { return(true); } } } return(false); }
public List <string> Get() { List <string> list = new List <string>(); SearchResult edsEndpointObject = ManageEdsConnectionStrings.AdConnectionStrings.GetEdsEndpointObject(); if (edsEndpointObject != null) { ResultPropertyValueCollection resultPropertyValueCollection = edsEndpointObject.Properties["serviceBindingInformation"]; foreach (object obj in resultPropertyValueCollection) { string item = (string)obj; list.Add(item); } } return(list); }
public void OnGet() { DirectorySearcher ds = new DirectorySearcher(); var name = User.Identity.Name.Split('\\')[1]; ds.Filter = $"(&(objectClass=user)(objectcategory=person)(sAMAccountName={name}))"; SearchResult userProperty = ds.FindOne(); List <string> _department = new List <string>(); List <string> _memberof = new List <string>(); string _name = string.Empty; string _mail = string.Empty; if (userProperty != null) { ResultPropertyValueCollection _departmentResult = userProperty.Properties["department"]; if (_departmentResult != null) { foreach (var de in _departmentResult) { _department.Add(de.ToString()); } } ResultPropertyValueCollection _memberofResult = userProperty.Properties["memberof"]; if (_memberofResult != null) { foreach (var me in _memberofResult) { _memberof.Add(me.ToString()); } } ResultPropertyValueCollection _nameResult = userProperty.Properties["name"]; if (_nameResult != null) { _name = _nameResult[0].ToString(); } ResultPropertyValueCollection _mailResult = userProperty.Properties["mail"]; if (_mailResult != null) { _mail = _mailResult[0].ToString(); } } int sdfsdf = 0; }
private string NomeUsuarioNoAD(string p_Consulta) { string _Resp = ""; try { DirectoryEntry _DirectoryEntry = new DirectoryEntry("LDAP://10.249.1.242:389", "SVC00031", "Aes3e4r5t"); DirectorySearcher _DirectorySearcher = new DirectorySearcher(_DirectoryEntry); _DirectorySearcher.PropertiesToLoad.Add("displayname"); _DirectorySearcher.PropertiesToLoad.Add("description"); string _Filtro = p_Consulta.Replace("%", "*"); _DirectorySearcher.Filter = "(|(displayname=" + _Filtro + ") (samaccountname=" + _Filtro + "))"; SearchResultCollection Results = _DirectorySearcher.FindAll(); if (Results.Count > 0) { ResultPropertyValueCollection _ResultPropertyValueCollection = null; foreach (SearchResult searchResult in Results) { _ResultPropertyValueCollection = searchResult.Properties["displayname"]; if (_ResultPropertyValueCollection.Count > 0) { _Resp = _ResultPropertyValueCollection[0].ToString().ToUpper(); } else { _ResultPropertyValueCollection = searchResult.Properties["description"]; if (_ResultPropertyValueCollection.Count > 0) { _Resp = _ResultPropertyValueCollection[0].ToString().ToUpper(); } else { _Resp = ""; } } break; } } } catch (Exception) { _Resp = ""; } return(_Resp); }
/// <summary> /// Method to search the User in the siemens directory /// </summary> /// <param name="searchText"></param> /// <param name="userName"></param> /// <param name="pass"></param> /// <returns></returns> public static List <UserModel> SearchUserInDirectory(string searchText) { //Log.Info("Utility -> SearchUserInDirectory -> Method Called"); List <UserModel> userModelList = new List <UserModel>();; UserModel userModel = null; DirectorySearcher dirSearcher = new DirectorySearcher(); try { if (searchText.Contains(SIEMENS_COM)) { dirSearcher.Filter = string.Format(MAIL_FILTER, searchText); } else { dirSearcher.Filter = string.Format(USERID_FILTER, searchText); } SearchResult srEmail = dirSearcher.FindOne(); ResultPropertyValueCollection emailColl = srEmail.Properties[MAILPROP_NAME]; ResultPropertyValueCollection displayName = srEmail.Properties[DISPLAY_NAME]; ResultPropertyValueCollection department = srEmail.Properties[DEPARTMENT]; ResultPropertyValueCollection zidColl = srEmail.Properties[ZIDPROP_NAME]; ResultPropertyValueCollection cn = srEmail.Properties[FULL_NAME]; string[] names = cn[0].ToString().Split(ONESPACE_CHAR); string lastName = names[0].Trim(); string firstName = names[1].Trim(); string fullName = firstName + " " + lastName; userModel = new UserModel { AccountId = zidColl[0].ToString(), DisplayName = displayName[0].ToString(), OrganisationCode_BU = department[0].ToString(), EmailId = emailColl[0].ToString() }; userModelList.Add(userModel); return(userModelList); } catch (Exception ex) { Log.Error("Utility -> SearchUserInDirectory -> Exception Occured : " + ex); return(userModelList); } }
public static object GetSearchResultPropertyValue(SearchResult res, string propertyName) { ResultPropertyValueCollection values = null; try { values = res.Properties[propertyName]; if ((values == null) || (values.Count < 1)) { throw new ActiveDirectoryOperationException(Res.GetString("PropertyNotFound", new object[] { propertyName })); } } catch (COMException exception) { throw ExceptionHelper.GetExceptionFromCOMException(exception); } return(values[0]); }
private IValue ResultValueCollectionAsIValue(ResultPropertyValueCollection values) { IValue result; if (values.Count == 1) { result = ValueFactory.Create(values[0].ToString()); } else { ArrayImpl collection = new ArrayImpl(); foreach (object value in values) { collection.Add(ValueFactory.Create(value.ToString())); } result = collection; } return result; }
private string GetStringList(ResultPropertyValueCollection coll) { string result = ""; foreach (string prop in coll) { if (result.Length > 0) { result += string.Format(", {0}", prop); } else { result += prop; } } return(string.Format("[ {0} ]", result));; }
public static bool IsInGroup(ResultPropertyValueCollection memberOf, string groupName) { if (memberOf.Count > 0 & !String.IsNullOrWhiteSpace(groupName)) { foreach (String group in memberOf) { if (group.ToString().Contains(groupName)) { return(true); } } return(false); } else { return(false); } }
public static void propertyValueCollection() { //Create DirectoryEntry object DirectoryEntry ent = new DirectoryEntry("LDAP://apress"); //Create DirectorySearcher by specifying filter criteria DirectorySearcher dirSearcher = new DirectorySearcher(ent, "(name=Doug*)"); //retrieve the search result SearchResult searchResult = dirSearcher.FindOne(); //get the value in ResultPropertyValueCollection ResultPropertyValueCollection searchResultPropColl1 = searchResult.Properties["sn"]; //print value Console.WriteLine(searchResultPropColl1[0].ToString()); }
private static string GetObjectSid(System.DirectoryServices.ResultPropertyCollection props, string name) { if (!props.Contains(name)) { return(string.Empty); } ResultPropertyValueCollection pvc = props[name]; if (pvc == null || pvc.Count == 0) { return(string.Empty); } byte[] sidInBytes = (byte[])pvc[0]; SecurityIdentifier sid = new SecurityIdentifier(sidInBytes, 0); return(sid.ToString()); }
private string getPropertyValue(string sPropertyName) { try { //string targetOU = "cn=" + sUserName + ",ou=BASF-YPC COMPANY LIMITED,ou=EMPLOYEES,o=auth"; string targetOU = "cn=" + sUserName + ",ou=Users,ou=7430BASF,DC=byc,DC=com,DC=cn"; if (de == null) { //de = new DirectoryEntry("LDAP://10.4.21.214:389", targetOU, sPassword, AuthenticationTypes.None); de = new DirectoryEntry("LDAP://10.137.1.30:389", targetOU, sPassword, AuthenticationTypes.None); } DirectorySearcher ds = new DirectorySearcher(); ds.SearchRoot = de; //ds.Filter = ("(objectClass=group)"); ds.Filter = "cn=" + sUserName; //ds.Filter = ("(objectCategory=YBS)(objectClass=user)") ; //. Find("ybs", "Group")) foreach (SearchResult result in ds.FindAll()) { ResultPropertyValueCollection pvc = result.Properties[sPropertyName]; if (pvc.Count > 0) { return(pvc[0].ToString()); } //string name = result.GetDirectoryEntry().Name.ToString(); //DirectoryEntry deGroup = new DirectoryEntry(result.Path, targetOU, sPassword, AuthenticationTypes.None); //System.DirectoryServices.PropertyCollection pcoll = deGroup.Properties; //int n = pcoll["member"].Count; } } catch (Exception ex) { sError = ex.Message; //throw; } return(""); }
public static string ConvertMultiValuedToString(ResultPropertyValueCollection pValues) { var r = new StringBuilder(); foreach (string p in pValues) { if (string.IsNullOrEmpty(r.ToString())) { r.Append(p); } else { r.Append(Constants.MULTI_VALUED_SEPARATOR); r.Append(p); } } return(r.ToString()); }
public static IDictionary <string, string> GetUser(string domainName, string filterName, string filterValue) { var allProperties = "name,displayname,givenName,samaccountname,mail,title"; var properties = allProperties.Split(new char[] { '\r', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries); try { DirectoryEntry entry = new DirectoryEntry("LDAP://" + domainName); DirectorySearcher search = new DirectorySearcher(entry); search.Filter = $"({filterName}={filterValue})"; //search.Filter = "(samaccountname=" + loginName + ")"; //search.Filter = "(mail=" + userEmail + ")"; //foreach (string p in properties) //{ // search.PropertiesToLoad.Add(p); //} SearchResult result = search.FindOne(); if (result != null) { Dictionary <string, string> res = new Dictionary <string, string>(); foreach (DictionaryEntry p in result.Properties) { ResultPropertyValueCollection value = p.Value as ResultPropertyValueCollection; res.Add(p.Key.ToString(), value[0].ToString()); } return(res); } else { return(null); } } catch (Exception ex) { return(null); } return(null); }
public string GetDNSDomaiNamefromNetbios(string netbios) { string netbiosName = netbios; // Search for an object that is of type crossRefContainer. DirectoryEntry configde = new DirectoryEntry("LDAP://" + configDN); DirectorySearcher searcher = new DirectorySearcher(configde); searcher.Filter = string.Format("(&(objectcategory=Crossref)(netBIOSName={0}))", netbios); searcher.PropertiesToLoad.Add("dnsRoot"); SearchResultCollection results = searcher.FindAll(); if (results.Count > 0) { ResultPropertyValueCollection rpvc = results[0].Properties["dnsRoot"]; netbiosName = rpvc[0].ToString(); } return(netbiosName); }
private static string ResolveStandardProperty(ResultPropertyValueCollection property) { if (property == null) { return(string.Empty); } try { if (property.Count > 0) { return(property[0].ToString()); } } catch { return(string.Empty); } return(string.Empty); }
public static object GetSearchResultPropertyValue(SearchResult res, string propertyName) { ResultPropertyValueCollection item = null; try { item = res.Properties[propertyName]; if (item == null || item.Count < 1) { object[] objArray = new object[1]; objArray[0] = propertyName; throw new ActiveDirectoryOperationException(Res.GetString("PropertyNotFound", objArray)); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(cOMException); } return(item[0]); }
//-----------------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------------// //get mail address from AD so we can use it later to send email private string uEmail(string uid) { DirectorySearcher dirSearcher = new DirectorySearcher(); DirectoryEntry entry = new DirectoryEntry(dirSearcher.SearchRoot.Path); dirSearcher.Filter = "(&(objectClass=user)(objectcategory=person)(mail=" + uid + "*))"; SearchResult srEmail = dirSearcher.FindOne(); string propName = "mail"; ResultPropertyValueCollection valColl = srEmail.Properties[propName]; try { return(valColl[0].ToString()); } catch { return(""); } }
private static bool Authenticated() { string adPath = "LDAP://molex.com"; DirectoryEntry de = new DirectoryEntry(adPath); DirectorySearcher deSearch = new DirectorySearcher(de); deSearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + "ycchen10" + "))"; // LDAP 查询串 SearchResult results = deSearch.FindOne(); if (results != null) { ResultPropertyCollection coll = results.Properties; ResultPropertyValueCollection myCollection = coll["description"]; if (myCollection.Count == 1) { return(myCollection[0].Equals("169723")); } } return(false); }
private static string[] ResolveStringArrayAttribute(ResultPropertyValueCollection result) { if (result == null) { return(new string[0]); } List <string> resultList = new List <string>(); if (result.Count > 0) { foreach (string item in result) { resultList.Add(item); } return(resultList.ToArray()); } return(new string[0]); }
void ProcessUser(SearchResult result, string distinguishedName, List <SPUserInfo> users) { bool addUser = true; if (hideDisabledUsers) { ResultPropertyValueCollection accountControl = result.Properties["userAccountControl"]; if (accountControl != null && accountControl[0] != null) { // 2 is the flag for account disabled if (((int)accountControl[0] & 2) == 2) { addUser = false; } } } if (addUser) { users.Add(ProcessUser(result, distinguishedName)); } }
private static byte[][] ResolveNestedByteArrayAttribute(ResultPropertyValueCollection result) { List <byte[]> certByteList = new List <byte[]>(); if (result == null) { return(certByteList.ToArray()); } if (result.Count > 0) { foreach (byte[] certByte in result) { certByteList.Add(certByte); } return(certByteList.ToArray()); } return(certByteList.ToArray()); }
public void CopyTo(ResultPropertyValueCollection[] array, int index) { }