ISocialSecurityTrimmer ISocialSecurityTrimmer ISocialSecurityTrimmer Interface

Definition

Defines methods for security trimming lists that contain social data.

public interface class ISocialSecurityTrimmer
public interface ISocialSecurityTrimmer
Public Interface ISocialSecurityTrimmer
Derived

Remarks

The following code sample uses this interface to create a custom SearchSocialSecurityTrimmer.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using Microsoft.Office.Server.SocialData;

namespace CustomSecurityTrimmer
{
    public sealed class CustomSocialSecurityTrimmer : SearchSocialSecurityTrimmer
    {
        private const string C_KEY_EXCLUDEPATHS = "<span class="placeholder">ExcludePaths</span>";
        private const string C_KEY_INCLUDEPATHS = "<span class="placeholder">IncludePaths</span>";

        private static object syncRoot = new Object();
        private static volatile List&lt;Regex&gt; m_excludePaths;
        private static volatile List&lt;Regex&gt; m_includePaths;

        #region ISocialSecurityTrimmer interface
        public override void Initialize(NameValueCollection CustomProperty)
        {
            lock (syncRoot)
            {
                if (m_includePaths != null)
                    return;

                m_includePaths = new List&lt;Regex&gt;();
                m_excludePaths = new List&lt;Regex&gt;();

                // Cache parsed Url Regex objects's list onto static area to improve performance.
                // If you change the properties, you need to restart IIS to clear cache.
                string strIncludePaths = CustomProperty[C_KEY_INCLUDEPATHS];
                string strExcludePaths = CustomProperty[C_KEY_EXCLUDEPATHS];

                if (!String.IsNullOrEmpty(strIncludePaths))
                {
                    string[] strArray = strIncludePaths.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string strRegex in strArray)
                    {
                        m_includePaths.Add(new Regex(strRegex, RegexOptions.Singleline | RegexOptions.IgnoreCase));
                    }
                }

               if (!String.IsNullOrEmpty(strExcludePaths))
                {
                    string[] strArray = strExcludePaths.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string strRegex in strArray)
                    {
                        m_excludePaths.Add(new Regex(strRegex, RegexOptions.Singleline | RegexOptions.IgnoreCase));
                    }
                }
            }
        }

        public override List&lt;Uri&gt; Trim(List&lt;Uri&gt; uris)
        {
            List&lt;Uri&gt; resultUris = new List&lt;Uri&gt;();
            List&lt;Uri&gt; toBeTrimmedUris = new List&lt;Uri&gt;();

            foreach (Uri checkUri in uris)
            {
                if (IsUrlMatched(checkUri, m_includePaths))
                {
                    toBeTrimmedUris.Add(checkUri);
                }
                else if (IsUrlMatched(checkUri, m_excludePaths))
                {
                    resultUris.Add(checkUri);
                }
                else
                {
                    toBeTrimmedUris.Add(checkUri);
                }
            }

            // Execute Security Trimming.
            resultUris.AddRange(base.Trim(toBeTrimmedUris));

            return resultUris;
        }
        #endregion

        private static bool IsUrlMatched(Uri uri, List&lt;Regex&gt; strPatterns)
        {
            bool isMatch = false;

            foreach (Regex strPattern in strPatterns)
            {
                if (strPattern.IsMatch(uri.AbsoluteUri))
                {
                    isMatch = true;
                    break;
                }
            }
            return isMatch;
        }
    }
}

Methods

Initialize(NameValueCollection) Initialize(NameValueCollection) Initialize(NameValueCollection)

Obtains custom information that can be used for security trimming.

Trim(List<Uri>) Trim(List<Uri>) Trim(List<Uri>)

Security trims a list of URLs that represent pieces of social data.

Applies to