In part II we will go through the code a little deeper.
Check permission against different systems
Please open this page,
http://msdn2.microsoft.com/en-us/library/aa981173.aspx
Look at this part of the code.
for (int x = 0; x < crawlURLs.Count; x++) { /* To fully implement the security trimmer, add code to perform the security check and determine if strUser can access crawlURLs[x]. If strUser can access crawlURL[x], then: */ retArray[x] = true; //If not: retArray[x] = false; }
Quite simple explanation. But how can you ?
1. Use WindowsIdentity.GetCurrent().Name to get current username, or if you are using FBA, that is HttpContext.Current.User.Identity.Name.
2. Then use this username to check with the target system, if he has the permission to crawlURL[x], then return a True.
Different system has different security checking method. Here' re some suggested ways to check security:
If you want to have a better performance when a CST is applied...
I suggest that you cache the permission settings to your own box and check it in CST. Remote calls may have huge impact on the performance, especially Lotus Notes. Meanwhile, check security with remote machine also means an impact to the target system. If that system is critical, this will affect customer's business.
The cache thing can be done with some small tools, of course you can write a small application by using Lotus Domino Objects and grab all the notes ACL back to a SQL table, that depends on your own opinion.
Another important thing is to set a CheckLimit in your CST. If CheckLimit is reached, CST will report something back to user, or do something you defined, and stop the check. This message can be something like "too many results pls refine your keywords", "Please try keyword1+keyword2+keyword3"....That will help.
Register a custom security trimmer
The trimmer must be compiled with strong name. You must first install it to the assembly by the following command(There're some errors in SDK):
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin>gacutil.exe /i c:\Trimmer\CustomSecurityTrimmerSample.dll /f
C:\Trimmer\CustomSecurityTrimmerSample.dll is my trimmer's path, change it with your own one.
A very important step: Create an "include" crawl rule with the URL you want to bind this CST with. If you don't create it, you cannot deploy the trimmer. In this sample, the path is http://localhost:8100/*.
Then you should deploy it with stsadm:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o registersecuritytrimmer -ssp SharedServices1 -id 2 -typeName "CustomSecurityTrimmerSample.CustomSecurityTrimmer, CustomSecurityTrimmerSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b6c7fa67516b1230" -rulepath http://localhost:8100/*
PublicKeyToken is the token you can see in windows\assembly directory. rulepath is the crawl rule path you just created.
And don't forget iisrset. Then, if any search result matches the crawl rule, CST will be launched to check the permission.