/// <summary> /// </summary> /// <param name="directoryEntry"></param> public LDAPObject CreateObject(DirectoryEntry directoryEntry) { if (directoryEntry == null) throw new ArgumentNullException("directoryEntry"); LDAPObject result = null; string schemaClassName = null; try { schemaClassName = directoryEntry.SchemaClassName; } catch (Exception e) { _log.ErrorFormat("Can't get directoryEntry.SchemaClassName property. {0}", e); } finally { } switch (schemaClassName) { case Constants.ObjectClassKnowedValues.Domain: case Constants.ObjectClassKnowedValues.DomainDNS: result = new LDAPDomain(directoryEntry); break; case Constants.ObjectClassKnowedValues.User: result = new LDAPUser(directoryEntry); break; case Constants.ObjectClassKnowedValues.Computer: result = new LDAPComputer(directoryEntry); break; case Constants.ObjectClassKnowedValues.Group: result = new LDAPGroup(directoryEntry); break; case Constants.ObjectClassKnowedValues.Container: result = new LDAPContainer(directoryEntry); break; case Constants.ObjectClassKnowedValues.RpcContainer: result = new LDAPRpcContainer(directoryEntry); break; case Constants.ObjectClassKnowedValues.BuildInDomain: result = new LDAPBuildInDomain(directoryEntry); break; case Constants.ObjectClassKnowedValues.OrganizationalUnit: result = new LDAPOrganizationalUnit(directoryEntry); break; default: result = new LDAPOtherObject(directoryEntry); break; } return result; }
private UserInfo CreateUserInfo(LDAPUser domainUser, LDAPSupportSettings settings) { var user = new UserInfo { ID = Guid.NewGuid(), UserName = domainUser.AccountName, Sid = domainUser.Sid.Value, ActivationStatus = (!string.IsNullOrEmpty(domainUser.Mail) ? EmployeeActivationStatus.Activated : EmployeeActivationStatus.NotActivated), Email = (!string.IsNullOrEmpty(domainUser.Mail) ? domainUser.Mail : string.Empty), MobilePhone = (!string.IsNullOrEmpty(domainUser.Mobile) ? domainUser.Mobile : string.Empty), Title = (!string.IsNullOrEmpty(domainUser.Title) ? domainUser.Title : string.Empty), Location = (!string.IsNullOrEmpty(domainUser.Street) ? domainUser.Street : string.Empty), WorkFromDate = TenantUtil.DateTimeNow() }; if (!string.IsNullOrEmpty(domainUser.FirstName)) { if (domainUser.FirstName.Length > MAX_NUMBER_OF_SYMBOLS) { user.FirstName = domainUser.FirstName.Substring(0, MAX_NUMBER_OF_SYMBOLS); } else { user.FirstName = domainUser.FirstName; } } else { user.FirstName = string.Empty; } if (!string.IsNullOrEmpty(domainUser.SecondName)) { if (domainUser.SecondName.Length > MAX_NUMBER_OF_SYMBOLS) { user.LastName = domainUser.SecondName.Substring(0, MAX_NUMBER_OF_SYMBOLS); } else { user.LastName = domainUser.SecondName; } } else { user.LastName = string.Empty; } if (user.Email == string.Empty) { var domain = ADDomain.GetDomain(settings); var domainName = domain != null ? domain.Name : UNKNOWN_DOMAIN; string loginName = domainUser.InvokeGet(settings.LoginAttribute).ToString(); user.Email = loginName.Contains("@") ? loginName : loginName + "@" + domainName; } return(user); }
public static string GetUserAttribute(LDAPUser user, string userAttribute) { try { var member = user.InvokeGet(userAttribute); if (member != null) { return(member.ToString()); } } catch (Exception e) { _log.ErrorFormat("Wrong User Attribute parameters: {0}. {1}", userAttribute, e); } return(null); }
private UserInfo CreateUserInfo(LDAPUser domainUser) { return(new UserInfo { ID = Guid.NewGuid(), UserName = domainUser.AccountName, Sid = domainUser.Sid.Value, ActivationStatus = (!string.IsNullOrEmpty(domainUser.Mail) ? EmployeeActivationStatus.Activated : EmployeeActivationStatus.NotActivated), Email = (!string.IsNullOrEmpty(domainUser.Mail) ? domainUser.Mail : domainUser.AccountName + "@" + ADDomain.Domain.Name + ".net"), FirstName = (!string.IsNullOrEmpty(domainUser.FirstName) ? domainUser.FirstName : domainUser.AccountName), LastName = (!string.IsNullOrEmpty(domainUser.SecondName) ? domainUser.SecondName : domainUser.AccountName), MobilePhone = (!string.IsNullOrEmpty(domainUser.Mobile) ? domainUser.Mobile : string.Empty), Title = (!string.IsNullOrEmpty(domainUser.Title) ? domainUser.Title : string.Empty), Location = (!string.IsNullOrEmpty(domainUser.Street) ? domainUser.Street : string.Empty), WorkFromDate = TenantUtil.DateTimeNow() }); }
private static bool CheckUserAttribute(LDAPUser user, string userAttr) { try { var userAttribute = user.InvokeGet(userAttr); if (userAttribute == null || string.IsNullOrWhiteSpace(userAttribute.ToString())) { _log.ErrorFormat("Wrong Group Attribute parameter: {0}", userAttr); return(false); } } catch (Exception e) { _log.ErrorFormat("Wrong Group Attribute parameter: {0}. {1}", userAttr, e); return(false); } return(true); }
private bool IsUserExistsInGroup(LDAPUser domainUser, LDAPSupportSettings settings) { if (!settings.GroupMembership || DomainGroups == null || DomainGroups.Count == 0 || _primaryGroup != null) { return(true); } var dn = ADDomain.GetUserAttribute(domainUser, settings.UserAttribute); foreach (var domainGroup in DomainGroups) { if (ADDomain.UserExistsInGroup(domainGroup, dn, settings.GroupAttribute)) { return(true); } } return(false); }
public static bool CheckLoginAttribute(LDAPUser user, string loginAttribute) { string memberUser; try { var member = user.InvokeGet(loginAttribute); memberUser = member != null?member.ToString() : null; if (string.IsNullOrWhiteSpace(memberUser)) { _log.ErrorFormat("Wrong Login Attribute parameter: {0}", memberUser); return(false); } } catch (Exception e) { memberUser = null; _log.ErrorFormat("Wrong Login Attribute parameter: {0}. {1}", memberUser, e); return(false); } return(true); }
/// <summary> /// </summary> /// <param name="directoryEntry"></param> public LDAPObject CreateObject(DirectoryEntry directoryEntry) { if (directoryEntry == null) { throw new ArgumentNullException("directoryEntry"); } LDAPObject result = null; string schemaClassName = null; try { schemaClassName = directoryEntry.SchemaClassName; } catch (Exception e) { _log.ErrorFormat("Can't get directoryEntry.SchemaClassName property. {0}", e); } finally { } switch (schemaClassName) { case Constants.ObjectClassKnowedValues.Domain: case Constants.ObjectClassKnowedValues.DomainDNS: result = new LDAPDomain(directoryEntry); break; case Constants.ObjectClassKnowedValues.User: result = new LDAPUser(directoryEntry); break; case Constants.ObjectClassKnowedValues.Computer: result = new LDAPComputer(directoryEntry); break; case Constants.ObjectClassKnowedValues.Group: result = new LDAPGroup(directoryEntry); break; case Constants.ObjectClassKnowedValues.Container: result = new LDAPContainer(directoryEntry); break; case Constants.ObjectClassKnowedValues.RpcContainer: result = new LDAPRpcContainer(directoryEntry); break; case Constants.ObjectClassKnowedValues.BuildInDomain: result = new LDAPBuildInDomain(directoryEntry); break; case Constants.ObjectClassKnowedValues.OrganizationalUnit: result = new LDAPOrganizationalUnit(directoryEntry); break; default: result = new LDAPOtherObject(directoryEntry); break; } return(result); }
private UserInfo CreateUserInfo(LDAPUser domainUser) { return new UserInfo { ID = Guid.NewGuid(), UserName = domainUser.AccountName, Sid = domainUser.Sid.Value, ActivationStatus = (!string.IsNullOrEmpty(domainUser.Mail) ? EmployeeActivationStatus.Activated : EmployeeActivationStatus.NotActivated), Email = (!string.IsNullOrEmpty(domainUser.Mail) ? domainUser.Mail : domainUser.AccountName + "@" + ADDomain.Domain.Name + ".net"), FirstName = (!string.IsNullOrEmpty(domainUser.FirstName) ? domainUser.FirstName : domainUser.AccountName), LastName = (!string.IsNullOrEmpty(domainUser.SecondName) ? domainUser.SecondName : domainUser.AccountName), MobilePhone = (!string.IsNullOrEmpty(domainUser.Mobile) ? domainUser.Mobile : string.Empty), Title = (!string.IsNullOrEmpty(domainUser.Title) ? domainUser.Title : string.Empty), Location = (!string.IsNullOrEmpty(domainUser.Street) ? domainUser.Street : string.Empty), WorkFromDate = TenantUtil.DateTimeNow() }; }
private UserInfo CreateUserInfo(LDAPUser domainUser, LDAPSupportSettings settings) { var user = new UserInfo { ID = Guid.NewGuid(), UserName = domainUser.AccountName, Sid = domainUser.Sid.Value, ActivationStatus = (!string.IsNullOrEmpty(domainUser.Mail) ? EmployeeActivationStatus.Activated : EmployeeActivationStatus.NotActivated), Email = (!string.IsNullOrEmpty(domainUser.Mail) ? domainUser.Mail : string.Empty), MobilePhone = (!string.IsNullOrEmpty(domainUser.Mobile) ? domainUser.Mobile : string.Empty), Title = (!string.IsNullOrEmpty(domainUser.Title) ? domainUser.Title : string.Empty), Location = (!string.IsNullOrEmpty(domainUser.Street) ? domainUser.Street : string.Empty), WorkFromDate = TenantUtil.DateTimeNow() }; if (!string.IsNullOrEmpty(domainUser.FirstName)) { if (domainUser.FirstName.Length > MAX_NUMBER_OF_SYMBOLS) { user.FirstName = domainUser.FirstName.Substring(0, MAX_NUMBER_OF_SYMBOLS); } else { user.FirstName = domainUser.FirstName; } } else { user.FirstName = string.Empty; } if (!string.IsNullOrEmpty(domainUser.SecondName)) { if (domainUser.SecondName.Length > MAX_NUMBER_OF_SYMBOLS) { user.LastName = domainUser.SecondName.Substring(0, MAX_NUMBER_OF_SYMBOLS); } else { user.LastName = domainUser.SecondName; } } else { user.LastName = string.Empty; } if (user.Email == string.Empty) { var domain = ADDomain.GetDomain(settings); var domainName = domain != null ? domain.Name : UNKNOWN_DOMAIN; string loginName = domainUser.InvokeGet(settings.LoginAttribute).ToString(); user.Email = loginName.Contains("@") ? loginName : loginName + "@" + domainName; } return user; }
private bool IsUserExistsInGroup(LDAPUser domainUser, LDAPSupportSettings settings) { if (!settings.GroupMembership || DomainGroups == null || DomainGroups.Count == 0 || _primaryGroup != null) { return true; } var dn = ADDomain.GetUserAttribute(domainUser, settings.UserAttribute); foreach (var domainGroup in DomainGroups) { if (ADDomain.UserExistsInGroup(domainGroup, dn, settings.GroupAttribute)) { return true; } } return false; }
public static string GetUserAttribute(LDAPUser user, string userAttribute) { try { var member = user.InvokeGet(userAttribute); if (member != null) { return member.ToString(); } } catch (Exception e) { _log.ErrorFormat("Wrong User Attribute parameters: {0}. {1}", userAttribute, e); } return null; }
public static bool CheckLoginAttribute(LDAPUser user, string loginAttribute) { string memberUser; try { var member = user.InvokeGet(loginAttribute); memberUser = member != null ? member.ToString() : null; if (string.IsNullOrWhiteSpace(memberUser)) { _log.ErrorFormat("Wrong Login Attribute parameter: {0}", memberUser); return false; } } catch (Exception e) { memberUser = null; _log.ErrorFormat("Wrong Login Attribute parameter: {0}. {1}", memberUser, e); return false; } return true; }
private static bool CheckUserAttribute(LDAPUser user, string userAttr) { try { var userAttribute = user.InvokeGet(userAttr); if (userAttribute == null || string.IsNullOrWhiteSpace(userAttribute.ToString())) { _log.ErrorFormat("Wrong Group Attribute parameter: {0}", userAttr); return false; } } catch (Exception e) { _log.ErrorFormat("Wrong Group Attribute parameter: {0}. {1}", userAttr, e); return false; } return true; }