Introduction – What is Security Trimming?

Security trimming is simply the act of filtering out content that should not be accessible (typically read-able) for a given user. It is a core concept within SharePoint that affects what navigation elements you see, what sites you have access to, what lists and libraries you have access to, and what list items you see.  It is also a core concept within SharePoint search.  Security trimming in SharePoint search comes in two flavors: indexed security trimming and query-time security trimming.

Indexed Security Trimming

Security trimming within the index is possible when the crawler can obtain Access Control Lists (ACLs) for each item and store them in the index.  It is the preferred approach because it is faster.  There is little that is “dirty” about this approach.  This is used for SharePoint content as well as file shares and other content sources.  Outside of some minor storage and crawl processing costs, the only real downside is that permission changes are not reflected until the next incremental crawl.

Query-Time Security Trimming

Sometimes you do not have ACLs available at index time and you must resort to query-time security trimmers.  This is the case when crawling web sites since there is no way to ask a website “who has access to this page?”  This may also be the case with Business Connectivity Services (BCS) when you are crawling content from a database or web service.   BCS can use indexed security trimming, but only if you can make ACLs available through your external system.

The rest of this post focuses on query-time security trimming and how this has changed with SharePoint 2010.  Most of it is straightforward, but there are a couple of little “dirty secrets” you’ll need to be aware of.  First I’ll give an implementation overview, then I’ll show what I have observed, and finally I’ll focus on two gotchas that are in SharePoint 2010.

Implementing a Custom Security Trimmer

Query-time security trimming in SharePoint 2010 is very similar to SharePoint 2007.  They both require the server edition of the product (no WSS 3.0 or SharePoint Foundation).  In both cases you write a class that implements an interface and then you register that security trimmer with a crawl rule.  For SharePoint 2007 you use theISecurityTrimmer interface, whereas in SharePoint 2010 you use theISecurityTrimmer2 interface.  A good reference for writing security trimmers can be found in Writing a Custom SecurityTrimmer for SharePoint Server Search.

This interface is very simple.  It has an Initialize() method that runs once and can provide your class information specified when registering the security trimmer.  This method is identical for SharePoint 2007 and SharePoint 2010.

The only other method is a CheckAccess method.  This is the more interesting of the two.  This is where the query is actually happening.  This method returns a BitArray describing whether the current user has access to each URL provided.  It has some differences between SharePoint 2007 and SharePoint 2010; most notably that in SharePoint 2010 you are provided an IIdentity.  In SharePoint 2007 you had to use WindowsIdentity.GetCurrent() or HttpContext.Current.User depending on the authentication method.

CheckAccess Details

The CheckAccess method can run multiple times for a single query.  What the query engine is doing is providing your security trimmer a batch of URLs expecting to find out which ones can be provided to the current user for search results.  So, your security trimming code is running during the query – potentially multiple times.  If the security trimmer does not give the query engine enough hits, it will provide the next batch of URLs to your security trimmer – and will continue to do so until it has what it considers enough URLs or until it has exhausted all hits for the search request.

Since the security trimmer is running during the query, it needs to be quick and efficient.  However, while your security trimmer code is running you are likely doing some processing to find out if the current user has access to a URL.  This may involve a web service call to another system.  This may be fine, but I recommend that you test the performance thoroughly just to be sure.  Unfortunately, since SharePoint 2010 only provides an IIdentity, you are fairly limited since this does not provide you as much information as what you have access to in SharePoint 2007.  The context the security trimmer runs in is not the same context you are used to for your typical server-side SharePoint code, so you may have to do additional calls to lookup user information or other context-specific data.  If so, you’ll want to factor that into your performance costs.

In SharePoint 2007, the security trimmer was typically run enough so that the query engine could provide a page-worth of URLs to the user running the query.  Since the default query page size was 10, it may have stopped after having 20 or so URLs.  In SharePoint 2010, however, it not only wants enough URLs to show a page-worth of results to the user, but it also wants enough to show appropriate refiners.  By default, I believe that this means that the SharePoint 2010 query engine wants 50 results (after trimming).

CheckAccess Observations

Depending on how many search results there are before trimming and how many are trimmed out, your security trimmer may be called a large number of times.  Using the default settings with a large result set and with the majority of search results trimmed out, my observations have shown me that the first time the security trimmer is run it is provided 50 URLs.  If you trim some out, the security trimmer is immediately called again with another 75 URLs – and this is done before the user sees any search results.  That continues with batches of 75 URLs until enough results are satisfied or until the total result set is exhausted.  Using trace statements and DebugView I can watch what is going on.  The chart below shows how many URL are requested for a single query.  In this case the security trimmer is called 6 times and given a total of 425 URLs.

URLs Requested in a Single Query

In the output below, the first line is when Initialize is called.  Each subsequent line indicates an individual call to CheckAccess.

00000000 0.00000000 [9292] [CustomSecurityTrimmer] Initializing
00000001 0.00353188 [9292] [CustomSecurityTrimmer] Count = 50 - Total = 50.
00000002 0.05990715 [9292] [CustomSecurityTrimmer] Count = 75 - Total = 125.
00000003 0.10741841 [9292] [CustomSecurityTrimmer] Count = 75 - Total = 200.
00000004 0.16418955 [9292] [CustomSecurityTrimmer] Count = 75 - Total = 275.
00000005 0.21421386 [9292] [CustomSecurityTrimmer] Count = 75 - Total = 350.
00000006 0.26570737 [9292] [CustomSecurityTrimmer] Count = 75 - Total = 425.

The algorithm changes once the user clicks to view the second page of results.  The initial count of URLs provided to the security trimmer for the second page is 60.  It is 70 for the third, and then seems to max out at 76.  The pattern is a little more complex, so it is probably best just to show you some data.  Notice how the total resets on subsequent page requests.  That is because for each page we are starting a new set of processing as far as the security trimmer is concerned.

00000000 0.00000000 [11200] [CustomSecurityTrimmer] Initializing
00000001 0.00489843 [11200] [CustomSecurityTrimmer] Count = 50 - Total = 50.
00000002 0.06208209 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 125.
00000003 30.23514748 [11200] [CustomSecurityTrimmer] Count = 60 - Total = 60.  (Page 2)
00000004 30.27280998 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 135.
00000005 45.76335526 [11200] [CustomSecurityTrimmer] Count = 70 - Total = 70.  (Page 3)
00000006 45.79971313 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 145.
00000007 59.88526917 [11200] [CustomSecurityTrimmer] Count = 76 - Total = 76.  (Page 4)
00000008 59.88538742 [11200] [CustomSecurityTrimmer] Count = 4 - Total = 80.
00000009 59.92379761 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 155.
00000010 59.97734451 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 230.
00000011 82.77108765 [11200] [CustomSecurityTrimmer] Count = 76 - Total = 76.  (Page 5)
00000012 82.77122498 [11200] [CustomSecurityTrimmer] Count = 14 - Total = 90.
00000013 82.84067535 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 165.
00000014 82.93080902 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 240.
00000015 99.88347626 [11200] [CustomSecurityTrimmer] Count = 76 - Total = 76.  (Page 6)
00000016 99.88369751 [11200] [CustomSecurityTrimmer] Count = 24 - Total = 100.
00000017 99.94698334 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 175.
00000018 100.04191589 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 250.
00000019 106.22407532 [11200] [CustomSecurityTrimmer] Count = 76 - Total = 76.  (Page 7)
00000020 106.22446442 [11200] [CustomSecurityTrimmer] Count = 34 - Total = 110.
00000021 106.30342865 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 185.
00000022 106.39843750 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 260.
00000023 111.46296692 [11200] [CustomSecurityTrimmer] Count = 76 - Total = 76.  (Page 8 )
00000024 111.46327972 [11200] [CustomSecurityTrimmer] Count = 44 - Total = 120.
00000025 111.52843475 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 195.
00000026 111.62356567 [11200] [CustomSecurityTrimmer] Count = 75 - Total = 270.

If we are processing too much within a page (a single request), then then you can throw a PluggableAccessCheckException.  This is a way for the security trimmer to throw up its hands and basically give up.  A good overview of how to use this is found on Walkthrough: Using a Custom Security Trimmer for SharePoint Server Search Results, but read further below as there is a problem with this in SharePoint 2010. With this exception you can provide a message to show the end user; it basically tells them to refine their search.  This is an important part of a security trimmer because you don’t want to leave the user hanging too long.  If the query lasts too long, the thread will be aborted.  By default this is 90 seconds.

OK, now it’s time to dish some dirt…

Dirty Secret #1 – PluggableAccessCheckException

As mentioned above, the purpose of the PluggableAccessCheckException is to allow the security trimmer to tell the query engine to stop processing so a response can be given to the user performing the query without taking too much time.  Unfortunately, with SharePoint 2010 the opposite occurs.  If you throw a PluggableAccessCheckException what happens is that your security trimmer will be called with all URLs in the result set (typically in batches of 75) unless the thread is aborted before you reach the end of the result set.  This is even the case if the security trimmer does not trim out any results after throwing the exception.  In the output below I have set a low limit of 150 URLs after which I throw the exception.

00000000 0.00000000 [4500] [CustomSecurityTrimmer] Initializing
00000001 0.00339907 [4500] [CustomSecurityTrimmer] Count = 50 - Total = 50.
00000002 0.05012119 [4500] [CustomSecurityTrimmer] Count = 75 - Total = 125.
00000003 20.21066093 [4500] [CustomSecurityTrimmer] Count = 60 - Total = 60.  (Page 2)
00000004 20.25085640 [4500] [CustomSecurityTrimmer] Count = 75 - Total = 135.
00000005 40.40690613 [4500] [CustomSecurityTrimmer] Count = 70 - Total = 70.  (Page 3)
00000006 40.45227051 [4500] [CustomSecurityTrimmer] Count = 75 - Total = 145.
00000007 57.72388458 [4500] [CustomSecurityTrimmer] Count = 76 - Total = 76.  (Page 4)
00000008 57.72399139 [4500] [CustomSecurityTrimmer] Count = 4 - Total = 80.
00000009 57.76459122 [4500] [CustomSecurityTrimmer] Count = 75 - Total = 155.
00000010 57.76465225 [4500] [CustomSecurityTrimmer] Exceeded Limit of 150.Count = 75 - Total = 155.  Throwing PluggableAccessCheckException
00000011 57.93753815 [4500] [CustomSecurityTrimmer] Count = 75 - Total = 230.
00000012 57.93761063 [4500] [CustomSecurityTrimmer] Exceeded Limit of 150.Count = 75 - Total = 230.  Throwing PluggableAccessCheckException... (skipping 8 sets of trace statements) ...
00000029 58.56541061 [4500] [CustomSecurityTrimmer] Count = 75 - Total = 905.
00000030 58.56551361 [4500] [CustomSecurityTrimmer] Exceeded Limit of 150.Count = 75 - Total = 905.  Throwing PluggableAccessCheckException
00000031 58.65005875 [4500] [CustomSecurityTrimmer] Count = 75 - Total = 980.
00000032 58.65012360 [4500] [CustomSecurityTrimmer] Exceeded Limit of 150.Count = 75 - Total = 980.  Throwing PluggableAccessCheckException
00000033 58.73397064 [4500] [CustomSecurityTrimmer] Count = 47 - Total = 1027.
00000034 58.73407364 [4500] [CustomSecurityTrimmer] Exceeded Limit of 150.Count = 47 - Total = 1027.  Throwing PluggableAccessCheckException

Last I heard, the product group confirmed the behavior and said that since multiple pluggable trimmers can be registered, search cannot be stopped on throwing the exception.  I assume that they are still trying to prevent continuously calling the security trimmer that threw the exception and hope that they will consider all results trimmed that are associated to a crawl rule in which a security trimmer threw the exception.

Bottom line: You may want to consider the risks of your custom security trimmer being called too many times and running too long.  A workaround may be to simply return False for every URL that is provided to your security trimmer once you determine that you have been running too long.  This could be done without doing any expensive processing.

Dirty Secret #2 – FAST Search for SharePoint 2010

Unfortunately, query time security trimmers are not supported with FAST for SharePoint (FS4SP).  The FAST pipeline is different and although FAST is a flexible platform, I am told that FAST Search for SharePoint 2010 does not currently have a feasible way to make this happen.

I believe this is because FS4SP has deep refinements (among other features).  Without FAST, SharePoint provides refiner information based on the first 50 results, but with FAST the exact count can be provided for each refiner.  This exact count cannot be provided unless all of the results are processed, which just isn’t feasible with a query-time security trimmer (which can conceivably have tens of thousands of hits or more for a single query).

Last I heard this was not currently supported, but that R&D is actively working on a design change to allow for this functionality in a future release.

Conclusion

Security trimming is a great thing and a powerful feature used liberally throughout SharePoint.  Security trimming with SharePoint search is crucial, especially when search results show hit highlighting of content.  If possible, use security trimming at index time.  If you must use query-time security trimming, go in with your eyes wide open.

from:http://www.threewill.com/2011/03/security-trimming-secrets/

转载于:https://www.cnblogs.com/frankzye/archive/2013/03/21/2972414.html

Security Trimming Secrets相关推荐

  1. Azure KeyVault(四)另类在 .NET Core 上操作 Secrets 的类库方法-----Azure.Security.KeyVault.Secrets

    Python微信订餐小程序课程视频 https://edu.csdn.net/course/detail/36074 Python实战量化交易理财系统 https://edu.csdn.net/cou ...

  2. Linux wifi连接桌面,【已解决】Arch linux 安装之后在deepin桌面环境下使用networkmanager连接wifi 出现间歇性重连的情况...

    依云 说:ss9095 说:现在情况是这样的,现在连上以后会隔一段时间断开重新连接,不知道怎么回事,这段时间隔着有点长,我一开始担心日志太长会没有耐心看,所以就没敢放出来.谢谢您,网卡型号我暂时不知道 ...

  3. 2017-2018-2 20179317 《网络攻防技术》第七周学习心得体会

    教材学习内容总结 课本第七章主要围绕windows操作系统安全攻防技术进行讲述,教材中主要涉及的攻击内容如下: Windows操作系统的基本结构 运行于处理器特权模式的操作系统内核 运行在处理器非特权 ...

  4. TreeView和Menu

    TreeView 控件关键属性 CheckedNodes                 声明被选择的单个或者多个节点 ExpandDepth                   声明TreeView ...

  5. ASP.NET 2.0构建动态导航的Web应用程序(TreeView和Menu )[转载]

    TreeView 控件关键属性 CheckedNodes                 声明被选择的单个或者多个节点 ExpandDepth                   声明TreeView ...

  6. CVE-2020-1472 Netlogon权限提升漏洞分析

    一.漏洞信息 1. 漏洞简述 漏洞名称:Netlogon 权限提升漏洞 漏洞编号:CVE-2020-1472 漏洞类型:权限提升 CVSS评分:10 利用难度:简单 基础用户:不需要 2. 组件概述 ...

  7. 内网渗透攻击技术的利用

    DCSync 是什么 在域环境中,不同域控制器(DC)之间,每 15 分钟都会有一次域数据的同步.当一个域控制器(DC 1)想从其他域控制器(DC 2)获取数据时,DC 1 会向 DC 2 发起一个 ...

  8. wireshark分析实战

    数据包嗅探包括三个步骤 第一,收集,将网卡设置成混杂模式,收集所有的原始二进制数据 第二,转换,将捕获的二进制文件转换为可读形式 第三,分析,识别和验证所用协议 网络通信原理 1 协议 传输控制协议T ...

  9. 窃密软件访问的文件和注册表

    注册表路径 SAM - Encrypted Local Account Pwd hashes '\REGISTRY\MACHINE\SAM' '\REGISTRY\MACHINE\SAM\SAM\Do ...

  10. 学习笔记-Windows 安全

    Windows 安全 注 : 笔记中拓扑图 drawio 源文件在其图片目录下 免责声明 本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关. 大纲 漏 ...

最新文章

  1. pythonvbb转换txt_Caltech行人数据集转化VOC数据集
  2. CSDN Markdown编辑器的使用
  3. Eclipse中JRE System Library、Web App Libraries的作用
  4. 计算机专业考研末流211和双非,211大学考985研究生难吗,如何看待本科985学生读研去211学校?...
  5. eclipse如何设置js源文件编码
  6. java被电脑阻止怎么办_学电脑,一定要记住的6个常用命令,它能让你快速成为电脑达人...
  7. 牛客xiao白月赛32-- 拼三角(暴力却有坑)
  8. 源代码:spark-shell解读
  9. 01在Windows Server 2008R2上面搭建一台根DC
  10. Python中文手册——开胃菜
  11. php用户登录界面代码有背景,HTML和CSS实现动态背景登录页面
  12. Matlab spline
  13. C语言字符数组的初始化
  14. hp计算机控制面板,HP5000打印机控制面板菜单解释
  15. Linux的历史背景和基本指令
  16. ubuntu 20.04 下载 WPS
  17. 【科普】搜索引擎的工作原理
  18. 贵州省六盘水谷歌卫星地图下载
  19. 大数据平台搭建 | Hive
  20. iOS 动态改变应用图标

热门文章

  1. 西部旅游杂志西部旅游杂志社西部旅游编辑部2022年第19期目录
  2. java刮刮乐,20行JS代码实现网页刮刮乐效果
  3. 计算机主机自动关机如何设置,电脑设置如何自动关机【图文教程】
  4. netty编解码之jboss marshalling
  5. Cortex-M中特别实用的DWT计数器
  6. K41H 老笔记本维修升级记
  7. 消息队列 RocketMQ应用场景之削峰填谷
  8. 不使用BHO监控IE窗口事件
  9. 年薪30W+,数据库工程师凭什么?
  10. html的excel表格自动换行,Excel单元格内换行实现同时设置多单元格自动换、避免输入短横线...