Copy() public method

public Copy ( ) : IPermission
return IPermission
Ejemplo n.º 1
0
		public void PermissionStateUnrestricted () 
		{
			PrincipalPermission p = new PrincipalPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (p, "PrincipalPermission(PermissionState.Unrestricted)");
			Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
			PrincipalPermission copy = (PrincipalPermission) p.Copy ();
			Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			// Note: Unrestricted isn't shown in XML
		}
		public void PermissionStateUnrestricted () 
		{
			PrincipalPermission p = new PrincipalPermission (PermissionState.Unrestricted);
			AssertNotNull ("PrincipalPermission(PermissionState.Unrestricted)", p);
			Assert ("IsUnrestricted", p.IsUnrestricted ());
			PrincipalPermission copy = (PrincipalPermission) p.Copy ();
			AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ());
			// Note: Unrestricted isn't shown in XML
		}
Ejemplo n.º 3
0
        public IPermission Intersect(IPermission target)
        {
            PrincipalPermission pp = Cast(target);

            if (pp == null)
            {
                return(null);
            }

            if (IsUnrestricted())
            {
                return(pp.Copy());
            }
            if (pp.IsUnrestricted())
            {
                return(Copy());
            }

            PrincipalPermission intersect = new PrincipalPermission(PermissionState.None);

            foreach (PrincipalInfo pi in principals)
            {
                foreach (PrincipalInfo opi in pp.principals)
                {
                    if (pi.IsAuthenticated == opi.IsAuthenticated)
                    {
                        string name = null;
                        if ((pi.Name == opi.Name) || (opi.Name == null))
                        {
                            name = pi.Name;
                        }
                        else if (pi.Name == null)
                        {
                            name = opi.Name;
                        }
                        string role = null;
                        if ((pi.Role == opi.Role) || (opi.Role == null))
                        {
                            role = pi.Role;
                        }
                        else if (pi.Role == null)
                        {
                            role = opi.Role;
                        }
                        if ((name != null) || (role != null))
                        {
                            PrincipalInfo ipi = new PrincipalInfo(name, role, pi.IsAuthenticated);
                            intersect.principals.Add(ipi);
                        }
                    }
                }
            }

            return((intersect.principals.Count > 0) ? intersect : null);
        }
		public void PermissionStateNone () 
		{
			PrincipalPermission p = new PrincipalPermission (PermissionState.None);
			AssertNotNull ("PrincipalPermission(PermissionState.None)", p);
			Assert ("IsUnrestricted", !p.IsUnrestricted ());
			PrincipalPermission copy = (PrincipalPermission) p.Copy ();
			AssertEquals ("Copy.IsUnrestricted", p.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = p.ToXml ();
			Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className));
			AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string));
		}
Ejemplo n.º 5
0
		public void PermissionStateNone () 
		{
			PrincipalPermission p = new PrincipalPermission (PermissionState.None);
			Assert.IsNotNull (p, "PrincipalPermission(PermissionState.None)");
			Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
			PrincipalPermission copy = (PrincipalPermission) p.Copy ();
			Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = p.ToXml ();
			Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
		}
Ejemplo n.º 6
0
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission will be null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not an instance of the same class as the current permission. </exception>
        public IPermission Intersect(IPermission target)
        {
            PrincipalPermission principalPermission = this.Cast(target);

            if (principalPermission == null)
            {
                return(null);
            }
            if (this.IsUnrestricted())
            {
                return(principalPermission.Copy());
            }
            if (principalPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            PrincipalPermission principalPermission2 = new PrincipalPermission(PermissionState.None);

            foreach (object obj in this.principals)
            {
                PrincipalPermission.PrincipalInfo principalInfo = (PrincipalPermission.PrincipalInfo)obj;
                foreach (object obj2 in principalPermission.principals)
                {
                    PrincipalPermission.PrincipalInfo principalInfo2 = (PrincipalPermission.PrincipalInfo)obj2;
                    if (principalInfo.IsAuthenticated == principalInfo2.IsAuthenticated)
                    {
                        string text = null;
                        if (principalInfo.Name == principalInfo2.Name || principalInfo2.Name == null)
                        {
                            text = principalInfo.Name;
                        }
                        else if (principalInfo.Name == null)
                        {
                            text = principalInfo2.Name;
                        }
                        string text2 = null;
                        if (principalInfo.Role == principalInfo2.Role || principalInfo2.Role == null)
                        {
                            text2 = principalInfo.Role;
                        }
                        else if (principalInfo.Role == null)
                        {
                            text2 = principalInfo2.Role;
                        }
                        if (text != null || text2 != null)
                        {
                            PrincipalPermission.PrincipalInfo value = new PrincipalPermission.PrincipalInfo(text, text2, principalInfo.IsAuthenticated);
                            principalPermission2.principals.Add(value);
                        }
                    }
                }
            }
            return((principalPermission2.principals.Count <= 0) ? null : principalPermission2);
        }
		public void FromXml () 
		{
			PrincipalPermission p = new PrincipalPermission (PermissionState.None);
			SecurityElement se = p.ToXml ();
			AssertNotNull ("ToXml()", se);

			PrincipalPermission p2 = (PrincipalPermission) p.Copy ();
			p2.FromXml (se);
			AssertEquals ("FromXml-Copy", p.ToString (), p2.ToString ());

			string className = (string) se.Attributes ["class"];
			string version = (string) se.Attributes ["version"];

			SecurityElement se2 = new SecurityElement (se.Tag);
			se2.AddAttribute ("class", className);
			se2.AddAttribute ("version", version);
			p2.FromXml (se2);

			SecurityElement sec = new SecurityElement ("Identity");
			sec.AddAttribute ("Authenticated", "true");
			se2.AddChild (sec);
			p2.FromXml (se2);
			Assert ("FromXml-Unrestricted", p2.IsUnrestricted ());
		}