private static List <string> GetContacts(this LdapObject ldapUser, Mapping key, LdapSettings settings, ILog log = null)
        {
            if (!settings.LdapMapping.ContainsKey(key))
            {
                return(null);
            }

            var bindings = settings.LdapMapping[key].Split(',').Select(x => x.Trim()).ToArray();

            if (bindings.Length > 1)
            {
                var list = new List <string>();
                foreach (var bind in bindings)
                {
                    list.AddRange(ldapUser.GetAttributes(bind, log));
                }
                return(list);
            }
            else
            {
                return(ldapUser.GetAttributes(bindings[0], log));
            }
        }
Пример #2
0
        public static UserInfo ToUserInfo(this LdapObject ldapUser, LdapUserImporter ldapUserImporter, ILog log = null)
        {
            var settings = ldapUserImporter.Settings;
            var resource = ldapUserImporter.Resource;

            var userName    = ldapUser.GetAttribute(settings.LoginAttribute, log);
            var firstName   = ldapUser.GetAttribute(settings.FirstNameAttribute, log);
            var secondName  = ldapUser.GetAttribute(settings.SecondNameAttribute, log);
            var mail        = ldapUser.GetAttribute(settings.MailAttribute, log);
            var emails      = ldapUser.GetAttributes(settings.MailAttribute, log);
            var mobilePhone = ldapUser.GetAttribute(settings.MobilePhoneAttribute, log);
            var title       = ldapUser.GetAttribute(settings.TitleAttribute, log);
            var location    = ldapUser.GetAttribute(settings.LocationAttribute, log);

            if (string.IsNullOrEmpty(userName))
            {
                throw new Exception("LDAP LoginAttribute is empty");
            }

            var contacts = new List <string>();

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

            if (emails.Any())
            {
                foreach (var email in emails)
                {
                    if (email.Equals(mail))
                    {
                        continue;
                    }

                    contacts.Add(EXT_MAIL);
                    contacts.Add(email);
                }
            }

            var user = new UserInfo
            {
                ID               = Guid.Empty,
                UserName         = userName,
                Sid              = ldapUser.Sid,
                ActivationStatus = EmployeeActivationStatus.NotActivated,
                Status           = ldapUser.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 = resource.FirstName;
            }

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

            user.Email = string.IsNullOrEmpty(mail)
                ? (userName.Contains("@")
                    ? userName
                    : string.Format("{0}@{1}", userName, ldapUserImporter.LDAPDomain))
                : mail;

            return(user);
        }