예제 #1
0
        public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset)
        {
#if !MOBILE
            if (pset == null)
            {
                throw new ArgumentNullException("pset");
            }
            if ((action == SecurityAction.RequestMinimum) ||
                (action == SecurityAction.RequestOptional) ||
                (action == SecurityAction.RequestRefuse))
            {
                throw new ArgumentOutOfRangeException("action", "Request* values are not permitted");
            }

            RejectIfCreated();

            if (permissions != null)
            {
                /* Check duplicate actions */
                foreach (RefEmitPermissionSet set in permissions)
                {
                    if (set.action == action)
                    {
                        throw new InvalidOperationException("Multiple permission sets specified with the same SecurityAction.");
                    }
                }

                RefEmitPermissionSet[] new_array = new RefEmitPermissionSet [permissions.Length + 1];
                permissions.CopyTo(new_array, 0);
                permissions = new_array;
            }
            else
            {
                permissions = new RefEmitPermissionSet [1];
            }

            permissions [permissions.Length - 1] = new RefEmitPermissionSet(action, pset.ToXml().ToString());
            attrs |= MethodAttributes.HasSecurity;
#endif
        }
예제 #2
0
        internal void AddPermissionRequests(PermissionSet required, PermissionSet optional, PermissionSet refused)
        {
#if !NET_2_1
            if (created)
            {
                throw new InvalidOperationException("Assembly was already saved.");
            }

            // required for base Assembly class (so the permissions
            // can be used even if the assembly isn't saved to disk)
            _minimum  = required;
            _optional = optional;
            _refuse   = refused;

            // required to reuse AddDeclarativeSecurity support
            // already present in the runtime
            if (required != null)
            {
                permissions_minimum     = new RefEmitPermissionSet [1];
                permissions_minimum [0] = new RefEmitPermissionSet(
                    SecurityAction.RequestMinimum, required.ToXml().ToString());
            }
            if (optional != null)
            {
                permissions_optional     = new RefEmitPermissionSet [1];
                permissions_optional [0] = new RefEmitPermissionSet(
                    SecurityAction.RequestOptional, optional.ToXml().ToString());
            }
            if (refused != null)
            {
                permissions_refused     = new RefEmitPermissionSet [1];
                permissions_refused [0] = new RefEmitPermissionSet(
                    SecurityAction.RequestRefuse, refused.ToXml().ToString());
            }
#endif
        }
예제 #3
0
		internal void AddPermissionRequests (PermissionSet required, PermissionSet optional, PermissionSet refused)
		{
#if !NET_2_1
			if (created)
				throw new InvalidOperationException ("Assembly was already saved.");

			// required for base Assembly class (so the permissions
			// can be used even if the assembly isn't saved to disk)
			_minimum = required;
			_optional = optional;
			_refuse = refused;

			// required to reuse AddDeclarativeSecurity support 
			// already present in the runtime
			if (required != null) {
				permissions_minimum = new RefEmitPermissionSet [1];
				permissions_minimum [0] = new RefEmitPermissionSet (
					SecurityAction.RequestMinimum, required.ToXml ().ToString ());
			}
			if (optional != null) {
				permissions_optional = new RefEmitPermissionSet [1];
				permissions_optional [0] = new RefEmitPermissionSet (
					SecurityAction.RequestOptional, optional.ToXml ().ToString ());
			}
			if (refused != null) {
				permissions_refused = new RefEmitPermissionSet [1];
				permissions_refused [0] = new RefEmitPermissionSet (
					SecurityAction.RequestRefuse, refused.ToXml ().ToString ());
			}
#endif
		}
예제 #4
0
		public void AddDeclarativeSecurity (SecurityAction action, PermissionSet pset)
		{
#if !NET_2_1
			if (pset == null)
				throw new ArgumentNullException ("pset");
			if ((action == SecurityAction.RequestMinimum) ||
				(action == SecurityAction.RequestOptional) ||
				(action == SecurityAction.RequestRefuse))
				throw new ArgumentOutOfRangeException ("Request* values are not permitted", "action");

			RejectIfCreated ();

			if (permissions != null) {
				/* Check duplicate actions */
				foreach (RefEmitPermissionSet set in permissions)
					if (set.action == action)
						throw new InvalidOperationException ("Multiple permission sets specified with the same SecurityAction.");

				RefEmitPermissionSet[] new_array = new RefEmitPermissionSet [permissions.Length + 1];
				permissions.CopyTo (new_array, 0);
				permissions = new_array;
			}
			else
				permissions = new RefEmitPermissionSet [1];

			permissions [permissions.Length - 1] = new RefEmitPermissionSet (action, pset.ToXml ().ToString ());
			attrs |= MethodAttributes.HasSecurity;
#endif
		}