CreatePermissionSet() public method

public CreatePermissionSet ( ) : PermissionSet
return PermissionSet
        static bool TryProcessPermissionSetAttribute(SecurityDeclaration declaration, out PermissionSet set)
        {
            set = null;

            if (!declaration.HasSecurityAttributes && declaration.SecurityAttributes.Count != 1)
            {
                return(false);
            }

            var security_attribute = declaration.SecurityAttributes [0];

            if (!security_attribute.AttributeType.IsTypeOf("System.Security.Permissions", "PermissionSetAttribute"))
            {
                return(false);
            }

            var named_argument = security_attribute.Properties [0];

            if (named_argument.Name != "XML")
            {
                throw new NotSupportedException();
            }

            var attribute = new SSP.PermissionSetAttribute((SSP.SecurityAction)declaration.Action);

            attribute.XML = (string)named_argument.Argument.Value;

            set = attribute.CreatePermissionSet();
            return(true);
        }
		static bool TryProcessPermissionSetAttribute (SecurityDeclaration declaration, out PermissionSet set)
		{
			set = null;

			if (!declaration.HasSecurityAttributes && declaration.SecurityAttributes.Count != 1)
				return false;

			var security_attribute = declaration.SecurityAttributes [0];
			if (!security_attribute.AttributeType.IsTypeOf ("System.Security.Permissions", "PermissionSetAttribute"))
				return false;

			var attribute = new SSP.PermissionSetAttribute ((SSP.SecurityAction) declaration.Action);

			var named_argument = security_attribute.Properties [0];
			string value = (string) named_argument.Argument.Value;
			switch (named_argument.Name) {
			case "XML":
				attribute.XML = value;
				break;
			case "Name":
				attribute.Name = value;
				break;
			default:
				throw new NotImplementedException (named_argument.Name);
			}

			set = attribute.CreatePermissionSet ();
			return true;
		}
		public void Default () 
		{
			PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
			Assert.IsNull (a.File, "File");
			Assert.IsNull (a.Hex, "Hex");
			Assert.IsNull (a.Name, "Name");
			Assert.IsNull (a.XML, "XML");
			Assert.IsFalse (a.UnicodeEncoded, "UnicodeEncoded");
			Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
			Assert.IsFalse (a.Unrestricted, "Unrestricted");

			IPermission perm = a.CreatePermission ();
			Assert.IsNull (perm, "CreatePermission");

			PermissionSet ps = a.CreatePermissionSet ();
			Assert.AreEqual (0, ps.Count, "CreatePermissionSet");
		}
Beispiel #4
0
        static bool TryProcessPermissionSetAttribute(SecurityDeclaration declaration, out PermissionSet set)
        {
            set = null;

            if (!declaration.HasSecurityAttributes && declaration.SecurityAttributes.Count != 1)
            {
                return(false);
            }

            var security_attribute = declaration.SecurityAttributes [0];

            if (!security_attribute.AttributeType.IsTypeOf("System.Security.Permissions", "PermissionSetAttribute"))
            {
                return(false);
            }

            var attribute = new SSP.PermissionSetAttribute((SSP.SecurityAction)declaration.Action);

            var    named_argument = security_attribute.Properties [0];
            string value          = (string)named_argument.Argument.Value;

            switch (named_argument.Name)
            {
            case "XML":
                attribute.XML = value;
                break;

            case "Name":
                attribute.Name = value;
                break;

            default:
                throw new NotImplementedException(named_argument.Name);
            }

            set = attribute.CreatePermissionSet();
            return(true);
        }
Beispiel #5
0
		static bool TryProcessPermissionSetAttribute (SecurityDeclaration declaration, out PermissionSet set)
		{
			set = null;

			if (!declaration.HasSecurityAttributes && declaration.SecurityAttributes.Count != 1)
				return false;

			var security_attribute = declaration.SecurityAttributes [0];
			var attribute_type = security_attribute.AttributeType;

			if (attribute_type.Name != "PermissionSetAttribute" || attribute_type.Namespace != "System.Security.Permissions")
				return false;

			var named_argument = security_attribute.Properties [0];
			if (named_argument.Name != "XML")
				throw new NotSupportedException ();

			var attribute = new SSP.PermissionSetAttribute ((SSP.SecurityAction) declaration.Action);
			attribute.XML = (string) named_argument.Argument.Value;

			set = attribute.CreatePermissionSet ();
			return true;
		}
		private void Unification (string xml)
		{
			PermissionSetAttribute psa = new PermissionSetAttribute (SecurityAction.Assert);
			psa.XML = xml;
			string pset = psa.CreatePermissionSet ().ToString ();
			string currentVersion = typeof (string).Assembly.GetName ().Version.ToString ();
			Assert.IsTrue (pset.IndexOf (currentVersion) > 0, currentVersion);
		}
		public void Unrestricted () 
		{
			PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
			a.Unrestricted = true;
			Assert.IsNull (a.File, "File");
#if NET_2_0
			Assert.IsNull (a.Hex, "Hex");
#endif
			Assert.IsNull (a.Name, "Name");
			Assert.IsNull (a.XML, "XML");

			PermissionSet ps = a.CreatePermissionSet ();
			Assert.IsTrue (ps.IsUnrestricted (), "CreatePermissionSet.IsUnrestricted");
		}
		public void Hex_BigEndianUnicode_Permission ()
		{
			SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Assertion);
			PermissionSet ps = new PermissionSet (PermissionState.None);
			ps.AddPermission (sp);

			PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
			a.UnicodeEncoded = true;
			a.Hex = "003C005000650072006D0069007300730069006F006E00530065007400200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0053006500740022000D000A00760065007200730069006F006E003D002200310022003E000D000A003C0049005000650072006D0069007300730069006F006E00200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0073002E00530065006300750072006900740079005000650072006D0069007300730069006F006E002C0020006D00730063006F0072006C00690062002C002000560065007200730069006F006E003D0032002E0030002E0033003600300030002E0030002C002000430075006C0074007500720065003D006E00650075007400720061006C002C0020005000750062006C00690063004B006500790054006F006B0065006E003D00620037003700610035006300350036003100390033003400650030003800390022000D000A00760065007200730069006F006E003D002200310022000D000A0046006C006100670073003D00220041007300730065007200740069006F006E0022002F003E000D000A003C002F005000650072006D0069007300730069006F006E005300650074003E000D000";
			PermissionSet psbeu = a.CreatePermissionSet ();
			Assert.IsTrue (ps.Equals (psbeu), "HEX-BIGENDIAN-UNICODE");
		}
		public void Hex_ASCII_Permission ()
		{
			SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Assertion);
			PermissionSet ps = new PermissionSet (PermissionState.None);
			ps.AddPermission (sp);

			PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
			a.Hex = "3C5065726D697373696F6E53657420636C6173733D2253797374656D2E53656375726974792E5065726D697373696F6E536574220D0A76657273696F6E3D2231223E0D0A3C495065726D697373696F6E20636C6173733D2253797374656D2E53656375726974792E5065726D697373696F6E732E53656375726974795065726D697373696F6E2C206D73636F726C69622C2056657273696F6E3D322E302E333630302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D62373761356335363139333465303839220D0A76657273696F6E3D2231220D0A466C6167733D22417373657274696F6E222F3E0D0A3C2F5065726D697373696F6E5365743E0D0A";
			PermissionSet psa = a.CreatePermissionSet ();
			Assert.IsTrue (ps.Equals (psa), "HEX-ASCII");
		}
		public void Hex_Bad ()
		{
			PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
			a.Hex = "g";
			Assert.AreEqual ("g", a.Hex, "Bad Hex");
			a.CreatePermissionSet ();
		}
		static bool TryProcessPermissionSetAttribute (SecurityDeclaration declaration, out PermissionSet set)
		{
			set = null;

			if (!declaration.HasSecurityAttributes)
				return false;

			var attributes = declaration.SecurityAttributes;
			if (attributes.Count != 1)
				return false;

			var security_attribute = attributes [0];
			var attribute_type = security_attribute.AttributeType;
			if (attribute_type.Name != "PermissionSetAttribute" || attribute_type.Namespace != "System.Security.Permissions")
				return false;

			var attribute = new SSP.PermissionSetAttribute ((SSP.SecurityAction) declaration.Action);

			foreach (var named_argument in security_attribute.Properties) {
				object value = named_argument.Argument.Value;
				switch (named_argument.Name) {
				case "Unrestricted":
					attribute.Unrestricted = (bool) value;
					break;
				case "UnicodeEncoded":
					attribute.UnicodeEncoded = (bool) value;
					break;
				case "XML":
					attribute.XML = (string) value;
					break;
				case "Name":
					attribute.Name = (string) value;
					break;
				case "File":
					attribute.File = (string) value;
					break;
				case "Hex":
					attribute.Hex = (string) value;
					break;
				default:
					throw new NotImplementedException (named_argument.Name);
				}
			}

			set = attribute.CreatePermissionSet ();
			return true;
		}
        static bool TryProcessPermissionSetAttribute(SecurityDeclaration declaration, out PermissionSet set)
        {
            set = null;

            if (!declaration.HasSecurityAttributes)
            {
                return(false);
            }

            var attributes = declaration.SecurityAttributes;

            if (attributes.Count != 1)
            {
                return(false);
            }

            var security_attribute = attributes [0];
            var attribute_type     = security_attribute.AttributeType;

            if (attribute_type.Name != "PermissionSetAttribute" || attribute_type.Namespace != "System.Security.Permissions")
            {
                return(false);
            }

            var attribute = new SSP.PermissionSetAttribute((SSP.SecurityAction)declaration.Action);

            foreach (var named_argument in security_attribute.Properties)
            {
                object value = named_argument.Argument.Value;
                switch (named_argument.Name)
                {
                case "Unrestricted":
                    attribute.Unrestricted = (bool)value;
                    break;

                case "UnicodeEncoded":
                    attribute.UnicodeEncoded = (bool)value;
                    break;

                case "XML":
                    attribute.XML = (string)value;
                    break;

                case "Name":
                    attribute.Name = (string)value;
                    break;

                case "File":
                    attribute.File = (string)value;
                    break;

                case "Hex":
                    attribute.Hex = (string)value;
                    break;

                default:
                    throw new NotImplementedException(named_argument.Name);
                }
            }

            set = attribute.CreatePermissionSet();
            return(true);
        }