2004-04-02 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / corlib / System.Security / CodeAccessPermission.cs
index 148c2a231ba2ceed3169653ef30a7657150974e1..ce56ae221659089b29e859714f6017f0a542b941 100755 (executable)
@@ -4,11 +4,15 @@
 // Authors:
 //     Miguel de Icaza (miguel@ximian.com)
 //     Nick Drochak, ndrochak@gol.com
+//     Sebastien Pouliot (spouliot@motus.com)
 //
 // (C) Ximian, Inc. http://www.ximian.com
 // Copyright (C) 2001 Nick Drochak, All Rights Reserved
+// Portions (C) 2004 Motus Technologies Inc. (http://www.motus.com)
 //
 
+using System.Globalization;
+using System.Security.Permissions;
 using System.Text;
 
 namespace System.Security {
@@ -18,16 +22,81 @@ namespace System.Security {
 
                protected CodeAccessPermission () {}
 
-               [MonoTODO()]
-               public void Assert () {}
+               // LAMESPEC: Documented as virtual
+               [MonoTODO("SecurityStackFrame not ready")]
+               public void Assert ()
+               {
+                       // throw a SecurityException if Assertion is denied
+                       new SecurityPermission (SecurityPermissionFlag.Assertion).Demand ();
+//                     SecurityStackFrame.Current.Assert = this;
+               }
 
                public abstract IPermission Copy ();
 
-               [MonoTODO()]
-               public void Demand () {}
+               // LAMESPEC: Documented as virtual
+               [MonoTODO("MS contralize demands, but I think we should branch back into indivual permission classes.")]
+               public void Demand ()
+               {
+                       IBuiltInPermission perm = (this as IBuiltInPermission);
+                       if (perm == null)
+                               return; // not sure about this :(
+
+                       // TODO : Loop the stack
+                       switch (perm.GetTokenIndex ()) {
+                               case 0: // EnvironmentPermission
+                                       // TODO
+                                       break;
+                               case 1: // FileDialogPermission
+                                       // TODO
+                                       break;
+                               case 2: // FileIOPermission
+                                       // TODO
+                                       break;
+                               case 3: // IsolatedStorageFilePermission
+                                       // TODO
+                                       break;
+                               case 4: // ReflectionPermission
+                                       // TODO
+                                       break;
+                               case 5: // RegistryPermission
+                                       // TODO
+                                       break;
+                               case 6: // SecurityPermission
+                                       // TODO
+                                       break;
+                               case 7: // UIPermission
+                                       // TODO
+                                       break;
+                               case 8: // PrincipalPermission
+                                       // TODO
+                                       break;
+                               case 9: // PublisherIdentityPermission
+                                       // TODO
+                                       break;
+                               case 10: // SiteIdentityPermission
+                                       // TODO
+                                       break;
+                               case 11: // StrongNameIdentityPermission
+                                       // TODO
+                                       break;
+                               case 12: // UrlIdentityPermission
+                                       // TODO
+                                       break;
+                               case 13: // ZoneIdentityPermission
+                                       // TODO
+                                       break;
+                               default:
+                                       string message = String.Format (Locale.GetText ("Unknown IBuiltInPermission #{0}"), perm.GetTokenIndex ());
+                                       throw new SecurityException (message);
+                       }
+               }
 
-               [MonoTODO()]
-               public void Deny () {}
+               // LAMESPEC: Documented as virtual
+               [MonoTODO("SecurityStackFrame not ready")]
+               public void Deny ()
+               {
+//                     SecurityStackFrame.Current.Deny = this;
+               }
 
                public abstract void FromXml (SecurityElement elem);
 
@@ -35,38 +104,51 @@ namespace System.Security {
 
                public abstract bool IsSubsetOf (IPermission target);
 
-               public override string ToString()
+               public override string ToString ()
                {
                        SecurityElement elem = ToXml ();
-                       return elem == null ? null : elem.ToString ();
+                       return elem.ToString ();
                }
 
                public abstract SecurityElement ToXml ();
 
-               [MonoTODO("Incomplete")]
                public virtual IPermission Union (IPermission other)
                {
-                       if (!(other is System.Security.CodeAccessPermission))
-                               throw new System.ArgumentException(); // other is not of type System.Security.CodeAccessPermission.
                        if (null != other)
-                               throw new System.NotSupportedException(); // other is not null.
+                               throw new System.NotSupportedException (); // other is not null.
                        return null;
                }
 
-               [MonoTODO()]
-               public void PermitOnly () {}
+               // LAMESPEC: Documented as virtual
+               [MonoTODO("SecurityStackFrame not ready")]
+               public void PermitOnly ()
+               {
+//                     SecurityStackFrame.Current.PermitOnly = this;
+               }
 
-               [MonoTODO()]
-               public static void RevertAll () {}
+               [MonoTODO("SecurityStackFrame not ready")]
+               public static void RevertAll ()
+               {
+//                     SecurityStackFrame.Current.RevertAll ();
+               }
 
-               [MonoTODO()]
-               public static void RevertAssert () {}
+               [MonoTODO("SecurityStackFrame not ready")]
+               public static void RevertAssert () 
+               {
+//                     SecurityStackFrame.Current.RevertAssert ();
+               }
 
-               [MonoTODO()]
-               public static void RevertDeny () {}
+               [MonoTODO("SecurityStackFrame not ready")]
+               public static void RevertDeny ()
+               {
+//                     SecurityStackFrame.Current.RevertDeny ();
+               }
 
-               [MonoTODO()]
-               public static void RevertPermitOnly () {}
+               [MonoTODO("SecurityStackFrame not ready")]
+               public static void RevertPermitOnly () 
+               {
+//                     SecurityStackFrame.Current.RevertPermitOnly ();
+               }
 
                // snippet moved from FileIOPermission (nickd) to be reused in all derived classes
                internal SecurityElement Element (object o, int version)