2 // System.Security.Permissions.ZoneIdentityPermission
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2002 Ximian, Inc (http://www.ximian.com)
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Globalization;
33 using System.Security;
35 namespace System.Security.Permissions {
38 public sealed class ZoneIdentityPermission : CodeAccessPermission, IBuiltInPermission {
40 private SecurityZone zone;
42 public ZoneIdentityPermission (PermissionState state)
45 case PermissionState.None:
46 zone = SecurityZone.NoZone;
48 case PermissionState.Unrestricted:
49 throw new ArgumentException (Locale.GetText (
50 "unrestricted not allowed"));
52 throw new ArgumentException (Locale.GetText (
57 public ZoneIdentityPermission (SecurityZone zone)
59 // also needs the validations
63 public override IPermission Copy ()
65 return new ZoneIdentityPermission (zone);
68 public override bool IsSubsetOf (IPermission target)
71 return zone == SecurityZone.NoZone;
73 ZoneIdentityPermission zip = (target as ZoneIdentityPermission);
75 throw new ArgumentException (Locale.GetText (
76 "Invalid permission"));
79 return (zone == zip.zone);
82 public override IPermission Union (IPermission target)
85 return (zone == SecurityZone.NoZone) ? null : Copy ();
87 ZoneIdentityPermission zip = (target as ZoneIdentityPermission);
89 throw new ArgumentException (Locale.GetText (
90 "Invalid permission"));
93 if (zone == zip.zone || zip.zone == SecurityZone.NoZone)
96 if (zone == SecurityZone.NoZone)
99 throw new ArgumentException (Locale.GetText (
100 "Union impossible"));
106 public override IPermission Intersect (IPermission target)
108 if (target == null || zone == SecurityZone.NoZone)
111 ZoneIdentityPermission zip = (target as ZoneIdentityPermission);
113 throw new ArgumentException (Locale.GetText (
114 "Invalid permission"));
117 if (zone == zip.zone)
123 public override void FromXml (SecurityElement esd)
126 throw new ArgumentException ("esd");
128 if (esd.Attribute ("version") != "1") {
129 throw new ArgumentException (Locale.GetText (
130 "version attributte is wrong"));
133 string zoneName = esd.Attribute ("Zone");
134 zone = (SecurityZone) Enum.Parse (typeof (SecurityZone), zoneName);
137 public override SecurityElement ToXml ()
139 SecurityElement se = new SecurityElement ("IPermission");
141 se.AddAttribute ("class", t.FullName + ", " + t.Module.Assembly.FullName);
142 se.AddAttribute ("version", "1");
143 se.AddAttribute ("Zone", zone.ToString ());
148 public SecurityZone SecurityZone {
151 if (!Enum.IsDefined (typeof (SecurityZone), value)) {
152 throw new ArgumentException (Locale.GetText (
159 // IBuiltInPermission
160 int IBuiltInPermission.GetTokenIndex ()