public void ToFromXml_RoundTrip()
        {
            PolicyStatement ps1 = new PolicyStatement(Unrestricted, PolicyStatementAttribute.All);
            SecurityElement se  = ps1.ToXml();

            PolicyStatement ps2 = new PolicyStatement(null);

            ps2.FromXml(se, null);

            Assert.AreEqual(ps1.ToXml().ToString(), ps2.ToXml().ToString(), "Xml");
        }
        public void Constructor_Copy()
        {
            PermissionSet   original = new PermissionSet(PermissionState.None);
            PolicyStatement ps       = new PolicyStatement(original, PolicyStatementAttribute.All);

            Assert.AreEqual(Empty.ToString(), ps.PermissionSet.ToString(), "PermissionSet");
            Assert.AreEqual(ps.ToXml().ToString(), ps.Copy().ToXml().ToString(), "Copy");

            original.AddPermission(new SecurityPermission(SecurityPermissionFlag.AllFlags));
            Assert.AreEqual(Empty.ToString(), ps.PermissionSet.ToString(), "PermissionSet");
            Assert.AreEqual(ps.ToXml().ToString(), ps.Copy().ToXml().ToString(), "Copy");
        }
Exemplo n.º 3
0
        public static void PolicyStatementCallMethods()
        {
            PolicyStatement ps     = new PolicyStatement(new PermissionSet(new PermissionState()));
            PolicyStatement ps2    = ps.Copy();
            bool            equals = ps.Equals(ps2);
            int             hash   = ps.GetHashCode();
            SecurityElement se     = new SecurityElement("");
            PolicyLevel     pl     = (PolicyLevel)Activator.CreateInstance(typeof(PolicyLevel), true);

            ps.FromXml(se);
            ps.FromXml(se, pl);
            se = ps.ToXml();
            se = ps.ToXml(pl);
        }
Exemplo n.º 4
0
        public static void PolicyStatementCallMethods()
        {
            PolicyStatement ps     = new PolicyStatement(new PermissionSet(new PermissionState()));
            PolicyStatement ps2    = ps.Copy();
            bool            equals = ps.Equals(ps2);
            int             hash   = ps.GetHashCode();
            SecurityElement se     = new SecurityElement("");
            PolicyLevel     pl     = (PolicyLevel)FormatterServices.GetUninitializedObject(typeof(PolicyLevel));

            ps.FromXml(se);
            ps.FromXml(se, pl);
            se = ps.ToXml();
            se = ps.ToXml(pl);
        }
Exemplo n.º 5
0
    //<Snippet13>
    // Demonstrate the use of ResolvePolicy for the supplied evidence and a specified policy level.
    private static void CheckEvidence(PolicyLevel pLevel, Evidence evidence)
    {
        // Display the code groups to which the evidence belongs.
        Console.WriteLine("\tResolvePolicy for the given evidence: ");
        IEnumerator codeGroup = evidence.GetEnumerator();

        while (codeGroup.MoveNext())
        {
            Console.WriteLine("\t\t" + ((CodeGroup)codeGroup.Current).Name);
        }
        Console.WriteLine("The current evidence belongs to the following root CodeGroup:");
        // pLevel is the current PolicyLevel, evidence is the Evidence to be resolved.
        CodeGroup cg1 = pLevel.ResolveMatchingCodeGroups(evidence);

        Console.WriteLine(pLevel.Label + " Level");
        Console.WriteLine("\tRoot CodeGroup = " + cg1.Name);

        // Show how Resolve is used to determine the set of permissions that
        // the security system grants to code, based on the evidence.

        // Show the granted permissions.
        Console.WriteLine("\nCurrent permissions granted:");
        PolicyStatement pState = pLevel.Resolve(evidence);

        Console.WriteLine(pState.ToXml().ToString());

        return;
    }
        public void ToFromXml_PolicyLevelNull()
        {
            PolicyStatement ps = new PolicyStatement(null);
            SecurityElement se = ps.ToXml(null);

            ps.FromXml(se, null);
        }
        public void Constructor_PermissionSetPolicyStatementAttribute_Null()
        {
            PolicyStatement ps = new PolicyStatement(null, PolicyStatementAttribute.All);

            Assert.AreEqual(PolicyStatementAttribute.All, ps.Attributes, "Attributes");
            Assert.AreEqual("Exclusive LevelFinal", ps.AttributeString, "AttributeString");
            Assert.AreEqual(Empty.ToString(), ps.PermissionSet.ToString(), "PermissionSet");
            Assert.AreEqual(ps.ToXml().ToString(), ps.Copy().ToXml().ToString(), "Copy");
        }
        public void Constructor_PermissionSet_Null()
        {
            PolicyStatement ps = new PolicyStatement(null);

            Assert.AreEqual(PolicyStatementAttribute.Nothing, ps.Attributes, "Attributes");
            Assert.AreEqual(String.Empty, ps.AttributeString, "AttributeString");
            Assert.AreEqual(Empty.ToString(), ps.PermissionSet.ToString(), "PermissionSet");
            Assert.AreEqual(ps.ToXml().ToString(), ps.Copy().ToXml().ToString(), "Copy");
        }
        public void Constructor_PermissionSet_Unrestricted()
        {
            PermissionSet   pset = new PermissionSet(PermissionState.Unrestricted);
            PolicyStatement ps   = new PolicyStatement(pset);

            Assert.AreEqual(PolicyStatementAttribute.Nothing, ps.Attributes, "Attributes");
            Assert.AreEqual(String.Empty, ps.AttributeString, "AttributeString");
            Assert.AreEqual(Unrestricted.ToString(), ps.PermissionSet.ToString(), "PermissionSet");
            Assert.AreEqual(ps.ToXml().ToString(), ps.Copy().ToXml().ToString(), "Copy");
        }
Exemplo n.º 10
0
    // If a class attribute is not found in the specified PolicyStatement,
    // add a child XML element with an added class attribute.
    private static void addXmlMember(ref PolicyStatement policyStatement)
    {
        SecurityElement xmlElement = policyStatement.ToXml();

        if (xmlElement.Attribute("class") == null)
        {
            SecurityElement newElement =
                new SecurityElement("PolicyStatement");
            newElement.AddAttribute("class", policyStatement.ToString());
            newElement.AddAttribute("version", "1.1");

            newElement.AddChild(new SecurityElement("PermissionSet"));

            policyStatement.FromXml(newElement);

            Console.Write("Added the class attribute and modified its ");
            Console.WriteLine("version number.\n" + newElement.ToString());
        }
    }