예제 #1
0
        private Task <IUser> SearchOrganizerAsync(Organizer organizer)
        {
            var taskCompletionSource = new TaskCompletionSource <IUser>();
            var connection           = OpenConnection();

            var requestState = new SearchRequestState(connection, taskCompletionSource, organizer);

            Task.Run(() => ExecuteSearchSafe(requestState));

            return(taskCompletionSource.Task);
        }
예제 #2
0
 private void ExecuteSearchSafe(SearchRequestState requestState)
 {
     try
     {
         var searchQueue = StartUserSearch(requestState);
         CompleteUserSearch(requestState, searchQueue);
     }
     catch (Exception e)
     {
         _logger.LogError(e, $"Error searching for an LDAP with the filter '{requestState.Filter}'");
         requestState.SetNoResult();
     }
     finally
     {
         requestState.Dispose();
     }
 }
예제 #3
0
        private LdapSearchQueue StartUserSearch(SearchRequestState requestState)
        {
            var searchConstraints =
                new LdapSearchConstraints(_ldapConfiguration.Value.TimeoutInMilliseconds,
                                          _ldapConfiguration.Value.TimeoutInSeconds,
                                          LdapSearchConstraints.DerefNever,
                                          1,
                                          true,
                                          1,
                                          null,
                                          20);
            var attributes  = new[] { "name", "givenname", "samaccountname", "mail" };
            var searchQueue = requestState.Connection.Search(_ldapConfiguration.Value.SearchBase,
                                                             LdapConnection.ScopeSub,
                                                             requestState.Filter,
                                                             attributes,
                                                             false,
                                                             null,
                                                             searchConstraints);

            return(searchQueue);
        }
예제 #4
0
        private void CompleteUserSearch(SearchRequestState requestState, LdapMessageQueue searchQueue)
        {
            var response = searchQueue.GetResponse();

            if (!(response is LdapSearchResult searchResult))
            {
                _logger.LogTrace($"Received an unexpected result of type '{response?.GetType()}' from LDAP search.");
                requestState.SetNoResult();
                return;
            }

            if (searchResult.Entry == null)
            {
                _logger.LogTrace($"Could not find an LDAP user with the filter '{requestState.Filter}'");
                requestState.SetNoResult();
                return;
            }

            var user = User.FromLdapEntry(searchResult.Entry);

            requestState.SetResult(user);
        }