Inheritance: System.Security.CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission
        /// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
        /// <param name="target">A permission to test for the subset relationship. This permission must be the same type as the current permission. </param>
        /// <returns>
        ///     <see langword="true" /> if the current permission is a subset of the specified permission; otherwise, <see langword="false" />.</returns>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception>
        // Token: 0x0600265E RID: 9822 RVA: 0x0008ACE8 File Offset: 0x00088EE8
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.m_windowFlag == UIPermissionWindow.NoWindows && this.m_clipboardFlag == UIPermissionClipboard.NoClipboard);
            }
            bool result;

            try
            {
                UIPermission uipermission = (UIPermission)target;
                if (uipermission.IsUnrestricted())
                {
                    result = true;
                }
                else if (this.IsUnrestricted())
                {
                    result = false;
                }
                else
                {
                    result = (this.m_windowFlag <= uipermission.m_windowFlag && this.m_clipboardFlag <= uipermission.m_clipboardFlag);
                }
            }
            catch (InvalidCastException)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            return(result);
        }
		public void UIPermission_Clipboard_All ()
		{
			UIPermission uip = new UIPermission (UIPermissionClipboard.AllClipboard);
			Assert.AreEqual (UIPermissionClipboard.AllClipboard, uip.Clipboard, "Clipboard");
			Assert.AreEqual (UIPermissionWindow.NoWindows, uip.Window, "Window");
			Assert.IsFalse (uip.IsUnrestricted (), "IsUnrestricted");
		}
Beispiel #3
0
        public override bool IsSubsetOf(IPermission target)
        {
            bool flag;

            if (target == null)
            {
                return((this.m_windowFlag == UIPermissionWindow.NoWindows) && (this.m_clipboardFlag == UIPermissionClipboard.NoClipboard));
            }
            try
            {
                UIPermission permission = (UIPermission)target;
                if (permission.IsUnrestricted())
                {
                    return(true);
                }
                if (this.IsUnrestricted())
                {
                    return(false);
                }
                flag = (this.m_windowFlag <= permission.m_windowFlag) && (this.m_clipboardFlag <= permission.m_clipboardFlag);
            }
            catch (InvalidCastException)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            return(flag);
        }
Beispiel #4
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }

            UIPermission          operand             = (UIPermission)target;
            UIPermissionWindow    isectWindowFlags    = m_windowFlag < operand.m_windowFlag ? m_windowFlag : operand.m_windowFlag;
            UIPermissionClipboard isectClipboardFlags = m_clipboardFlag < operand.m_clipboardFlag ? m_clipboardFlag : operand.m_clipboardFlag;

            if (isectWindowFlags == UIPermissionWindow.NoWindows && isectClipboardFlags == UIPermissionClipboard.NoClipboard)
            {
                return(null);
            }
            else
            {
                return(new UIPermission(isectWindowFlags, isectClipboardFlags));
            }
        }
Beispiel #5
0
 /// <summary>确定当前权限是否为指定权限的子集。</summary>
 /// <returns>如果当前权限是指定权限的子集,则为 true;否则为 false。</returns>
 /// <param name="target">要测试子集关系的权限。此权限必须与当前权限属于同一类型。</param>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception>
 public override bool IsSubsetOf(IPermission target)
 {
     if (target == null)
     {
         if (this.m_windowFlag == UIPermissionWindow.NoWindows)
         {
             return(this.m_clipboardFlag == UIPermissionClipboard.NoClipboard);
         }
         return(false);
     }
     try
     {
         UIPermission uiPermission = (UIPermission)target;
         if (uiPermission.IsUnrestricted())
         {
             return(true);
         }
         if (this.IsUnrestricted())
         {
             return(false);
         }
         return(this.m_windowFlag <= uiPermission.m_windowFlag && this.m_clipboardFlag <= uiPermission.m_clipboardFlag);
     }
     catch (InvalidCastException ex)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
     }
 }
Beispiel #6
0
 /// <summary>用指定的窗口和剪贴板权限初始化 <see cref="T:System.Security.Permissions.UIPermission" /> 类的新实例。</summary>
 /// <param name="windowFlag">枚举值之一。</param>
 /// <param name="clipboardFlag">枚举值之一。</param>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="windowFlag" /> 参数不是有效的 <see cref="T:System.Security.Permissions.UIPermissionWindow" /> 值。- 或 -<paramref name="clipboardFlag" /> 参数不是有效的 <see cref="T:System.Security.Permissions.UIPermissionClipboard" /> 值。</exception>
 public UIPermission(UIPermissionWindow windowFlag, UIPermissionClipboard clipboardFlag)
 {
     UIPermission.VerifyWindowFlag(windowFlag);
     UIPermission.VerifyClipboardFlag(clipboardFlag);
     this.m_windowFlag    = windowFlag;
     this.m_clipboardFlag = clipboardFlag;
 }
 protected override IStackWalk CreateStackWalk()
 {
     UIPermission permission = new UIPermission(PermissionState.Unrestricted);
     permission.Clipboard = attribute.Clipboard;
     permission.Window = attribute.Window;
     return permission;
 }
		public void SetClipboardSettings() {
			try {
				var permission = new UIPermission(UIPermissionClipboard.AllClipboard);
				if (Clipboard.ContainsData("UPDATEDATAv3")) {
					var rawClipboarData = (string) Clipboard.GetData("UPDATEDATAv3");
					var clipboardData = new Dictionary<string, string>();
					foreach (string dataItem in rawClipboarData.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)) {
						clipboardData.Add(
							dataItem.Split(new[] {'#'})[0],
							dataItem.Split(new[] {'#'})[1]
							);
					}
					//UpdateURL = clipboardData["updateUrl"];
					ProjektID = clipboardData["projectId"];
					PublicKey = clipboardData["publicKey"];
				}
				else
					MessageBox.Show("Es konnten keine Updateinformationen in der Zwischenablage gefunden werden.", "updateSystem.NET",
					                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				RefreshDesigner();
			}
			catch (Exception ex) {
				MessageBox.Show(
					string.Format("Die Updateeinstellungen konnten aufgrund eines Fehlers nicht übernommen werden:\r\n{0}", ex.ToString()),
					"updateSystem.Net", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
Beispiel #9
0
        //------------------------------------------------------
        //
        // IPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------

        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                // Only safe subset if this is empty
                return(m_windowFlag == UIPermissionWindow.NoWindows && m_clipboardFlag == UIPermissionClipboard.NoClipboard);
            }

            try
            {
                UIPermission operand = (UIPermission)target;
                if (operand.IsUnrestricted())
                {
                    return(true);
                }
                else if (this.IsUnrestricted())
                {
                    return(false);
                }
                else
                {
                    return(this.m_windowFlag <= operand.m_windowFlag && this.m_clipboardFlag <= operand.m_clipboardFlag);
                }
            }
            catch (InvalidCastException)
            {
                throw new
                      ArgumentException(
                          Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
                          );
            }
        }
Beispiel #10
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
                          );
            }

            UIPermission          operand             = (UIPermission)target;
            UIPermissionWindow    isectWindowFlags    = m_windowFlag > operand.m_windowFlag ? m_windowFlag : operand.m_windowFlag;
            UIPermissionClipboard isectClipboardFlags = m_clipboardFlag > operand.m_clipboardFlag ? m_clipboardFlag : operand.m_clipboardFlag;

            if (isectWindowFlags == UIPermissionWindow.NoWindows && isectClipboardFlags == UIPermissionClipboard.NoClipboard)
            {
                return(null);
            }
            else
            {
                return(new UIPermission(isectWindowFlags, isectClipboardFlags));
            }
        }
Beispiel #11
0
		// Methods
		public override IPermission CreatePermission ()
		{
			UIPermission perm = null;
			if (this.Unrestricted)
				perm = new UIPermission (PermissionState.Unrestricted);
			else
				perm = new UIPermission (window, clipboard);
			return perm;
		}
        /// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
        /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
        /// <param name="target">A permission to test for the subset relationship. This permission must be the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override bool IsSubsetOf(IPermission target)
        {
            UIPermission uipermission = this.Cast(target);

            if (uipermission == null)
            {
                return(this.IsEmpty(this._window, this._clipboard));
            }
            return(uipermission.IsUnrestricted() || (this._window <= uipermission._window && this._clipboard <= uipermission._clipboard));
        }
Beispiel #13
0
        /// <summary>Creates and returns a new <see cref="T:System.Security.Permissions.UIPermission" />.</summary>
        /// <returns>A <see cref="T:System.Security.Permissions.UIPermission" /> that corresponds to this attribute.</returns>
        public override IPermission CreatePermission()
        {
            UIPermission result;

            if (base.Unrestricted)
            {
                result = new UIPermission(PermissionState.Unrestricted);
            }
            else
            {
                result = new UIPermission(this.window, this.clipboard);
            }
            return(result);
        }
        // Methods
        public override IPermission CreatePermission()
        {
            UIPermission perm = null;

            if (this.Unrestricted)
            {
                perm = new UIPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new UIPermission(window, clipboard);
            }
            return(perm);
        }
        private UIPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            UIPermission uipermission = target as UIPermission;

            if (uipermission == null)
            {
                CodeAccessPermission.ThrowInvalidPermission(target, typeof(UIPermission));
            }
            return(uipermission);
        }
		public void PermissionStateUnrestricted ()
		{
			UIPermission uip = new UIPermission (PermissionState.Unrestricted);
			Assert.AreEqual (UIPermissionClipboard.AllClipboard, uip.Clipboard, "Clipboard");
			Assert.AreEqual (UIPermissionWindow.AllWindows, uip.Window, "Window");
			Assert.IsTrue (uip.IsUnrestricted (), "IsUnrestricted");

			SecurityElement se = uip.ToXml ();
			Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted");

			UIPermission copy = (UIPermission)uip.Copy ();
			Assert.AreEqual (UIPermissionClipboard.AllClipboard, uip.Clipboard, "Copy-Clipboard");
			Assert.AreEqual (UIPermissionWindow.AllWindows, uip.Window, "Copy-Window");
			Assert.IsTrue (uip.IsUnrestricted (), "Copy-IsUnrestricted");
		}
		public void PermissionStateNone ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			Assert.AreEqual (UIPermissionClipboard.NoClipboard, uip.Clipboard, "Clipboard");
			Assert.AreEqual (UIPermissionWindow.NoWindows, uip.Window, "Window");
			Assert.IsFalse (uip.IsUnrestricted (), "IsUnrestricted");

			SecurityElement se = uip.ToXml ();
			Assert.IsNull (se.Attribute ("Unrestricted"), "Xml-Unrestricted");

			UIPermission copy = (UIPermission)uip.Copy ();
			Assert.AreEqual (UIPermissionClipboard.NoClipboard, uip.Clipboard, "Copy-Clipboard");
			Assert.AreEqual (UIPermissionWindow.NoWindows, uip.Window, "Copy-Window");
			Assert.IsFalse (uip.IsUnrestricted (), "Copy-IsUnrestricted");
		}
Beispiel #18
0
        public override bool IsSubsetOf(IPermission target)
        {
            UIPermission uip = Cast(target);

            if (uip == null)
            {
                return(IsEmpty(_window, _clipboard));
            }
            if (uip.IsUnrestricted())
            {
                return(true);
            }

            // there are not [Flags] so we can't use boolean operators
            return((_window <= uip._window) && (_clipboard <= uip._clipboard));
        }
Beispiel #19
0
        private UIPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            UIPermission uip = (target as UIPermission);

            if (uip == null)
            {
                ThrowInvalidPermission(target, typeof(UIPermission));
            }

            return(uip);
        }
        /// <summary>Creates a permission that is the union of the permission and the specified permission.</summary>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <param name="target">A permission to combine with the current permission. It must be the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Union(IPermission target)
        {
            UIPermission uipermission = this.Cast(target);

            if (uipermission == null)
            {
                return(this.Copy());
            }
            UIPermissionWindow    uipermissionWindow    = (this._window <= uipermission._window) ? uipermission._window : this._window;
            UIPermissionClipboard uipermissionClipboard = (this._clipboard <= uipermission._clipboard) ? uipermission._clipboard : this._clipboard;

            if (this.IsEmpty(uipermissionWindow, uipermissionClipboard))
            {
                return(null);
            }
            return(new UIPermission(uipermissionWindow, uipermissionClipboard));
        }
Beispiel #21
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            if (!base.VerifyType(target))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            UIPermission          permission    = (UIPermission)target;
            UIPermissionWindow    windowFlag    = (this.m_windowFlag < permission.m_windowFlag) ? this.m_windowFlag : permission.m_windowFlag;
            UIPermissionClipboard clipboardFlag = (this.m_clipboardFlag < permission.m_clipboardFlag) ? this.m_clipboardFlag : permission.m_clipboardFlag;

            if ((windowFlag == UIPermissionWindow.NoWindows) && (clipboardFlag == UIPermissionClipboard.NoClipboard))
            {
                return(null);
            }
            return(new UIPermission(windowFlag, clipboardFlag));
        }
Beispiel #22
0
        /// <summary>创建一个权限,该权限是当前权限和指定权限的并集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns>
        /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            if (!this.VerifyType(target))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            UIPermission          uiPermission  = (UIPermission)target;
            UIPermissionWindow    windowFlag    = this.m_windowFlag > uiPermission.m_windowFlag ? this.m_windowFlag : uiPermission.m_windowFlag;
            UIPermissionClipboard clipboardFlag = this.m_clipboardFlag > uiPermission.m_clipboardFlag ? this.m_clipboardFlag : uiPermission.m_clipboardFlag;

            if (windowFlag == UIPermissionWindow.NoWindows && clipboardFlag == UIPermissionClipboard.NoClipboard)
            {
                return((IPermission)null);
            }
            return((IPermission) new UIPermission(windowFlag, clipboardFlag));
        }
Beispiel #23
0
        public override IPermission Union(IPermission target)
        {
            UIPermission uip = Cast(target);

            if (uip == null)
            {
                return(Copy());
            }

            // there are not [Flags] so we can't use boolean operators
            UIPermissionWindow    w = ((_window > uip._window) ? _window : uip._window);
            UIPermissionClipboard c = ((_clipboard > uip._clipboard) ? _clipboard : uip._clipboard);

            if (IsEmpty(w, c))
            {
                return(null);
            }

            return(new UIPermission(w, c));
        }
        /// <summary>Creates a permission that is the union of the permission and the specified permission.</summary>
        /// <param name="target">A permission to combine with the current permission. It must be the same type as the current permission. </param>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception>
        // Token: 0x06002660 RID: 9824 RVA: 0x0008AE18 File Offset: 0x00089018
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            if (!base.VerifyType(target))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            UIPermission          uipermission          = (UIPermission)target;
            UIPermissionWindow    uipermissionWindow    = (this.m_windowFlag > uipermission.m_windowFlag) ? this.m_windowFlag : uipermission.m_windowFlag;
            UIPermissionClipboard uipermissionClipboard = (this.m_clipboardFlag > uipermission.m_clipboardFlag) ? this.m_clipboardFlag : uipermission.m_clipboardFlag;

            if (uipermissionWindow == UIPermissionWindow.NoWindows && uipermissionClipboard == UIPermissionClipboard.NoClipboard)
            {
                return(null);
            }
            return(new UIPermission(uipermissionWindow, uipermissionClipboard));
        }
		public void FromXml_NoVersion ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			uip.FromXml (w);
		}
		private void Compare (UIPermission uip1, UIPermission uip2, string prefix)
		{
			Assert.AreEqual (uip1.Clipboard, uip2.Clipboard, prefix + ".Clipboard");
			Assert.AreEqual (uip1.Window, uip2.Window, prefix + ".Window");
			Assert.AreEqual (uip1.IsUnrestricted (), uip2.IsUnrestricted (), prefix + ".IsUnrestricted ()");
		}
		/// <summary>
		/// Filters out a message before it is dispatched
		/// </summary>
		/// <param name="m">The message to be dispatched. You cannot modify 
		/// this message</param>
		/// <returns>true to filter the message and prevent it from being 
		/// dispatched; false to allow the message to continue to the next 
		/// filter or control</returns>
		public bool PreFilterMessage(ref Message m)
		{
			// make sure we have a client
			if (this.Client == null)
			{
				return false;
			}
			
			// make sure the message is a key message
			if (m.Msg != (int) WindowMessage.WM_KEYDOWN && m.Msg != (int) WindowMessage.WM_SYSKEYDOWN && 
				m.Msg != (int) WindowMessage.WM_KEYUP && m.Msg != (int) WindowMessage.WM_SYSKEYUP)
			{
				return false;
			}

			// try to get the target control
			UIPermission uiPermission = new UIPermission(UIPermissionWindow.AllWindows);
			uiPermission.Demand();
			Control target = Control.FromChildHandle(m.HWnd);

			return this.Client.ProcessKeyMessage(target, (WindowMessage) m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32());
		}
		public void UIPermission_Windows_SafeTopLevelWindows ()
		{
			UIPermission uip = new UIPermission (UIPermissionWindow.SafeTopLevelWindows);
			Assert.AreEqual (UIPermissionClipboard.NoClipboard, uip.Clipboard, "Clipboard");
			Assert.AreEqual (UIPermissionWindow.SafeTopLevelWindows, uip.Window, "Window");
			Assert.IsFalse (uip.IsUnrestricted (), "IsUnrestricted");
		}
		public void Window_Bad ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			uip.Window = (UIPermissionWindow) 128;
		}
Beispiel #30
0
        internal override void CreateAllStyle() 
        {
            Invariant.Assert(App != null, "RootBrowserWindow must be created in an Application");

            IHostService ihs = (IHostService)App.GetService(typeof(IHostService)); 

            Invariant.Assert(ihs!=null, "IHostService in RootBrowserWindow cannot be null"); 
            Invariant.Assert(ihs.HostWindowHandle != IntPtr.Zero, "IHostService.HostWindowHandle in RootBrowserWindow cannot be null"); 

            //This sets the _ownerHandle correctly and will be used to create the _sourceWindow 
            //with the correct parent
            UIPermission uip = new UIPermission(UIPermissionWindow.AllWindows);
            uip.Assert();//Blessed Assert to set owner handle and to set styles
            try 
            {
                this.OwnerHandle = ihs.HostWindowHandle; 
                this.Win32Style = NativeMethods.WS_CHILD | NativeMethods.WS_CLIPCHILDREN | NativeMethods.WS_CLIPSIBLINGS; 
            }
            finally 
            {
                CodeAccessPermission.RevertAssert();
            }
 
        }
		public void Union_DifferentPermissions ()
		{
			UIPermission a = new UIPermission (PermissionState.None);
			SecurityPermission b = new SecurityPermission (PermissionState.None);
			a.Union (b);
		}
Beispiel #32
0
		public void ResolveWithChildren ()
		{
			PermissionSet pset1 = new PermissionSet (PermissionState.None);
			PermissionSet pset2 = new PermissionSet (PermissionState.None);
			PermissionSet pset3 = new PermissionSet (PermissionState.None);
			PermissionSet pset4 = new PermissionSet (PermissionState.None);
			PermissionSet pset5 = new PermissionSet (PermissionState.None);
			PermissionSet pset6 = new PermissionSet (PermissionState.None);

			IPermission perm1 = new UIPermission (PermissionState.Unrestricted);
			IPermission perm2 = new EnvironmentPermission (PermissionState.Unrestricted);
			IPermission perm3 = new FileDialogPermission (PermissionState.Unrestricted);
			IPermission perm4 = new ReflectionPermission (PermissionState.Unrestricted);
			IPermission perm5 = new RegistryPermission (PermissionState.Unrestricted);
			IPermission perm6 = new FileIOPermission (PermissionState.Unrestricted);
			
			pset1.AddPermission (perm1);
			PolicyStatement policy1 = new PolicyStatement (pset1);
			
			pset2.AddPermission(perm2);
			PolicyStatement policy2 = new PolicyStatement (pset2);
			
			pset3.AddPermission (perm3);
			PolicyStatement policy3 = new PolicyStatement (pset3);
			
			pset4.AddPermission (perm4);
			PolicyStatement policy4 = new PolicyStatement (pset4);
			
			pset5.AddPermission (perm5);
			PolicyStatement policy5 = new PolicyStatement (pset5);
			
			pset6.AddPermission (perm6);
			PolicyStatement policy6 = new PolicyStatement (pset6);

			UnionCodeGroup root = new UnionCodeGroup (new AllMembershipCondition (), policy1);
			
			UnionCodeGroup child1 = new UnionCodeGroup (new ZoneMembershipCondition (SecurityZone.Internet), policy2);
			UnionCodeGroup child2 = new UnionCodeGroup (new AllMembershipCondition (), policy3);
			UnionCodeGroup child3 = new UnionCodeGroup (new AllMembershipCondition (), policy4);
			UnionCodeGroup childofchild1 = new UnionCodeGroup (new AllMembershipCondition (), policy5);
			UnionCodeGroup childofchild3 = new UnionCodeGroup (new AllMembershipCondition (), policy6);
			
			child1.AddChild (childofchild1);
			child3.AddChild (childofchild3);

			root.AddChild (child1);
			root.AddChild (child2);
			root.AddChild (child3);
			
			PolicyStatement result = root.Resolve (new Evidence ());

			PermissionSet correctset = new PermissionSet (PermissionState.None);
			correctset.AddPermission (perm1);
			correctset.AddPermission (perm3);
			correctset.AddPermission (perm4);
			correctset.AddPermission (perm6);

			Assert.AreEqual (correctset.Count, result.PermissionSet.Count, "PermissionSet.Count");
			foreach (IPermission p in correctset) {
				IPermission r = result.PermissionSet.GetPermission (p.GetType ());
				Assert.IsNotNull (r, "PermissionSet.GetPermission");
			}
		}		
		public void FromXml_WrongTagCase ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();
			se.Tag = "IPERMISSION"; // instead of IPermission
			uip.FromXml (se);
		}
		public void FromXml_Null ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			uip.FromXml (null);
		}
		public void FromXml_WrongClass ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
			w.AddAttribute ("version", se.Attribute ("version"));
			uip.FromXml (w);
			// doesn't care of the class name at that stage
			// anyway the class has already be created so...
		}
		public void FromXml_NoClass ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", se.Attribute ("version"));
			uip.FromXml (w);
			// doesn't even care of the class attribute presence
		}
		// Loads any steps 
		protected override void OnLoad(System.EventArgs e)
		{
			base.OnLoad(e);

			if( !DesignMode )
			{
				OnLoadSteps(EventArgs.Empty);
			
				if( FirstStepName == "" )
					throw new InvalidOperationException("FirstStepName must be be a non-empty string.");

				ResetSteps();

				SetCurrentStep(FirstStepName, StepDirection.InitialStep);
			}
			else
			{
				UpdateLayout(currentLayout);
			}

			UIPermission uiP = new UIPermission(UIPermissionWindow.AllWindows);
			uiP.Demand();
		}
Beispiel #38
0
 /// <summary>在具有使用窗口的权限,但没有对剪贴板的访问权限的情况下,初始化 <see cref="T:System.Security.Permissions.UIPermission" /> 类的新实例。</summary>
 /// <param name="windowFlag">枚举值之一。</param>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="windowFlag" /> 参数不是有效的 <see cref="T:System.Security.Permissions.UIPermissionWindow" /> 值。</exception>
 public UIPermission(UIPermissionWindow windowFlag)
 {
     UIPermission.VerifyWindowFlag(windowFlag);
     this.m_windowFlag = windowFlag;
 }
		public void Union ()
		{
			UIPermission none = new UIPermission (PermissionState.None);
			UIPermission union = (UIPermission)none.Union (null);
			Compare (none, union, "none U null");
			Assert.IsFalse (Object.ReferenceEquals (none, union), "!ReferenceEquals1");
			Assert.IsTrue (none.IsSubsetOf (union), "none.IsSubsetOf (union)");

			union = (UIPermission)none.Union (new UIPermission (PermissionState.None));
			Assert.IsNull (union, "none U none");
			Assert.IsTrue (none.IsSubsetOf (null), "none.IsSubsetOf (null)");

			UIPermission unrestricted = new UIPermission (PermissionState.Unrestricted);
			union = (UIPermission)none.Union (unrestricted);
			Compare (unrestricted, union, "none U unrestricted");
			Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-1");
			Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "!ReferenceEquals2");
			Assert.IsTrue (none.IsSubsetOf (union), "none.IsSubsetOf (union)");
			Assert.IsTrue (unrestricted.IsSubsetOf (union), "unrestricted.IsSubsetOf (union)");

			union = (UIPermission)unrestricted.Union (unrestricted);
			Compare (unrestricted, union, "unrestricted U unrestricted");
			Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-2");
			Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "!ReferenceEquals3");
			Assert.IsTrue (unrestricted.IsSubsetOf (union), "unrestricted.IsSubsetOf (union)");

			UIPermission clip_all = new UIPermission (UIPermissionClipboard.AllClipboard);
			UIPermission win_all = new UIPermission (UIPermissionWindow.AllWindows);
			union = (UIPermission)clip_all.Union (win_all);
			Compare (unrestricted, union, "clip_all U win_all");
			Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-3");
			Assert.IsTrue (clip_all.IsSubsetOf (union), "clip_all.IsSubsetOf (union)");
			Assert.IsTrue (win_all.IsSubsetOf (union), "win_all.IsSubsetOf (union)");
		}
Beispiel #40
0
 /// <summary>在具有使用剪贴板的权限,但没有对窗口的访问权限的情况下,初始化 <see cref="T:System.Security.Permissions.UIPermission" /> 类的新实例。</summary>
 /// <param name="clipboardFlag">枚举值之一。</param>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="clipboardFlag" /> 参数不是有效的 <see cref="T:System.Security.Permissions.UIPermissionClipboard" /> 值。</exception>
 public UIPermission(UIPermissionClipboard clipboardFlag)
 {
     UIPermission.VerifyClipboardFlag(clipboardFlag);
     this.m_clipboardFlag = clipboardFlag;
 }
		public void IsSubsetOf_DifferentPermissions ()
		{
			UIPermission a = new UIPermission (PermissionState.None);
			SecurityPermission b = new SecurityPermission (PermissionState.None);
			a.IsSubsetOf (b);
		}
		public void Unrestricted () 
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();
			// attribute value is not case-sensitive
			se.AddAttribute ("Unrestricted", "TRUE");
			uip.FromXml (se);
			Assert.IsTrue (uip.IsUnrestricted (), "IsUnrestricted-TRUE");

			uip = new UIPermission (PermissionState.None);
			// attribute name is not case-sensitive either!!!
			se.AddAttribute ("UNRESTRICTED", "TRUE");
			uip.FromXml (se);
			Assert.IsTrue (uip.IsUnrestricted (), "IsUnrestricted-UPPER");
		}
		public void IsSubsetOf ()
		{
			UIPermission unrestricted = new UIPermission (PermissionState.Unrestricted);
			UIPermission empty = new UIPermission (PermissionState.None);

			Assert.IsFalse (unrestricted.IsSubsetOf (empty), "unrestricted.IsSubsetOf (empty)");
			Assert.IsTrue (empty.IsSubsetOf (unrestricted), "empty.IsSubsetOf (unrestricted)");
			Assert.IsTrue (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)");
			Assert.IsFalse (unrestricted.IsSubsetOf (null), "unrestricted.IsSubsetOf (null)");
		}
Beispiel #44
0
        [System.Security.SecurityCritical]  // auto-generated
        private static void ValidateCspFlags (CspProviderFlags flags) {
            // check that the flags are consistent.
            if ((flags & CspProviderFlags.UseExistingKey) != 0) {
                CspProviderFlags keyFlags = (CspProviderFlags.UseNonExportableKey | CspProviderFlags.UseArchivableKey | CspProviderFlags.UseUserProtectedKey);
                if ((flags & keyFlags) != CspProviderFlags.NoFlags)
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"));
            }

            // make sure we are allowed to display the key protection UI if a user protected key is requested.
            if ((flags & CspProviderFlags.UseUserProtectedKey) != 0) {
                // UI only allowed in interactive session.
                if (!System.Environment.UserInteractive)
                    throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NotInteractive"));

                // we need to demand UI permission here.
                UIPermission uiPermission = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
                uiPermission.Demand();
            }
        }
        /// <summary>
        /// Filters out a message before it is dispatched
        /// </summary>
        /// <param name="m">The message to be dispatched. You cannot modify 
        /// this message</param>
        /// <returns>true to filter the message and prevent it from being 
        /// dispatched; false to allow the message to continue to the next 
        /// filter or control</returns>
        public bool PreFilterMessage(ref Message m)
        {
            // make sure we have a client
            if (this.Client == null)
            {
                return false;
            }

            // make sure the message is a mouse message
            if ((m.Msg >= (int) WindowMessage.WM_MOUSEMOVE && m.Msg <= (int) WindowMessage.WM_XBUTTONDBLCLK) ||
                (m.Msg >= (int) WindowMessage.WM_NCMOUSEMOVE && m.Msg <= (int) WindowMessage.WM_NCXBUTTONUP))
            {
                // try to get the target control
                UIPermission uiPermission = new UIPermission(UIPermissionWindow.AllWindows);
                uiPermission.Demand();
                Control target = Control.FromChildHandle(m.HWnd);

                return this.Client.ProcessMouseMessage(target, (WindowMessage) m.Msg, m.WParam, m.LParam);
            }

            return false;
        }
		public void Clipboard_Bad ()
		{
			UIPermission uip = new UIPermission (PermissionState.None);
			uip.Clipboard = (UIPermissionClipboard) 128;
		}
		public void Intersect_DifferentPermissions ()
		{
			UIPermission a = new UIPermission (PermissionState.None);
			SecurityPermission b = new SecurityPermission (PermissionState.None);
			a.Intersect (b);
		}
		public void UIPermission_Windows_Bad ()
		{
			UIPermission uip = new UIPermission ((UIPermissionWindow)128);
		}
		public void Intersect ()
		{
			UIPermission clip_all = new UIPermission (UIPermissionClipboard.AllClipboard);
			UIPermission clip_own = new UIPermission (UIPermissionClipboard.OwnClipboard);
			UIPermission intersect = (UIPermission)clip_all.Intersect (clip_own);
			Compare (clip_own, intersect, "clip_all N clip_own");
			Assert.IsFalse (Object.ReferenceEquals (clip_own, intersect), "!ReferenceEquals1");
			Assert.IsTrue (intersect.IsSubsetOf (clip_all), "intersect.IsSubsetOf (clip_all)");
			Assert.IsTrue (intersect.IsSubsetOf (clip_own), "intersect.IsSubsetOf (clip_own)");

			UIPermission win_all = new UIPermission (UIPermissionWindow.AllWindows);
			UIPermission win_safe = new UIPermission (UIPermissionWindow.SafeSubWindows);
			intersect = (UIPermission) win_all.Intersect (win_safe);
			Compare (win_safe, intersect, "win_all N win_safe");
			Assert.IsFalse (Object.ReferenceEquals (win_safe, intersect), "!ReferenceEquals2");
			Assert.IsTrue (intersect.IsSubsetOf (win_all), "intersect.IsSubsetOf (win_all)");
			Assert.IsTrue (intersect.IsSubsetOf (win_safe), "intersect.IsSubsetOf (win_safe)");

			intersect = (UIPermission)win_all.Intersect (clip_all);
			Assert.IsNull (intersect, "win_all N clip_all");

			intersect = (UIPermission)win_all.Intersect (null);
			Assert.IsNull (intersect, "win_all N null");

			intersect = (UIPermission)clip_all.Intersect (null);
			Assert.IsNull (intersect, "clip_all N null");

			UIPermission empty = new UIPermission (PermissionState.None);
			intersect = (UIPermission)clip_all.Intersect (empty);
			Assert.IsNull (intersect, "clip_all N null");

			UIPermission unrestricted = new UIPermission (PermissionState.Unrestricted);
			intersect = (UIPermission)clip_all.Intersect (unrestricted);
			Compare (clip_all, intersect, "clip_all N unrestricted");
			Assert.IsFalse (Object.ReferenceEquals (clip_all, intersect), "!ReferenceEquals4");
			Assert.IsTrue (intersect.IsSubsetOf (clip_all), "intersect.IsSubsetOf (clip_all)");
			Assert.IsTrue (intersect.IsSubsetOf (unrestricted), "intersect.IsSubsetOf (unrestricted)");
		}
Beispiel #50
0
 /// <internalonly/>
 int IBuiltInPermission.GetTokenIndex()
 {
     return(UIPermission.GetTokenIndex());
 }
		public void PermissionStateInvalid ()
		{
			UIPermission uip = new UIPermission ((PermissionState)2);
		}