Ejemplo n.º 1
0
        private static SolrQueryResults <Dictionary <string, object> > ApplySecurity(SolrQueryResults <Dictionary <string, object> > solrQueryResults, SearchSecurityOptions options, ICorePipeline pipeline, IAccessRight accessRight, ref int numberFound)
        {
            if (!options.HasFlag(SearchSecurityOptions.DisableSecurityCheck))
            {
                var removalList = new HashSet <Dictionary <string, object> >();

                foreach (var searchResult in solrQueryResults.Where(searchResult => searchResult != null))
                {
                    object secToken;
                    object dataSource;

                    if (!searchResult.TryGetValue(BuiltinFields.UniqueId, out secToken))
                    {
                        continue;
                    }

                    searchResult.TryGetValue(BuiltinFields.DataSource, out dataSource);

                    var isExcluded = OutboundIndexFilterPipeline.CheckItemSecurity(pipeline, accessRight, new OutboundIndexFilterArgs((string)secToken, (string)dataSource));

                    if (isExcluded)
                    {
                        removalList.Add(searchResult);
                        numberFound = numberFound - 1;
                    }
                }

                foreach (var item in removalList)
                {
                    solrQueryResults.Remove(item);
                }
            }

            return(solrQueryResults);
        }
            private static SolrQueryResults <Dictionary <string, object> > ApplySecurity(SolrQueryResults <Dictionary <string, object> > solrQueryResults, SearchSecurityOptions options, BaseCorePipelineManager pipeline, IAccessRight accessRight, ref int numberFound)
            {
                if (!options.HasFlag(SearchSecurityOptions.DisableSecurityCheck))
                {
                    var hashSet = new HashSet <Dictionary <string, object> >();
                    foreach (var dictionary in solrQueryResults.Where(searchResult => searchResult != null))
                    {
                        object obj1;
                        if (dictionary.TryGetValue("_uniqueid", out obj1))
                        {
                            object obj2;
                            dictionary.TryGetValue("_datasource", out obj2);

                            var args = new OutboundIndexFilterArgs((string)obj1, (string)obj2)
                            {
                                AccessRight = accessRight.ItemRead()
                            };

                            pipeline.Run("indexing.filterIndex.outbound", args);

                            if (args.IsExcluded)
                            {
                                hashSet.Add(dictionary);
                                numberFound = numberFound - 1;
                            }
                        }
                    }
                    foreach (var dictionary in hashSet)
                    {
                        solrQueryResults.Remove(dictionary);
                    }
                }
                return(solrQueryResults);
            }
        private static IQueryResponse <Dictionary <string, object> > ApplySecurity(IQueryResponse <Dictionary <string, object> > queryResults, SearchSecurityOptions options, ref int resultsTotal)
        {
            if (!options.HasFlag(SearchSecurityOptions.DisableSecurityCheck))
            {
                var hitsToRemove = new HashSet <IHit <Dictionary <string, object> > >();
                foreach (var hit in from searchResult in queryResults.Hits.Hits
                         where searchResult != null
                         select searchResult)
                {
                    object uniqueId;
                    if (!hit.Source.TryGetValue("_uniqueid", out uniqueId))                     //TODO: shouldn't have to use the Source property here, the Fields property should be populated. probably something wrong with field mapping.
                    {
                        continue;
                    }

                    object datasource;
                    hit.Source.TryGetValue("_datasource", out datasource);                     //TODO: shouldn't have to use the Source property here, the Fields property should be populated. probably something wrong with field mapping.
                    if (!OutboundIndexFilterPipeline.CheckItemSecurity(new OutboundIndexFilterArgs((string)uniqueId, (string)datasource)))
                    {
                        continue;
                    }

                    hitsToRemove.Add(hit);
                }

                foreach (var hit in hitsToRemove)
                {
                    queryResults.Hits.Hits.Remove(hit);
                    resultsTotal--;
                }
            }
            return(queryResults);
        }