예제 #1
0
		public void AttributeString ()
		{
			PolicyStatementAttribute psa = PolicyStatementAttribute.LevelFinal;
			PolicyStatement ps = new PolicyStatement (new PermissionSet (PermissionState.None));
			ps.Attributes = psa;
			MyCodeGroup cg = new MyCodeGroup(new AllMembershipCondition (), ps);
			Assert.AreEqual (psa.ToString(), cg.AttributeString, "AttributeString");
		}
예제 #2
0
        public SecurityElement ToXml(PolicyLevel level)
        {
            SecurityElement element = new SecurityElement("PolicyStatement");

            element.AddAttribute("version", "1");

            if (attrs != PolicyStatementAttribute.Nothing)
            {
                element.AddAttribute("Attributes", attrs.ToString());
            }

            element.AddChild(PermissionSet.ToXml());

            return(element);
        }
예제 #3
0
        public SecurityElement ToXml(PolicyLevel level)
        {
            SecurityElement element;

            element = new SecurityElement("PolicyStatement");
            element.AddAttribute
                ("class",
                SecurityElement.Escape(typeof(PolicyStatement).
                                       AssemblyQualifiedName));
            element.AddAttribute("version", "1");
            if (attributes != PolicyStatementAttribute.Nothing)
            {
                element.AddAttribute("Attributes", attributes.ToString());
            }
            if (permSet != null)
            {
                NamedPermissionSet namedSet;
                namedSet = (permSet as NamedPermissionSet);
                if (namedSet != null)
                {
                    if (level != null &&
                        level.GetNamedPermissionSet(namedSet.Name) != null)
                    {
                        element.AddAttribute
                            ("PermissionSetName",
                            SecurityElement.Escape(namedSet.Name));
                    }
                    else
                    {
                        element.AddChild(permSet.ToXml());
                    }
                }
                else
                {
                    element.AddChild(permSet.ToXml());
                }
            }
            return(element);
        }
예제 #4
0
        private void Resolve_Zone(PolicyLevel level, SecurityZone z, PolicyStatementAttribute attr, bool unrestricted, int count)
        {
            string   prefix = z.ToString() + "-" + attr.ToString() + "-";
            Evidence e      = new Evidence();

            e.AddHost(new Zone(z));
            PolicyStatement result = level.Resolve(e);

            if (unrestricted)
            {
                Assert.AreEqual(attr, result.Attributes, prefix + "Attributes");
                switch (attr)
                {
                case PolicyStatementAttribute.Nothing:
                    Assert.AreEqual(String.Empty, result.AttributeString, prefix + "AttributeString");
                    break;

                case PolicyStatementAttribute.Exclusive:
                    Assert.AreEqual("Exclusive", result.AttributeString, prefix + "AttributeString");
                    break;

                case PolicyStatementAttribute.LevelFinal:
                    Assert.AreEqual("LevelFinal", result.AttributeString, prefix + "AttributeString");
                    break;

                case PolicyStatementAttribute.All:
                    Assert.AreEqual("Exclusive LevelFinal", result.AttributeString, prefix + "AttributeString");
                    break;
                }
            }
            else
            {
                Assert.AreEqual(PolicyStatementAttribute.Nothing, result.Attributes, prefix + "Attributes");
                Assert.AreEqual(String.Empty, result.AttributeString, prefix + "AttributeString");
            }
            Assert.AreEqual(unrestricted, result.PermissionSet.IsUnrestricted(), prefix + "IsUnrestricted");
            Assert.AreEqual(count, result.PermissionSet.Count, prefix + "Count");
        }
		private void Resolve_Zone (PolicyLevel level, SecurityZone z, PolicyStatementAttribute attr, bool unrestricted, int count)
		{
			string prefix = z.ToString () + "-" + attr.ToString () + "-";
			Evidence e = new Evidence ();
			e.AddHost (new Zone (z));
			PolicyStatement result = level.Resolve (e);
			if (unrestricted) {
				Assert.AreEqual (attr, result.Attributes, prefix + "Attributes");
				switch (attr) {
					case PolicyStatementAttribute.Nothing:
						Assert.AreEqual (String.Empty, result.AttributeString, prefix + "AttributeString");
						break;
					case PolicyStatementAttribute.Exclusive:
						Assert.AreEqual ("Exclusive", result.AttributeString, prefix + "AttributeString");
						break;
					case PolicyStatementAttribute.LevelFinal:
						Assert.AreEqual ("LevelFinal", result.AttributeString, prefix + "AttributeString");
						break;
					case PolicyStatementAttribute.All:
						Assert.AreEqual ("Exclusive LevelFinal", result.AttributeString, prefix + "AttributeString");
						break;
				}
			}
			else {
				Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, prefix + "Attributes");
				Assert.AreEqual (String.Empty, result.AttributeString, prefix + "AttributeString");
			}
			Assert.AreEqual (unrestricted, result.PermissionSet.IsUnrestricted (), prefix + "IsUnrestricted");
			Assert.AreEqual (count, result.PermissionSet.Count, prefix + "Count");
		}