// <Snippet2>
 // IsSubsetOf determines whether the current permission is a subset of the specified permission.
 private bool IsSubsetOfDemo()
 {
     try
     {
         //<Snippet9>
         GacIdentityPermission Gac1 = new GacIdentityPermission();
         GacIdentityPermission Gac2 = new GacIdentityPermission(PermissionState.None);
         if (Gac1.Equals(Gac2))
         {
             Console.WriteLine("GacIdentityPermission() equals GacIdentityPermission(PermissionState.None).");
         }
         //</Snippet9>
         if (Gac1.IsSubsetOf(Gac2))
         {
             Console.WriteLine(Gac1 + " is a subset of " + Gac2);
         }
         else
         {
             Console.WriteLine(Gac1 + " is not a subset of " + Gac2);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("An exception was thrown : " + e);
         return(false);
     }
     return(true);
 }
    // </Snippet2>
    // <Snippet3>
    // Union creates a new permission that is the union of the current permission
    // and the specified permission.
    private bool UnionDemo()
    {
        //<Snippet7>
        GacIdentityPermission Gac1 = new GacIdentityPermission(PermissionState.None);
        //</Snippet7>
        //<Snippet8>
        GacIdentityPermission Gac2 = new GacIdentityPermission();

        //</Snippet8>
        try
        {
            GacIdentityPermission p3 = (GacIdentityPermission)Gac1.Union(Gac2);

            if (p3 != null)
            {
                Console.WriteLine("The union of two GacIdentityPermissions was successful.");
            }
            else
            {
                Console.WriteLine("The union of two GacIdentityPermissions failed.");
                return(false);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("An exception was thrown : " + e);
            return(false);
        }

        return(true);
    }
    // </Snippet3>
    // <Snippet4>
    // Intersect creates and returns a new permission that is the intersection of the
    // current permission and the specified permission.
    private bool IntersectDemo()
    {
        GacIdentityPermission Gac1 = new GacIdentityPermission();
        GacIdentityPermission Gac2 = new GacIdentityPermission();

        try
        {
            GacIdentityPermission p3 = (GacIdentityPermission)Gac1.Intersect(Gac2);
            if (p3 != null)
            {
                Console.WriteLine("The intersection of the two permissions = " + p3.ToString() + "\n");
            }
            else
            {
                Console.WriteLine("The intersection of the two permissions is null.\n");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("An exception was thrown : " + e);
            return(false);
        }

        return(true);
    }
Exemplo n.º 4
0
        public void Union_DifferentPermissions()
        {
            GacIdentityPermission a = new GacIdentityPermission(PermissionState.None);
            SecurityPermission    b = new SecurityPermission(PermissionState.None);

            a.Union(b);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //<Snippet2>
            GacInstalled myGacInstalled = new GacInstalled();

            //</Snippet2>

            //<Snippet3>
            Object []             hostEvidence     = { myGacInstalled };
            Object []             assemblyEvidence = {};
            Evidence              myEvidence       = new Evidence(hostEvidence, assemblyEvidence);
            GacIdentityPermission myPerm           =
                (GacIdentityPermission)myGacInstalled.CreateIdentityPermission(
                    myEvidence);

            Console.WriteLine(myPerm.ToXml().ToString());
            //</Snippet3>

            //<Snippet4>
            GacInstalled myGacInstalledCopy =
                (GacInstalled)myGacInstalled.Copy();
            bool result = myGacInstalled.Equals(myGacInstalledCopy);

            //</Snippet4>

            //<Snippet5>
            Console.WriteLine(
                "Hashcode = " + myGacInstalled.GetHashCode().ToString());
            //</Snippet5>

            //<Snippet6>
            Console.WriteLine(myGacInstalled.ToString());
            //</Snippet6>
        }
Exemplo n.º 6
0
        public void IsSubsetOf_DifferentPermissions()
        {
            GacIdentityPermission a = new GacIdentityPermission(PermissionState.None);
            SecurityPermission    b = new SecurityPermission(PermissionState.None);

            a.IsSubsetOf(b);
        }
    //</Snippet5>
    //<Snippet6>
    // ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
    // permission with the specified state from the XML encoding.
    private bool ToFromXmlDemo()
    {
        GacIdentityPermission Gac1 = new GacIdentityPermission();
        GacIdentityPermission Gac2 = new GacIdentityPermission();

        Console.WriteLine("**************************************************************************");
        try
        {
            Gac2 = new GacIdentityPermission(PermissionState.None);
            Gac2.FromXml(Gac1.ToXml());
            bool result = Gac2.Equals(Gac1);
            if (Gac2.IsSubsetOf(Gac1) && Gac1.IsSubsetOf(Gac2))
            {
                Console.WriteLine("Result of ToFromXml = " + Gac2.ToString());
            }
            else
            {
                Console.WriteLine(Gac2.ToString());
                Console.WriteLine(Gac1.ToString());
                return(false);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("ToFromXml failed. " + e);
            return(false);
        }

        return(true);
    }
Exemplo n.º 8
0
        public void Intersect_DifferentPermissions()
        {
            GacIdentityPermission a = new GacIdentityPermission(PermissionState.None);
            SecurityPermission    b = new SecurityPermission(PermissionState.None);

            a.Intersect(b);
        }
Exemplo n.º 9
0
        public void FromXml_WrongTagCase()
        {
            GacIdentityPermission gip = new GacIdentityPermission();
            SecurityElement       se  = gip.ToXml();

            se.Tag = "IPERMISSION";             // instead of IPermission
            gip.FromXml(se);
        }
Exemplo n.º 10
0
        public void FromXml_WrongTag()
        {
            GacIdentityPermission gip = new GacIdentityPermission();
            SecurityElement       se  = gip.ToXml();

            se.Tag = "IMono";
            gip.FromXml(se);
        }
Exemplo n.º 11
0
        public void FromXml_WrongVersion()
        {
            GacIdentityPermission gip = new GacIdentityPermission();
            SecurityElement       se  = gip.ToXml();

            se.Attributes.Remove("version");
            se.Attributes.Add("version", "2");
            gip.FromXml(se);
        }
Exemplo n.º 12
0
        public void IsSubsetOf()
        {
            GacIdentityPermission gip = new GacIdentityPermission();

            Assert.IsFalse(gip.IsSubsetOf(null), "gip.IsSubsetOf (null)");

            GacIdentityPermission empty = new GacIdentityPermission(PermissionState.None);

            Assert.IsFalse(empty.IsSubsetOf(null), "empty.IsSubsetOf (null)");
        }
Exemplo n.º 13
0
        public void FromXml_NoVersion()
        {
            GacIdentityPermission gip = new GacIdentityPermission();
            SecurityElement       se  = gip.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", se.Attribute("class"));
            gip.FromXml(w);
        }
Exemplo n.º 14
0
        public void FromXml_NoClass()
        {
            GacIdentityPermission gip = new GacIdentityPermission();
            SecurityElement       se  = gip.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("version", se.Attribute("version"));
            gip.FromXml(w);
            // doesn't even care of the class attribute presence
        }
Exemplo n.º 15
0
 public static void GacIdentityPermissionCallMethods()
 {
     GacIdentityPermission gip = new GacIdentityPermission();
     IPermission ip = gip.Copy();
     IPermission ip2 = gip.Intersect(ip);
     bool issubset = gip.IsSubsetOf(ip);
     IPermission ip3 = gip.Union(ip2);
     SecurityElement se = new SecurityElement("");
     gip.FromXml(se);
     se = gip.ToXml();
 }
Exemplo n.º 16
0
        public static void GacIdentityPermissionCallMethods()
        {
            GacIdentityPermission gip = new GacIdentityPermission();
            IPermission           ip  = gip.Copy();
            IPermission           ip2 = gip.Intersect(ip);
            bool            issubset  = gip.IsSubsetOf(ip);
            IPermission     ip3       = gip.Union(ip2);
            SecurityElement se        = new SecurityElement("");

            gip.FromXml(se);
            se = gip.ToXml();
        }
Exemplo n.º 17
0
        public void FromXml_WrongClass()
        {
            GacIdentityPermission gip = new GacIdentityPermission();
            SecurityElement       se  = gip.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", "Wrong" + se.Attribute("class"));
            w.AddAttribute("version", se.Attribute("version"));
            gip.FromXml(w);
            // doesn't care of the class name at that stage
            // anyway the class has already be created so...
        }
Exemplo n.º 18
0
        public void PermissionStateNone()
        {
            GacIdentityPermission gip = new GacIdentityPermission(PermissionState.None);

            SecurityElement se = gip.ToXml();

            // only class and version are present
            Assert.AreEqual(2, se.Attributes.Count, "Xml-Attributes");
            Assert.IsNull(se.Children, "Xml-Children");

            GacIdentityPermission copy = (GacIdentityPermission)gip.Copy();

            Assert.IsFalse(Object.ReferenceEquals(gip, copy), "ReferenceEquals");
        }
Exemplo n.º 19
0
        public void Intersect()
        {
            GacIdentityPermission gip = new GacIdentityPermission();

            GacIdentityPermission intersect = (GacIdentityPermission)gip.Intersect(null);

            Assert.IsNull(intersect, "gip N null");

            GacIdentityPermission empty = new GacIdentityPermission(PermissionState.None);

            intersect = (GacIdentityPermission)gip.Intersect(empty);
            Assert.IsNotNull(intersect, "gip N null");

            intersect = (GacIdentityPermission)gip.Intersect(gip);
            Assert.IsNotNull(intersect, "gip N gip");
        }
Exemplo n.º 20
0
        public void Union()
        {
            GacIdentityPermission gip = new GacIdentityPermission();

            GacIdentityPermission union = (GacIdentityPermission)gip.Union(null);

            Assert.IsNotNull(union, "gip U null");

            GacIdentityPermission empty = new GacIdentityPermission(PermissionState.None);

            union = (GacIdentityPermission)gip.Union(empty);
            Assert.IsNotNull(union, "gip U empty");

            union = (GacIdentityPermission)gip.Union(gip);
            Assert.IsNotNull(union, "gip U gip");

            // note: can't be tested with PermissionState.Unrestricted
        }
Exemplo n.º 21
0
        public void PermissionStateUnrestricted()
        {
            GacIdentityPermission gip = new GacIdentityPermission(PermissionState.Unrestricted);

            // FX 2.0 now supports Unrestricted for Identity Permissions
            // However the XML doesn't show the Unrestricted status...

            SecurityElement se = gip.ToXml();

            // only class and version are present
            Assert.AreEqual(2, se.Attributes.Count, "Xml-Attributes");
            Assert.IsNull(se.Children, "Xml-Children");

            GacIdentityPermission copy = (GacIdentityPermission)gip.Copy();

            Assert.IsFalse(Object.ReferenceEquals(gip, copy), "ReferenceEquals");

            // ... and because it doesn't implement IUnrestrictedPermission
            // there is not way to know if it's unrestricted so...
            Assert.IsTrue(gip.Equals(new GacIdentityPermission(PermissionState.None)), "Unrestricted==None");
            // there is not much difference after all ;-)
        }
    //</Snippet4>
    //<Snippet5>
    //Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {
        GacIdentityPermission Gac1 = new GacIdentityPermission();
        GacIdentityPermission Gac2 = new GacIdentityPermission();

        Console.WriteLine("**************************************************************************");
        try
        {
            Gac2 = (GacIdentityPermission)Gac1.Copy();
            if (Gac2 != null)
            {
                Console.WriteLine("Result of copy = " + Gac2.ToString() + "\n");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Copy failed : " + Gac1.ToString() + e);
            return(false);
        }

        return(true);
    }
Exemplo n.º 23
0
        public void FromXml_Null()
        {
            GacIdentityPermission gip = new GacIdentityPermission();

            gip.FromXml(null);
        }
Exemplo n.º 24
0
 public void PermissionStateInvalid()
 {
     GacIdentityPermission gip = new GacIdentityPermission((PermissionState)2);
 }
Exemplo n.º 25
0
        public void IsGranted_GacIdentityPermission()
        {
            GacIdentityPermission gip = new GacIdentityPermission();

            Assert.IsTrue(SecurityManager.IsGranted(gip));
        }
Exemplo n.º 26
0
        public void GacIdentityPermission_Empty()
        {
            GacIdentityPermission gip = new GacIdentityPermission();

            Assert.IsNotNull(gip);
        }