Registering Security Trimmers Programmatically 

Tags:

Background

When WSS and MOSS crawl content and store that content to an index they can also store authorization information (ACL) to the data. This makes it easy for a search query to only provide results to which the search user has access. WSS search is limited to SharePoint sites, but MOSS search can go beyond that to web sites, file shares, exchange public folders, the BDC, and others. While some content such as SharePoint sites, file shares, and exchange public folders contain ACLs, others such as web sites and BDC do not.

The solution to trimming MOSS search results that do not contain ACLs is to use a security trimmer. A security trimmer is very simple; it takes a list of URLs and returns a BitArray indicating if the current user has access to each URL. A security trimmer runs at query time so there is a performance cost, but I've found that the story here isn't too bad since the security trimmer gets called in batches based on the number of search results shown to the user on a page. Basically if the ratio of allowed access to total possible results is high, the number of items to check for security trimming at a time should be kept to a minimum. In addition there is a way to specify a limit on the number of crawl URLs to check.

There is a BDC Security Trimmer or you can write your own Custom Security Trimmer. That last link has a good overview and walkthrough of how to write, deploy, and register a custom security trimmer. I recommend it for further reading. However, the walkthrough only shows how to register a security trimmer using stsadm. It does not show how to do it via code. In fact, on the stsadm command you provide the crawl rule path indicating that security trimmer references the craw rule, which is not the case (it is the other way around).

I needed to do this via code as part of a custom shared service provider administration screen. Since I had a little bit of trouble figuring this out and couldn't find anyone else that did it, I wanted to blog about it here once I found the solution. 

Show Me Some Code!

OK, enough background, let's see some code on how to do this.

  • First, you're code will need to reference Microsoft.Office.Server.Search.dll which can be found in the ISAPI folder under the 12 Hive for a MOSS install. In addition, all of my code below uses the following using statement.

using SearchAdmin = Microsoft.Office.Server.Search.Administration;

  • Now you can register your security trimmer.  You will need the fully qualified type name for your security trimmer or access to it via code (as I have done below).  In addition you need to specify the security trimmer id (an Int32 of any value of your choice assuming another security trimmer is not already registered with that value).  If you don't have the context of the shared service provider you'll have to do a little more work.

// Get the security trimmer manager

// Note: no need to call SetSearchContextToUse as it is determined implicitly through HttpContext

SearchAdmin.Security.PluggableSecurityTrimmerManager manager = SearchAdmin.Security.PluggableSecurityTrimmerManager.Instance;

 

// Register the security trimmer

// No need to provide any custom properties (must provide an empty named value collection)

string fullyQualifiedTypeName = typeof(MyCustomSecurityTrimmer).AssemblyQualifiedName;

 

manager.RegisterPluggableSecurityTrimmer(securityTrimmerId, fullyQualifiedTypeName, new NameValueCollection());

  • Then you will need to create or update your crawl rule to give it the security trimmer Id. The code below shows creating a crawl rule.  If you don't have the context of the shared service provider, you'll have to do a little more work.

// This page is in the context of the shared service provider, so this call should get our search context

// otherwise we would need to use the ServerContext object instead and call SearchContext.GetContext(serverContext);

// Note that ServerContext is in the Microsoft.Office.Server namespace (Microsoft.Office.Server.dll)

SearchAdmin.SearchContext searchContext = SearchAdmin.SearchContext.Current;

 

// Get the content object which is needed for access to content sources and crawl rules

SearchAdmin.Content content = new SearchAdmin.Content(searchContext);

 

// Create crawl rule

SearchAdmin.CrawlRule crawlRule = content.CrawlRules.Create(SearchAdmin.CrawlRuleType.InclusionRule, rulePath);

 

// Set other crawl rule properties here…

 

// Set the security trimmer id and save the changes

crawlRule.PluggableSecurityTrimmerId = securityTrimmerId;

crawlRule.Update();

That's it. Fairly simple, especially if you already have the appropriate context as my code does since it runs within the context of the shared service provider.

As you can see, the crawl rule references the security trimmer Id and the security trimmer does not reference the crawl rule.

Note that your security trimmer will not be in effect unless you crawl (probably a full crawl) after you register your security trimmer even though the security trimmer runs as query time.

 
Posted by Kirk Liemohn on 27-Oct-07
5 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Links to this post

Comments


nq316 commented on Saturday, 1-Nov-2008

bill commented on Tuesday, 11-Nov-2008
彼女         彼女


car wash commented on Monday, 29-Dec-2008

car wash commented on Monday, 29-Dec-2008
Best china wholesale service, quick wholesale delivery, nice wholesale products, is there anything more you can expect on this platform? This net will build up a link between you and you supplier so that to be sure you would have a satisfied wholesale clothingwholesale apparel trading. The account managers will take care of all your wholesale products questions, inquires and help you manage your account. We provid popular wholesale products such as wholesale watch and wholesale electronics. Different from other platforms, we also provide consumer electronics products, for example car electronics and digital camera. Meanwhile, we offer the best bluetooth phones and GPS Cellphone . Well begun is the half done. Please choose our platform to shorten your way to the successwholesale shoes,wholesale handbagsand wholesale toys
we offer chloe betty handbag,hermes handbags,gucci handbags,,balenciaga handbags,mulberry handbag,roxanne bag,hermes kelly bags,chloe betty bags ,miumiu bags,d&g handbags,fendi spy bag,chloe ascot handbag,hermes birkin,prada handbag,jimmy choo,leather wallets hermes we a supplier of those products.if you have any interest.contact ours Chinese antique furniture supplier and we can supplycar wash systems. car wash systems .car wash equipment. car wash equipment. automatic car wash .automatic car wash .car washing machine. car washing machine. car wash. car wash

楼梯有机玻璃电焊机硬度计测厚仪毛刷厂 毛刷毛刷北京汽车租赁防静电地板 白癜风 白癜风治疗货架 货架厂 网络地板 白癜风遮盖白癜风资讯白癜风资讯白癜风治疗有机玻璃加工数控切割机数控火焰切割机数控等离子切割机焊机健身器材 桶装水送水公司

工业毛刷 尖锐湿疣 尖锐湿疣治疗 生殖器疱疹 生殖器疱疹治疗 毛刷厂 帕金森清洗毛刷轻松过关名师课堂 粘钢胶树脂灌缝胶建筑结构胶植筋胶 结构胶灌浆料 灌浆 XYLITOLSODIUM SULPHATECAUSTIC SODA FLAKESMANGANESE SULFATESODIUM FORMATEMAGNESIUM SULFATEOXALIC ACIDFORMIC ACIDXYLITOLSODIUM SULPHATECAUSTIC SODA FLAKESMANGANESE SULFATESODIUM FORMATEMAGNESIUM SULFATEOXALIC ACIDFORMIC ACID Chinese antique furniture supplier and we can supplycar wash systems. car wash systems .car wash equipment. car wash equipment. automatic car wash .automatic car wash .car washing machine. car washing machine. car wash. car wash if u need ,contact me 会计专业资格会计专业资格考试会计从业资格证书会计专业技术资格会计从业资格证初级职称初级会计资格初级会计职称会计报名中级会计资格中级会计职称初级会计职称考试中级会计职称考试09年中级会计职称考试轻松过关名师课堂闫华红田明王燕会计答疑会计试题会计职称模拟试卷会计职称考前串讲会计职称历年试题会计资讯会计职称考试报名会计职称称准考证会计名师会计职称培训会计从业资格试题09年会计从业资格考试2009年会计报名2009年会计职称考试规律总结职称考试应试技巧会计职称考试答案会计职称考试试题会计职称考试时间中级职称初级职称培训初级职称报名中级职称报名中级职称培训职称考试初级会计中级会计初级会计初级中级 会计考试报名会计职称考试报名会计职称报名时间会计中级职称报名注会成绩查询注会考试成绩查询会计考试复习资料会计考试教材会计考试辅导视频会计考试历年试题会计考试真题会计考试答疑会计辅导名师最好的会计网校会计辅导权威网校最好的会计网会计远程教育权威会计网校会计人网上家园注册会计师教材会计论坛注册会计师会计在线学习北京会计培训注税考试报名注税考试辅导教材注税考试辅导课程高会考试报名高会考试辅导教材高会考试辅导课程高级会计师会计考试论坛中级财务管理注会经济法中级经济法经济法基础初级会计实务公司战略与风险管理注会税法经济法基础中级会计实务注会政策改革注会会计注会财务成本管理注会审计会计中级报名指南注会会计


Name:
URL:
Email:
Comments:

CAPTCHA Image Validation