protected bool CheckGroupAttribute(LDAPObject group, string groupAttr)
 {
     try
     {
         group.InvokeGet(groupAttr);
     }
     catch (Exception e)
     {
         log.ErrorFormat("Wrong Group Attribute parameter: {0}. {1}", groupAttr, e);
         return(false);
     }
     return(true);
 }
예제 #2
0
 private string GetAttributeFromUser(LDAPObject domainUser, string attribute)
 {
     if (String.IsNullOrEmpty(attribute))
     {
         return(String.Empty);
     }
     try
     {
         return(domainUser.InvokeGet(attribute) as string);
     }
     catch (Exception e)
     {
         _log.ErrorFormat("Can't get attribute from user: attr = {0}, dn = {1}, {2}",
                          attribute, domainUser.DistinguishedName, e);
         return(String.Empty);
     }
 }
 protected bool CheckUserAttribute(LDAPObject 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);
 }
 protected bool CheckGroupNameAttribute(LDAPObject group, string groupAttr)
 {
     try
     {
         var groupNameAttribute = group.GetValues(groupAttr);
         if (groupNameAttribute == null)
         {
             log.ErrorFormat("Wrong Group Name Attribute parameter: {0}", groupAttr);
             return(false);
         }
     }
     catch (Exception e)
     {
         log.ErrorFormat("Wrong Group Attribute parameter: {0}. {1}", groupAttr, e);
         return(false);
     }
     return(true);
 }
예제 #5
0
        private bool IsUserExistsInGroup(LDAPObject domainUser, LDAPSupportSettings settings)
        {
            if (!settings.GroupMembership || DomainGroups == null || DomainGroups.Count == 0 || primaryGroup != null)
            {
                return(true);
            }

            var distinguishedName = ldapHelper.GetUserAttribute(domainUser, settings.UserAttribute);

            foreach (var domainGroup in DomainGroups)
            {
                if (ldapHelper.UserExistsInGroup(domainGroup, distinguishedName, settings.GroupAttribute))
                {
                    return(true);
                }
            }

            return(false);
        }
        protected bool CheckLoginAttribute(LDAPObject user, string loginAttribute)
        {
            string memberUser = null;

            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)
            {
                log.ErrorFormat("Wrong Login Attribute parameter: memberUser = {0}. {1}", memberUser, e);
                return(false);
            }
            return(true);
        }
예제 #7
0
        public UserInfo CreateUserInfo(LDAPObject domainUser)
        {
            var userName    = GetAttributeFromUser(domainUser, _settings.LoginAttribute);
            var firstName   = GetAttributeFromUser(domainUser, _settings.FirstNameAttribute);
            var secondName  = GetAttributeFromUser(domainUser, _settings.SecondNameAttribute);
            var mail        = GetAttributeFromUser(domainUser, _settings.MailAttribute);
            var mobilePhone = GetAttributeFromUser(domainUser, _settings.MobilePhoneAttribute);
            var title       = GetAttributeFromUser(domainUser, _settings.TitleAttribute);
            var location    = GetAttributeFromUser(domainUser, _settings.LocationAttribute);
            var contacts    = new List <string>();

            if (!string.IsNullOrEmpty(mobilePhone))
            {
                contacts.Add(MOB_PHONE);
                contacts.Add(mobilePhone);
            }

            if (!string.IsNullOrEmpty(mail))
            {
                contacts.Add(MAIL);
                contacts.Add(mail);
            }

            var user = new UserInfo
            {
                ID               = Guid.NewGuid(),
                UserName         = userName,
                Sid              = domainUser.Sid,
                ActivationStatus = EmployeeActivationStatus.Activated,
                Status           = domainUser.IsDisabled ? EmployeeStatus.Terminated : EmployeeStatus.Active,
                Title            = (!string.IsNullOrEmpty(title) ? title : string.Empty),
                Location         = (!string.IsNullOrEmpty(location) ? location : string.Empty),
                WorkFromDate     = TenantUtil.DateTimeNow(),
                Contacts         = contacts
            };

            if (!string.IsNullOrEmpty(firstName))
            {
                user.FirstName = firstName.Length > MAX_NUMBER_OF_SYMBOLS
                                     ? firstName.Substring(0, MAX_NUMBER_OF_SYMBOLS)
                                     : firstName;
            }
            else
            {
                user.FirstName = string.Empty;
            }

            if (!string.IsNullOrEmpty(secondName))
            {
                user.LastName = secondName.Length > MAX_NUMBER_OF_SYMBOLS
                                    ? secondName.Substring(0, MAX_NUMBER_OF_SYMBOLS)
                                    : secondName;
            }
            else
            {
                user.LastName = string.Empty;
            }

            if (string.IsNullOrEmpty(LDAPDomain) && !TryLoadLDAPDomain())
            {
                throw new Exception("LDAP domain not found");
            }

            var email = userName.Contains("@") ? userName : userName + "@" + LDAPDomain;

            user.Email = email;

            return(user);
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
        private UserInfo CreateUserInfo(LDAPObject domainUser, LDAPSupportSettings settings)
        {
            string        userName    = GetAttributeFromUser(domainUser, settings.LoginAttribute);
            string        firstName   = GetAttributeFromUser(domainUser, settings.FirstNameAttribute);
            string        secondName  = GetAttributeFromUser(domainUser, settings.SecondNameAttribute);
            string        mail        = GetAttributeFromUser(domainUser, settings.MailAttribute);
            string        mobilePhone = GetAttributeFromUser(domainUser, settings.MobilePhoneAttribute);
            string        title       = GetAttributeFromUser(domainUser, settings.TitleAttribute);
            string        location    = GetAttributeFromUser(domainUser, settings.LocationAttribute);
            List <string> contacts    = new List <string>(2);

            if (!string.IsNullOrEmpty(mobilePhone))
            {
                contacts.Add(mobPhone);
                contacts.Add(mobilePhone);
            }

            var user = new UserInfo
            {
                ID               = Guid.NewGuid(),
                UserName         = userName,
                Sid              = domainUser.Sid,
                ActivationStatus = (!string.IsNullOrEmpty(mail) ? EmployeeActivationStatus.Activated : EmployeeActivationStatus.NotActivated),
                Email            = (!string.IsNullOrEmpty(mail) ? mail : string.Empty),
                Title            = (!string.IsNullOrEmpty(title) ? title : string.Empty),
                Location         = (!string.IsNullOrEmpty(location) ? location : string.Empty),
                WorkFromDate     = TenantUtil.DateTimeNow(),
                Contacts         = contacts
            };

            if (!string.IsNullOrEmpty(firstName))
            {
                if (firstName.Length > maxNumberOfSymbols)
                {
                    user.FirstName = firstName.Substring(0, maxNumberOfSymbols);
                }
                else
                {
                    user.FirstName = firstName;
                }
            }
            else
            {
                user.FirstName = string.Empty;
            }

            if (!string.IsNullOrEmpty(secondName))
            {
                if (secondName.Length > maxNumberOfSymbols)
                {
                    user.LastName = secondName.Substring(0, maxNumberOfSymbols);
                }
                else
                {
                    user.LastName = secondName;
                }
            }
            else
            {
                user.LastName = string.Empty;
            }

            if (user.Email == string.Empty)
            {
                var domain = ldapHelper.GetDomain(settings);
                //DC= or dc=
                var domainName = domain != null && domain.DistinguishedName != null?
                                 domain.DistinguishedName.Remove(0, 3).Replace(",DC=", ".").Replace(",dc=", ".") : unknownDomain;

                string loginName = domainUser.InvokeGet(settings.LoginAttribute).ToString();
                string email     = loginName.Contains("@") ? loginName : loginName + "@" + domainName;
                user.Email = email.Replace(" ", string.Empty);
            }

            return(user);
        }