public JsonResult QueryUsers(string query)
        {
            IEnumerable <ActiveDirectoryMetadata> sources = configurationRepository.GetAll <ActiveDirectoryMetadata>();

            List <ActiveDirectoryMetadataAuthPrincipalQueryResultModel> results = new List <ActiveDirectoryMetadataAuthPrincipalQueryResultModel>();

            foreach (ActiveDirectoryMetadata source in sources)
            {
                List <ActiveDirectoryAuthenticablePrincipal> sourceResults = activeDirectory.Search <ActiveDirectoryAuthenticablePrincipal>("anr", query, NamingContext.Default, source);

                if (sourceResults == null)
                {
                    continue;
                }

                if (sourceResults.Count == 1)
                {
                    results.Add(new ActiveDirectoryMetadataAuthPrincipalQueryResultModel()
                    {
                        Domain            = source.Domain,
                        SamAccountName    = sourceResults[0].SamAccountName,
                        Id                = sourceResults[0].Id,
                        UserPrincipalName = sourceResults[0].UserPrincipalName,
                        DisplayName       = sourceResults[0].DisplayName,
                        Name              = sourceResults[0].Name,
                        DomainId          = source.Id
                    });
                    continue;
                }

                foreach (var user in sourceResults)
                {
                    results.Add(new ActiveDirectoryMetadataAuthPrincipalQueryResultModel()
                    {
                        Domain            = source.Domain,
                        SamAccountName    = user.SamAccountName,
                        Id                = user.Id,
                        UserPrincipalName = user.UserPrincipalName,
                        DisplayName       = user.DisplayName,
                        Name              = user.Name,
                        DomainId          = source.Id
                    });
                    continue;
                }
            }

            return(http.RespondSuccess(results));
        }
        public List <AdcsCertificateTemplate> GetActiveDirectoryTemplates(ActiveDirectoryMetadata metadata)
        {
            List <AdcsCertificateTemplate> templates = activeDirectory.Search <AdcsCertificateTemplate>(NamingContext.Configuration, metadata);

            return(templates);
        }