Exemplo n.º 1
0
		internal static IResolvedAction GetIResolvedAction(PolicyResponseObject pro, Workshare.PolicyContent.ResolvedAction raIn)
		{
			Workshare.Policy.Engine.ResolvedAction raOut = new Workshare.Policy.Engine.ResolvedAction();

			raOut.Sequence = raIn.Sequence;

			raOut.ContentCollection = new Collection<IContentItem>();
			if (raIn.Contents != null)
			{
				foreach (Workshare.PolicyContent.ContentItem item in raIn.Contents)
				{
					Workshare.Policy.Engine.ContentItem proItem = null;
					foreach (Workshare.Policy.Engine.ContentItem ci in pro.ContentCollection)
					{
						if (ci.File.ContentId == item.Id)
							proItem = ci;
					}
					if (proItem != null)
						raOut.ContentCollection.Add(proItem);
				}
			}

			raOut.ResponseAction = ActionAdaptor.GetIPolicyResponseAction(raIn.Action);

			return raOut;
		}
Exemplo n.º 2
0
        static public string[] GetRecipientAddressList(PolicyResponseObject pro)
        {
            if (null == pro)
                throw new Workshare.Policy.Exceptions.ArgumentNullException("pro", "Invalid policy response object");

            return GetRecipientAddressList(pro.UniversalRequestObject);
        }
Exemplo n.º 3
0
		public void TestClientVerified_GetResponse()
		{
			PolicyResponseObject pro = new PolicyResponseObject();
			
			//Various steps to set up a valid Pro object.  Not specific to this test.
			pro.UniversalRequestObject = new UniversalRequestObject();
			pro.PolicyType = PolicyType.Mta;

			//This is specific to the test.
			pro.VerifiedOnClient = false;
		   
			Response response = ResponseAdaptor.GetResponse(pro);
			Assert.IsFalse(Array.Exists<CustomProperty>(response.Properties, delegate(CustomProperty cp)
			{
				return (cp.Name == PolicyConstants.ClientVerified && bool.TrueString == cp.Value);
			}), "Since VerifiedOnClient is false, there should be no such property in the output.");

			pro.VerifiedOnClient = true;
			response = ResponseAdaptor.GetResponse(pro);
			Assert.IsTrue(Array.Exists<CustomProperty>(response.Properties, delegate(CustomProperty cp)
			{
				return (cp.Name == PolicyConstants.ClientVerified && bool.TrueString == cp.Value);
			}), "Since VerifiedOnClient is true, this property is expected.");

		}
Exemplo n.º 4
0
        public static List<IPolicyResponseAction> GetPolicyResponseActions(PolicyResponseObject upi)
        {
            List<IPolicyResponseAction> policyResponseActionCollection = new List<IPolicyResponseAction>();
            Dictionary<String, PolicyResponseActionMerger> allPRAs = new Dictionary<string, PolicyResponseActionMerger>();

            Collection<IContentItem> fileCollection = upi.ContentCollection;
            foreach (ContentItem filePolicyInfo in fileCollection)
            {
                if (filePolicyInfo.PolicySetCollection == null)
                    continue;

                foreach (PolicySetResponse policySetResponse in filePolicyInfo.PolicySetCollection)
                {
                    if (policySetResponse.PolicyReportCollection == null)
                        continue;

                    foreach (IPolicyResponse policyResponse in policySetResponse.PolicyReportCollection)
                    {
                        if (!policyResponse.Triggered)
                            continue;

                        if (policyResponse.ActionCollection == null)
                            continue;

                        foreach (PolicyResponseAction policyResponseAction in policyResponse.ActionCollection)
                        {
                            if (policyResponseAction == null || policyResponseAction.Action == null 
                                || policyResponseAction.IsExceptionAction )
                                continue;

                            if (allPRAs.ContainsKey(policyResponseAction.Type))
                                allPRAs[policyResponseAction.Type].AddActionPropertySet(policyResponseAction.InternalProperties);
                            else
                            {
                                PolicyResponseActionMerger merger = new PolicyResponseActionMerger(policyResponseAction);
                                if (merger != null)
                                    allPRAs.Add(policyResponseAction.Type, merger);
                            }
                        }
                    }
                }
            }

            foreach (KeyValuePair<String, PolicyResponseActionMerger> kvp in allPRAs)
            {
                PolicyResponseActionMerger merger = kvp.Value;
                policyResponseActionCollection.Add(merger.MergePra());
            }

            policyResponseActionCollection.Sort(new ActionInfoSorterGenerics());

            return policyResponseActionCollection;
        }
Exemplo n.º 5
0
        public static Collection<IContentItem> GetContentItems(PolicyResponseObject upi, IPolicyResponseAction responseAction)
        {
            Dictionary<Guid, IContentItem> contentItems = new Dictionary<Guid, IContentItem>();

            Collection<IContentItem> contentCollection = upi.ContentCollection;
            foreach (ContentItem contentItem in contentCollection)
            {
                IFile currentFile = contentItem.File;

                if (contentItem.PolicySetCollection == null)
                    continue;

                foreach (IPolicySetResponse policySet in contentItem.PolicySetCollection)
                {
                    PolicySetResponse policySetInfo = policySet as PolicySetResponse;

                    if (policySetInfo.PolicyReportCollection == null)
                        continue;

                    foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
                    {
                        if (policyInfo.ActionCollection == null)
                            continue;

                        foreach (IPolicyResponseAction ai in policyInfo.ActionCollection)
                        {
                            PolicyResponseAction actionInfo = ai as PolicyResponseAction;
                            if (actionInfo.Action == null)
                                continue;

                            if (actionInfo.Type == ((PolicyResponseAction)responseAction).Type)
                            {
                                if (!contentItems.ContainsKey(currentFile.UniqueIdentifier))
                                    contentItems.Add(currentFile.UniqueIdentifier, contentItem);
                            }
                        }
                    }
                }
            }

            Collection<IContentItem> contents = new Collection<IContentItem>();
            foreach (KeyValuePair<Guid, IContentItem> kvp in contentItems)
            {
                contents.Add(kvp.Value);
            }

            return contents;
        }
Exemplo n.º 6
0
		static public string GetDisplayNames(PolicyResponseObject pro)
		{
			string s = "";
			if (pro != null)
			{
				Collection<IContentItem> contentItems = pro.ContentCollection;
				if (contentItems != null && contentItems.Count > 0)
				{
					ContentItem item = contentItems[0] as ContentItem;
					if (item != null && item.File != null)
					{
						s += ". file0:" + item.File.DisplayName;
					}
				}
			}
			return s;
		}
Exemplo n.º 7
0
        static public void SetPolicyEngineAddresses(PolicyResponseObject pro, PolicyEngine policyEngine, string[] addresses)
        {
            if (null == pro)
                throw new Workshare.Policy.Exceptions.ArgumentNullException("pro", "Invalid policy response object");

            if (null != pro.UniversalRequestObject.Source && null != pro.UniversalRequestObject.Source.Items && pro.UniversalRequestObject.Source.Items.Count > 0)
            {
                policyEngine.CurrentUser = pro.UniversalRequestObject.Source.Items[0].Content;
            }

            policyEngine.Source = pro.UniversalRequestObject.Source;
            policyEngine.Destination = pro.UniversalRequestObject.Destination;

            policyEngine.RecipientList = addresses;
            policyEngine.RequestChannel = RequestChannel.Unknown;
            if ((null != pro) && (null != pro.UniversalRequestObject) && (pro.UniversalRequestObject.Properties.ContainsKey("RequestChannel")))
            {
                string requestChannel = pro.UniversalRequestObject.Properties["RequestChannel"];
                policyEngine.RequestChannel = (RequestChannel)Enum.Parse(typeof(RequestChannel), requestChannel, true);
            }
        }
Exemplo n.º 8
0
		private void ProcessActionInfosForContentCollection(PolicyResponseObject upi, Dictionary<string, PolicyEngine> policyEngines)
		{
            if ((null == upi) || (null == upi.ContentCollection))
                return;

            for (int index = upi.ContentCollection.Count - 1; index >= 0; --index)
            {
                ContentItem contentItem = upi.ContentCollection[index] as ContentItem;
                if (null == contentItem)
                    continue;

                bool bHasExceptionActionBeenAdded = false;
                IEnumerator<IPolicySetResponse> responseEnumerator = contentItem.PolicySetCollection.GetEnumerator();
                foreach (KeyValuePair<string, PolicyEngine> policyEnginePair in policyEngines)
                {
                    responseEnumerator.MoveNext();
					Logger.LogDebug("ProcessActions: engine & policySet" + policyEnginePair.Value.ToString() + responseEnumerator.Current.Name);
#if DEBUG
					Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(upi));
#endif
					policyEnginePair.Value.ProcessActionInfo(contentItem, responseEnumerator.Current);

                    List<IPolicyResponseAction> actions = ActionUtils.AssociateFilesWithActions(contentItem);

                    ActionUtils.SupersedeActionsToPreventMultipleCalls(actions);

                    if (!bHasExceptionActionBeenAdded)  // only needs to be on one of them
                    {
                        if (policyEnginePair.Value.ProcessExceptionAction(contentItem, responseEnumerator.Current))
                        {
							Logger.LogDebug("ProcessActions Added ExceptionAction: engine & policySet" + policyEnginePair.Value.ToString() + responseEnumerator.Current.Name);
#if DEBUG
							Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(upi));
#endif
							bHasExceptionActionBeenAdded = true;
                        }
                    }
                }
            }
		}
Exemplo n.º 9
0
        public PolicyResponseObject Process(PolicyResponseObject pro)
        {
            if (null == pro)
                throw new PolicyEngineException("An invalid Policy Information Object was passed to the PolicyEngine.");

            ChannelType channel = PolicyTypeMappings.Lookup[pro.UniversalRequestObject.PolicyType];
            m_policyEngineCache.SetPolicyEnginesCompiledPolicySetCache(pro, channel.ToString());


            Dictionary<string, PolicyEngine> policyEngines = m_policyEngineCache.GetPolicyEnginesForChannel(channel.ToString());
            if (0 == policyEngines.Count)
                return null;

            string[] addresses = AddressUtilities.GetRecipientAddressList(pro);

            PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.Routing);

            foreach (ContentItem contentItem in pro.ContentCollection)
            {
                IEnumerator<IPolicySetResponse> numPsi = contentItem.PolicySetCollection.GetEnumerator();
                foreach (KeyValuePair<string, PolicyEngine> policyEnginePair in policyEngines)
                {
                    AddressUtilities.SetPolicyEngineAddresses(pro, policyEnginePair.Value, addresses);

                    numPsi.MoveNext();
                    Logger.LogDebug("ProcessRoutings: policySet:" + numPsi.Current.Name);
#if DEBUG
					Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif

					policyEnginePair.Value.ProcessRoutingInfo(contentItem, numPsi.Current);
                }
            }

            PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.Routing, 0);

            return pro;
        }
Exemplo n.º 10
0
        /// <summary>
        /// This method retrieves the properties for a given action, provided with a PolicyResponse, and IFile
        /// </summary>
        /// <param name="upi"></param>
        /// <param name="file"></param>
        /// <param name="thisAction"></param>
        /// <returns></returns>
        public static IActionPropertySet GetPropertySetForCorrespondingAction(PolicyResponseObject upi, IFile file, PolicyResponseAction thisAction)
        {
            foreach (IResolvedAction resolvedAction in upi.ResolvedActionCollection)
            {
                if (thisAction.Type == resolvedAction.ResponseAction.Type)
                {
                    Collection<IContentItem> fileCollection = resolvedAction.ContentCollection;
                    foreach (ContentItem filePolicyInfo in fileCollection)
                    {
                        IFile currentFile = filePolicyInfo.File;
                        if (file.UniqueIdentifier == currentFile.UniqueIdentifier)
                        {
                            if (filePolicyInfo.PolicySetCollection == null)
                                continue;

                            foreach (IPolicySetResponse policySet in filePolicyInfo.PolicySetCollection)
                            {
                                PolicySetResponse policySetInfo = policySet as PolicySetResponse;
                                if (policySetInfo.PolicyReportCollection == null)
                                    continue;

                                foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
                                {
                                    if (policyInfo.ActionCollection == null)
                                        continue;

                                    foreach (IPolicyResponseAction ai in policyInfo.ActionCollection)
                                    {
                                        PolicyResponseAction actionInfo = ai as PolicyResponseAction;
                                        if (actionInfo.Action == null)
                                            continue;

                                        if (actionInfo.SupersededByAction == null &&
                                            actionInfo.Type == thisAction.Type &&
                                            actionInfo.ExceptionAction == thisAction.ExceptionAction)
                                        {
                                            foreach (IActionPropertyResponse apr in actionInfo.SystemPropertyCollection)
                                            {
                                                if (actionInfo.Action.PropertySet.SystemProperties.ContainsKey(apr.Name))
                                                {
                                                    actionInfo.Action.PropertySet.SystemProperties[apr.Name].Value = apr.Value;
                                                }
                                                else
                                                {
                                                    ActionProperty prop = new ActionProperty(apr.Name, apr.Value);
                                                    actionInfo.Action.PropertySet.SystemProperties.Add(apr.Name, prop);
                                                }
                                            }
                                            return actionInfo.Action.PropertySet;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
Exemplo n.º 11
0
        private void InitialisePro(PolicyResponseObject pro, IUniversalRequestObject uro)
        {
            pro.RunAt = m_runAt;
            pro.UniversalRequestObject = uro;
            pro.PolicyType = uro.PolicyType;
            pro.ChannelDetail = uro.Properties.ContainsKey("RequestChannel") ? uro.Properties["RequestChannel"] : "";
            RoutingInfoHelper.PopulateRoutingInfo(pro);

            ContainerBuilder containerBuilder = new ContainerBuilder(pro);
            containerBuilder.CreateContainerFromUro();
        }
Exemplo n.º 12
0
        private static void ProcessActions(GeneralPolicyProcessor gpp, PolicyResponseObject pro, bool skipDiscovery)
        {
            Logger.LogTrace("ContentScanner: ProcessActions ENTER");
            foreach( IContentItem contentItem in pro.ContentCollection)
			{
				Debug.Assert(1 == contentItem.PolicySetCollection.Count,
							 "This collection should only contain one policy set - we only passed one in (see constructor)");

				double size = contentItem.Size;
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanActionsSize);
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanActions);
				gpp.SkipDiscovery = skipDiscovery;
				gpp.ProcessAction(contentItem, contentItem.PolicySetCollection[0]);

				List<IPolicyResponseAction> actions = ActionUtils.AssociateFilesWithActions(contentItem);

				gpp.ProcessExceptionAction(contentItem, contentItem.PolicySetCollection[0]);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanActions, 0);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanActionsSize, size);
			}
            Logger.LogTrace("ContentScanner: ProcessActions EXIT");
        }
Exemplo n.º 13
0
        private static void ProcessRouting(GeneralPolicyProcessor gpp, PolicyResponseObject pro)
        {
            Logger.LogTrace("ContentScanner: ProcessRouting ENTER");
            foreach (IContentItem contentItem in pro.ContentCollection)
            {
                Debug.Assert(1 == contentItem.PolicySetCollection.Count,
                             "This collection should only contain one policy set - we only passed one in (see constructor)");

                double size = contentItem.Size;
                PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanRoutingSize);
                PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanRouting);
                gpp.ProcessRouting(contentItem, contentItem.PolicySetCollection[0]);
                PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanRouting, 0);
                PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanRoutingSize, size);
            }
            Logger.LogTrace("ContentScanner: ProcessRouting EXIT");
        }
Exemplo n.º 14
0
 private static void ProcessExpressions(GeneralPolicyProcessor gpp, PolicyResponseObject pro)
 {
     Logger.LogTrace("ContentScanner: ProcessExpressions ENTER");
     foreach (IContentItem contentItem in pro.ContentCollection)
     {
         double size = contentItem.Size;
         PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanExpressionSize);
         PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanExpression);
         gpp.ProcessFileInfo(contentItem);
         PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanExpression, 0);
         PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanExpressionSize, size);
     }
     Logger.LogTrace("ContentScanner: ProcessExpressions EXIT");
 }
Exemplo n.º 15
0
		/// <summary>
		/// Traverse-s the list of all triggered policies to determine the value of BlockOnException.
		/// If at least one policy has this set to true then the result is true.
		/// </summary>
		/// <param name="pro"></param>
		/// <returns>whether to block on exception</returns>
		bool BlockOnException(PolicyResponseObject pro)
		{
			foreach (ContentItem ci in pro.ContentCollection)
			{
				if (ci.PolicySetCollection == null)
					return true; // a very strange situation indeed
				foreach (PolicySetResponse psr in ci.PolicySetCollection)
				{
					if (psr.PolicyReportCollection == null)
						continue;
					foreach (PolicyResponse pr in psr.PolicyReportCollection)
					{
						if (pr.Triggered && pr.BlockOnException)
							return true;
					}
				}
			}

			return false;
		}
Exemplo n.º 16
0
		private void ProcessFileAgainstPolicyEngines(PolicyResponseObject pro, RunAt runat, string[] addresses, ContentItem contentItem)
		{
			try
			{
				ChannelType channel = PolicyTypeMappings.Lookup[pro.UniversalRequestObject.PolicyType];

				Dictionary<string, PolicyEngine> engines = m_policyEngineCache.GetPolicyEnginesForChannel(channel.ToString());
				foreach (KeyValuePair<string, PolicyEngine> policyEnginePair in engines)
				{
					AddressUtilities.SetPolicyEngineAddresses(pro, policyEnginePair.Value, addresses);

					Logger.LogDebug("About to process: " + policyEnginePair.Key.ToString() + "/" + contentItem.File.DisplayName);
#if DEBUG
					Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif

					OnPolicyProgress(new ExecuteEventArgs(null, "", status.Started));

					policyEnginePair.Value.ProcessFileInfo(runat, contentItem);
				}
			}
			catch (System.Exception ex)
			{
				Logger.LogError(ex);
#if DEBUG
				Logger.LogError(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif

				throw new ProcessConditionsException(contentItem.File.DisplayName, ex.Message, ex);
			}
		}
Exemplo n.º 17
0
		private static void ProcessRouting(GeneralPolicyProcessor gpp, PolicyResponseObject pro)
		{
			foreach (IContentItem contentItem in pro.ContentCollection)
			{
                if (contentItem.Properties.ContainsKey("SkipScanning")
                    && (string.Equals(contentItem.Type, "PDFDocument", StringComparison.InvariantCultureIgnoreCase)
                        || contentItem.Properties.ContainsKey("ReadProtected")
                       )
                   )
				{
					continue;
				}
				
				Debug.Assert(1 == contentItem.PolicySetCollection.Count, "This collection should only contain one policy set - we only passed one in (see constructor)");

				double size = contentItem.Size;
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanRoutingSize);
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanRouting);
				gpp.ProcessRouting(contentItem, contentItem.PolicySetCollection[0]);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanRouting, 0);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanRoutingSize, size);
			}
		}
Exemplo n.º 18
0
        public static IActionPropertySet GetActionPropertySet(PolicyResponseObject upi, IFile file, PolicyResponseAction thisAction)
        {
            Collection<IContentItem> fileCollection = upi.ContentCollection;
            foreach (ContentItem filePolicyInfo in fileCollection)
            {
                IFile currentFile = filePolicyInfo.File;
                if (file.UniqueIdentifier == currentFile.UniqueIdentifier)
                {
                    if (filePolicyInfo.PolicySetCollection == null)
                        continue;

                    foreach (IPolicySetResponse policySet in filePolicyInfo.PolicySetCollection)
                    {
                        PolicySetResponse policySetInfo = policySet as PolicySetResponse;
                        if (policySetInfo.PolicyReportCollection == null)
                            continue;

                        foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
                        {
                            if (policyInfo.ActionCollection == null)
                                continue;

                            foreach (IPolicyResponseAction  ai in policyInfo.ActionCollection)
                            {
                                PolicyResponseAction actionInfo = ai as PolicyResponseAction;
                                if (actionInfo.Action == null)
                                    continue;

                                if (actionInfo.SupersededByAction == null &&
                                    actionInfo.Type == thisAction.Type &&
                                    actionInfo.ExceptionAction == thisAction.ExceptionAction)
                                {
                                    return actionInfo.InternalProperties;
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
Exemplo n.º 19
0
		public PolicyResponseObject Process(RunAt runat, IUniversalRequestObject uro, out IContainer container)
		{
			if (null == uro)
				throw new PolicyEngineException("An invalid Universal Request Object was passed to the PolicyEngine.");

			PolicyResponseObject pro = new PolicyResponseObject();
			pro.RunAt = runat;
			pro.UniversalRequestObject = uro;
			pro.PolicyType = uro.PolicyType;
			pro.ChannelDetail = uro.Properties.ContainsKey("RequestChannel") ? uro.Properties["RequestChannel"] : "";

			// Conditions may use some routing information
			// hence it is populated here.
			PopulateRoutingInfo(pro);

			Logger.LogDebug(PolicyResponseLogHelper.BuildUroMessage("ProcessConditions. input uro: ", uro));

			OnPolicyProgress(new ExecuteEventArgs(null, "", status.Started));

			ChannelType channel = PolicyTypeMappings.Lookup[uro.PolicyType];

			m_policyEngineCache.SetPolicyEnginesCompiledPolicySetCache(pro, channel.ToString());

			Logger.LogDebug("Process Conditions: PolicySetCacheSet");
#if DEBUG
			Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif

			OnPolicyProgress(new ExecuteEventArgs(null, "", status.Started));

			Logger.LogDebug("Process Conditions: Properties Added");
#if DEBUG
			Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif

			AddFiles(pro, out container);

			Logger.LogDebug("Process Conditions: Files Added");
#if DEBUG
			Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif
			OnPolicyProgress(new ExecuteEventArgs(null, "", status.Started));

			string[] addresses = AddressUtilities.GetRecipientAddressList(pro);

			Logger.LogDebug("Process Conditions: Addresses Set");
#if DEBUG
			Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif

			OnPolicyProgress(new ExecuteEventArgs(null, "", status.Started));

			if (0 == m_policyEngineCache.GetPolicyEnginesForChannel(channel.ToString()).Count)
			{
				Logger.LogInfo("Warning: Processing content against no policy sets.");

				return pro;
			}

			Logger.LogDebug("Process Conditions: About to process fileinfo objects");
#if DEBUG
			Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif
			foreach (ContentItem fi in pro.ContentCollection)
			{
				StartPerformanceCounterForFileType(fi.File.FileType);

				ProcessFileAgainstPolicyEngines(pro, runat, addresses, fi);

				StopPerformanceCounterForFileType(fi.File.FileType, fi.Size);
			}

			Logger.LogDebug("Process Conditions: Completed");
#if DEBUG
			Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(pro));
#endif
			return pro;
		}
Exemplo n.º 20
0
		private void SynchronizeContentItemCollectionForZip(PolicyResponseObject pro, IFile modifiedFile, IFile originalFile)
		{
			originalFile.Files.Clear();

			if (FileType.ZIP != modifiedFile.FileType)
			{
				CopyChildren(modifiedFile, originalFile);
				return;
			}

			originalFile.Files.Add(modifiedFile);
		}
Exemplo n.º 21
0
		/// <summary>
		/// Helper method to the one above, enables the code to be shared with the Mime scenario.
		/// </summary>
		/// <param name="pro"> </param>
		/// <param name="item"></param>
		/// <param name="type"></param>
		/// <returns></returns>
		private static PolicyResponseAction GetActionOfTypeFromContentItem(PolicyResponseObject pro, IContentItem item, string type)
		{
			PolicyResponseAction result = null;

			foreach (IPolicySetResponse set in item.PolicySetCollection)
			{
				foreach (IPolicyResponse policy in set.PolicyReportCollection)
				{
					if (!policy.Triggered)
						continue;

					List<IPolicyResponseAction> actions = new List<IPolicyResponseAction>(policy.ActionCollection);

					IPolicyResponseAction action = actions.Find(delegate(IPolicyResponseAction temp)
					{
						return temp.Type == type;
					});

					if (null == action)
						continue;

					result = (PolicyResponseAction) action;

					while (result.SupersededByAction != null)
						result = (PolicyResponseAction) result.SupersededByAction;

					//DE 4729 CurrentUser must be propagated. AND RecipientList AND RunAt
					if (!result.InternalProperties.SystemProperties.ContainsKey("CurrentUser"))
						result.InternalProperties.SystemProperties["CurrentUser"] = new Workshare.Policy.Action.ActionProperty("CurrentUser", "");
					if (!result.InternalProperties.SystemProperties.ContainsKey("RecipientList"))
						result.InternalProperties.SystemProperties["RecipientList"] = new Workshare.Policy.Action.ActionProperty("RecipientList", "");
					if (!result.InternalProperties.SystemProperties.ContainsKey("RunAt"))
						result.InternalProperties.SystemProperties["RunAt"] = new Workshare.Policy.Action.ActionProperty("RunAt", "");


					result.InternalProperties.SystemProperties["RunAt"].Value = pro.RunAt.ToString();

					// not all policy types fill the details about the source into the uro
					//and network content discovery doesnt even fill that in!!!!
					// might as well be paranoid.
					// we shouldnt really need to be doing such null checks so far down the stack. - rethink
					if (pro.UniversalRequestObject.Source != null &&
						pro.UniversalRequestObject.Source.Items != null &&
						pro.UniversalRequestObject.Source.Items.Count > 0)
					{
						result.InternalProperties.SystemProperties["CurrentUser"].Value =
							pro.UniversalRequestObject.Source.Items[0].Content;
					}
					result.InternalProperties.SystemProperties["RecipientList"].Value =
						AddressUtilities.GetRecipientAddressList(pro);

					return result;
				}
			}

			return result;
		}
Exemplo n.º 22
0
		/// <summary>
		/// This method searches for an Action corresponding to
		///     a) the required ResolvedAction <paramref name="resAction"/>
		///     b) the required ContentItem within <paramref name="item"/>
		/// 
		/// When given a flat list of ResolvedAction items, we need to find the corresponding action in the heirarchy beneath the 
		/// ContentItems, in order to use the properties that are specific to that Content.
		/// </summary>
		/// <param name="pro"> </param>
		/// <param name="item"></param>
		/// <param name="resAction"></param>
		/// <param name="folderAction"> </param>
		/// <returns></returns>
		private static PolicyResponseAction FindContentAction(PolicyResponseObject pro, ActionData item, ResolvedAction resAction, bool folderAction)
		{
			List<IContentItem> contents = new List<IContentItem>(resAction.ContentCollection);
			IContentItem content;
			if (!folderAction)
			{
				content = contents.Find(delegate(IContentItem temp)
				{
					return ((ContentItem) (temp)).File.ContentId == item.Underworld.ContentId;
				});
			}
			else
			{
				content = contents[0];
			}

			PolicyResponseAction pra = null;
			pra = GetActionOfTypeFromContentItem(pro, content, resAction.ResponseAction.Type);

			if (pra == null)
				Debug.Assert(false, "Should not get here - unless the ResolvedAction and the ActionData params were not related in the first place");

			return pra;
		}
Exemplo n.º 23
0
		static private IUniversalRequestObject CreateOutputUro(PolicyResponseObject pro, IContainer container)
		{
			if ((null == pro) || (null == container))
				return null;

			UniversalRequestObject uroIn = pro.UniversalRequestObject as UniversalRequestObject;
			if (null == uroIn)
				return null;

			UniversalRequestObject uroOut = new UniversalRequestObject();
			uroOut.PolicyType = uroIn.PolicyType;
			uroOut.DataTimeStamp = uroIn.DataTimeStamp;
			uroOut.OriginalContentBytes = uroIn.OriginalContentBytes;

			UniversalResponseObjectHelper.CopyProperties(uroIn, uroOut);
			UniversalResponseObjectHelper.CopyRouting(uroIn, uroOut);

			// Ignore the dummy parent container, only interested in the children
			foreach (IContainer childContainer in container.Files)
			{
				// We work with the files now, can just pass them straight back
				RecreateAttachments(uroIn, uroOut, childContainer);
			}
			Logger.LogDebug(PolicyResponseLogHelper.BuildUroMessage("Output Uro: ", uroOut));
			return uroOut;
		}
Exemplo n.º 24
0
		private static void ProcessActions(GeneralPolicyProcessor gpp, PolicyResponseObject pro, bool skipDiscovery)
		{
			foreach (IContentItem contentItem in pro.ContentCollection)
			{
                if (contentItem.Properties.ContainsKey("SkipScanning")
                    && (string.Equals(contentItem.Type, "PDFDocument", StringComparison.InvariantCultureIgnoreCase)
                        || contentItem.Properties.ContainsKey("ReadProtected")
                       )
                   )
				{
					continue;
				}

				Debug.Assert(1 == contentItem.PolicySetCollection.Count,
							 "This collection should only contain one policy set - we only passed one in (see constructor)");

				double size = contentItem.Size;
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanActionsSize);
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanActions);
				gpp.SkipDiscovery = skipDiscovery;
				gpp.ProcessAction(contentItem, contentItem.PolicySetCollection[0]);

				List<IPolicyResponseAction> actions = ActionUtils.AssociateFilesWithActions(contentItem);

				gpp.ProcessExceptionAction(contentItem, contentItem.PolicySetCollection[0]);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanActions, 0);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanActionsSize, size);
			}
		}
Exemplo n.º 25
0
		private static void PopulateRoutingInfo(PolicyResponseObject pro)
		{
			if (null == pro)
				return;

			IUniversalRequestObject uro = pro.UniversalRequestObject;
			if (null == uro)
				return;

			ResponseRoutingHandler routingHandler = new ResponseRoutingHandler(uro);
			pro.RoutingInformation = routingHandler.GenerateResponseFromUro();
		}
Exemplo n.º 26
0
        public IPolicyResponseObject Scan(IUniversalRequestObject uro, ProcessLevel processLevel)
        {
            PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScan);

            PolicyResponseObject pro = new PolicyResponseObject();

            GeneralPolicyProcessor gpp = GetGeneralPolicyProcessor(uro);

            if ( null == gpp)
                return pro;

            try
            {
                SetupPolicyProcessor(gpp, uro);

                InitialisePro(pro, uro);

                ProcessExpressions(gpp, pro);

                if (processLevel >= ProcessLevel.Routing)
                {
                    ProcessRouting(gpp, pro);

                    if (processLevel >= ProcessLevel.Actions)
                    {
                        ProcessActions(gpp, pro, m_skipDiscovery);
                    }
                }
            }
            finally
            {
                TearDownPolicyProcessor(gpp);
                PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScan, 0);
            }

            return pro;
        }
Exemplo n.º 27
0
		internal static void AddFiles(PolicyResponseObject pro, out IContainer container)
		{
			if ((null == pro) || (null == pro.UniversalRequestObject) || (null == pro.UniversalRequestObject.Attachments))
			{
				container = null;
				return;
			}

			ContainerBuilder containerBuilder = new ContainerBuilder(pro);
			container = containerBuilder.CreateContainerFromUro() as IContainer;
		}
Exemplo n.º 28
0
		private PolicyActionException CreateActionException(string action, PolicyResponseObject response, Exception e, bool forceNew)
		{
			string message = "ActionExecution: Exception on " + action + ". Message: " + e.Message;
			Logger.LogDebug(message);
#if DEBUG
			Logger.LogDebug(PolicyResponseLogHelper.GetDisplayNames(response));
#endif

			PolicyActionException exception = (forceNew ? null : e as PolicyActionException);
			if (exception == null)
			{
				exception = new PolicyActionException(message, e);
			}
			exception.Action = action;
			exception.ExceptionHandling = (BlockOnException(response) ? ActionExceptionHandling.Block : ActionExceptionHandling.Prompt);
			return exception;
		}
Exemplo n.º 29
0
		private void SetAuditLevel(PolicyResponseObject upi, int iMode)
		{
			// 0 = none, 1 == some None, 2 = all triggered, 3 = partly triggered, 4 = some all, 5 = all all
			bool flipper = true;
			foreach (ContentItem fileInfo in upi.ContentCollection)
			{
				foreach (IPolicySetResponse policySet in fileInfo.PolicySetCollection)
				{
					PolicySetResponse policySetInfo = policySet as PolicySetResponse;
					foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
					{
						if (iMode == 0)
						{
							((PolicyResponse)policyInfo).Audit = false;
						}
						else if (iMode == 1)
						{
							if (flipper)
							{
								((PolicyResponse)policyInfo).Audit = false;
							}
							else
								((PolicyResponse)policyInfo).Audit = true;
							flipper = !flipper;
						}
						else if (iMode == 3)
						{
							if (flipper)
							{
								((PolicyResponse)policyInfo).Audit= true;
							}
							else
								((PolicyResponse)policyInfo).Audit = false;
							flipper = !flipper;
						}
						else if (iMode == 4)
						{
							if (flipper)
							{
								((PolicyResponse)policyInfo).Audit = true;
							}
							else
								((PolicyResponse)policyInfo).Audit = false;
							flipper = !flipper;
						}
						else if (iMode == 5)
						{
							((PolicyResponse)policyInfo).Audit = true;
						}
						
					}
				}
			}
		}
Exemplo n.º 30
0
		private static void ProcessExpressions(GeneralPolicyProcessor gpp, PolicyResponseObject pro)
		{
			foreach (IContentItem contentItem in pro.ContentCollection)
			{
                if (contentItem.Properties.ContainsKey("SkipScanning")
                    && (string.Equals(contentItem.Type, "PDFDocument", StringComparison.InvariantCultureIgnoreCase)
                        || contentItem.Properties.ContainsKey("ReadProtected")
                       )
                   )
				{
					continue;
				}
				
				double size = contentItem.Size;
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanExpressionSize);
				PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.ContentScanExpression);
				gpp.ProcessFileInfo(contentItem);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanExpression, 0);
				PerformanceCounters.Instance.StopTimer(PerformanceCounters.CounterType.ContentScanExpressionSize, size);
			}
		}