コード例 #1
0
 private static void SetUser(LDAPUserParam param, PropertyCollection propertyCollection, ref LDAPUser user)
 {
     user.ID          = GetPropertyValue(param.UniqueIDAttribute, propertyCollection);
     user.FirstName   = GetPropertyValue(param.FirstNameAttribute, propertyCollection);
     user.LastName    = GetPropertyValue(param.LastNameAttribute, propertyCollection);
     user.DisplayName = GetPropertyValue(param.DisplayNameAttribute, propertyCollection);
     user.Email       = GetPropertyValue(param.EmailAttribute, propertyCollection);
 }
コード例 #2
0
        public static LDAPUser GetUser(LDAPUserParam param)
        {
            LDAPUser       user           = new LDAPUser();
            DirectoryEntry directoryEntry = new DirectoryEntry(param.Path, param.DomainLoginName, param.Password, AuthenticationTypes.Secure);

            try
            {
                DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);
                directorySearcher.Filter = param.UserNameFilter;

                SearchResult       searchResult       = directorySearcher.FindOne();
                DirectoryEntry     userDirectoryEntry = searchResult.GetDirectoryEntry();
                PropertyCollection propertyCollection = userDirectoryEntry.Properties;
                SetUser(param, propertyCollection, ref user);
            }
            catch (Exception exception)
            {
                user.SetErrorMessage(exception.Message);
            }

            return(user);
        }