Example #1
0
        public static IPolicySet ReadRuntimePolicySet(string filename, out PolicySetVersionStatus status)
        {
            status = PolicySetVersionStatus.Disabled;

            PolicyProxy runtimeCache = PolicyProxy.CreateLocalRuntimeCache();
            IPolicySetCache policySetCache = runtimeCache.GetPolicySet(filename);
            if (null == policySetCache)
                runtimeCache = PolicyProxy.CreateLocalPolicySourceCache();

            policySetCache = runtimeCache.GetPolicySet(filename);
            if (null == policySetCache)
                throw new Exception("Failed to load the runtime policy");

            status = policySetCache.LatestVersion.Status;

            PolicyConverterFactory factory = new PolicyConverterFactory(policySetCache);
            return factory.ConvertPolicySet(null);
        }
Example #2
0
		internal bool Load(string policyname, PolicyConverterFactory.AddPolicyLoadConversionMessageDelegate AddConversionMessage)
		{
			if (null == m_proxy)
				throw new Workshare.Policy.Exceptions.ArgumentNullException("policySetCache", "A null policy set cache object was passed in");

			m_policyname = policyname;

			m_cacheSet = m_proxy.GetPolicySet(policyname);

			if (m_cacheSet == null)
			{
				Logger.LogError(policyname + " returned null PolicySetCache - does the policyset exist or is it deleted?");
				return false;
			}
			else if (m_cacheSet.LatestVersion.Status == PolicySetVersionStatus.Deleted)
			{
				Logger.LogError("Latest version status set to deleted for policyset" + policyname);
				return false;
			}

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(m_cacheSet);
			m_data = policySetConverter.ConvertPolicySet(AddConversionMessage);

			// This has been added to enforce the full loading of the PolicySet /////////////////////////////////////////////////////
			// Unfortunately we don't have time to corect the load before the up and comming release.
			// We will probably leave it here for future generations to marvel over! JE,MM,TT 03.06.2011
			PolicySetValidator policySetValidator = new PolicySetValidator(m_data);
			policySetValidator.Validate();
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

			//We UnEscape the xml here as we dont want the users to see escaped characters in the descriptions
			foreach (ICondition condition in m_data.MasterCatalogue.Conditions)
			{
				condition.Name.Value = StringUtilities.UnEscapeXML(condition.Name.Value);
			}

			return true;
		}
		public void TestConvertPolicySetEmptyPolicySet()
		{
			LocalPolicyCache localPolicyCache = new LocalPolicyCache(m_testPath, false);
			IPolicySetCache policySetCache = localPolicyCache.NewPolicySet("Test policy set");
			policySetCache.NewVersion("");
			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);
			policySetConverter.ConvertPolicySet(AddConversionMessage);
		}
		public void TestUpgradeLDAPVersion_1_1_ToLatest()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test Policy Set based on version 1.1 format for LDAP.policy");

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			int compiledPolicySetsCount = policySetCache.LatestVersion.CompiledPolicySets.Count;
			PolicySetVersionStatus policySetVersionStatus = policySetCache.LatestVersion.Status;

			System.Xml.XmlDocument originalCatalogue = new System.Xml.XmlDocument();
			originalCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			string[] searchTokens = new string[] { "Addresses", "Address", "AddressGroup", "AddressCollection", "SenderAddressCollectionId", "RecipientAddressCollectionId" };
			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, true, searchTokens);

			PolicyConverterBase converter = new PolicySetVersionConverter_2_1(policySetCache, AddConversionMessage);
			converter.Convert();
			converter.ConvertCompiledPolicySets();

			Assert.AreEqual(policySetVersionStatus, policySetCache.LatestVersion.Status, "Expected the status to be unchanged");

			XmlDocument convertedCatalogue = new XmlDocument();
			convertedCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);


			Dictionary<string, int> expectedRoutingTableAttributes = new Dictionary<string, int>();
			expectedRoutingTableAttributes["{40AD6174-72D2-4C97-8CF6-FC67FE786302}"] = 3;
			expectedRoutingTableAttributes["{BC39CB1E-D597-4675-BE38-27752FD42A99}"] = 3;
			expectedRoutingTableAttributes["{A4CFB401-4F07-4D87-96AB-D557ED8A26CB}"] = 3;
			expectedRoutingTableAttributes["{9D86AC33-1754-4EB4-B6E0-3C283B52B414}"] = 3;
			CheckConvertedRoutingTableData(originalCatalogue, convertedCatalogue, expectedRoutingTableAttributes);
			CheckRoutingItemCollections(convertedCatalogue, "Workshare.DirectorySearcher.dll", "Workshare.Policy.Routing.LDAPRouter");

			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, false, searchTokens);
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("SenderAddressCollectionId"));
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("RecipientAddressCollectionId"));
			Assert.AreEqual(2, policySetCache.LatestVersion.CompiledPolicySets.Count, "Expected the same amount of compiled policy sets after a conversion");

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual("2.1", policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}
		public void TestUpgradeInternalExternalVersion_1_1_ToLatest()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test Policy Set based on version 1.1 format for internal external.policy");

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			int compiledPolicySetsCount = policySetCache.LatestVersion.CompiledPolicySets.Count;
			PolicySetVersionStatus policySetVersionStatus = policySetCache.LatestVersion.Status;

			System.Xml.XmlDocument originalCatalogue = new System.Xml.XmlDocument();
			originalCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			string[] searchTokens = new string[] { "Addresses", "Address", "AddressGroup", "AddressCollection", "SenderAddressCollectionId", "RecipientAddressCollectionId" };
			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, true, searchTokens);

			m_conversionMessages.Clear();
			PolicyConverterBase converter = new PolicySetVersionConverter_2_1(policySetCache, AddConversionMessage);
			converter.Convert();
			converter.ConvertCompiledPolicySets();

			Assert.AreEqual(policySetVersionStatus, policySetCache.LatestVersion.Status, "Expected the status to be unchanged");
			Assert.AreEqual(1, m_conversionMessages.Count, "Incorrect number of conversion messages for conversion to 2.0");

			XmlDocument convertedCatalogue = new XmlDocument();
			convertedCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			Dictionary<string, int> expectedRoutingTableAttributes = new Dictionary<string, int>();
			expectedRoutingTableAttributes["{76F28B5E-E458-45C4-BF68-42B075EE83C5}"] = 4;
			expectedRoutingTableAttributes["{79171CB4-014C-46EE-9CCA-B7D9418E6529}"] = 3;
			expectedRoutingTableAttributes["{C4E8D1C2-1E49-4BFD-8D8E-378A0C1D305E}"] = 3;
			expectedRoutingTableAttributes["{405E9F94-F72D-4AEE-9C0C-7BB3A4C090D9}"] = 3;
			CheckConvertedRoutingTableData(originalCatalogue, convertedCatalogue, expectedRoutingTableAttributes);
			CheckRoutingItemCollections(convertedCatalogue, "Workshare.InternalExternalResolver.dll", "Workshare.Policy.Routing.InternalExternalRouter");

			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, false, searchTokens);
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("SenderAddressCollectionId"));
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("RecipientAddressCollectionId"));
			Assert.AreEqual(2, policySetCache.LatestVersion.CompiledPolicySets.Count, "Expected the same amount of compiled policy sets after a conversion");

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual("2.1", policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}
		public void TestUpgradeVersion_1_0_ToLatest()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test Policy Set based on version 1.0 format.policy");

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			int compiledPolicySetsCount = policySetCache.LatestVersion.CompiledPolicySets.Count;
			PolicySetVersionStatus policySetVersionStatus = policySetCache.LatestVersion.Status;

			System.Xml.XmlDocument originalCatalogue = new System.Xml.XmlDocument();
			originalCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			string[] searchTokens = new string[] { "SmtpRoutingTable", "HttpRoutingTable", "ActiveContentRoutingTable" };
			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, true, searchTokens);

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);
			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(policySetVersionStatus, policySetCache.LatestVersion.Status, "Expected the status to be unchanged");

			XmlDocument convertedCatalogue = new XmlDocument();
			convertedCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			Dictionary<string, int> expectedRoutingTableAttributes = new Dictionary<string, int>();
			expectedRoutingTableAttributes["{76ABAAA1-08F9-4157-9B72-101F50954086}"] = 4;
			expectedRoutingTableAttributes["{32035E05-814B-4834-A7AF-36264E01B36F}"] = 3;
			expectedRoutingTableAttributes["{F5F9F02D-456B-4877-B4D4-C8B8E9026D75}"] = 3;
			CheckConvertedRoutingTableData(originalCatalogue, convertedCatalogue, expectedRoutingTableAttributes);
			CheckRoutingItemCollections(convertedCatalogue, "Workshare.InternalExternalResolver.dll", "Workshare.Policy.Routing.InternalExternalRouter");

			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, false, searchTokens);
					   
			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}
		public void TestConvertPolicySetWithVersion()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test policy with versioning.policy");
			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual("1.0", policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}