diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2004-08-18 18:54:31 +0400 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2004-08-18 18:54:31 +0400 |
commit | 97426dead1d7f63dac30d15ff203413ecb3cb892 (patch) | |
tree | aebc429041a4749dcbaff73c118b07deaae46b3e /mcs/class/corlib/System.Security.Permissions | |
parent | bce97c7b41b71d7393ed9f111b3a0368b6cc6057 (diff) |
2004-08-18 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageContainment.cs: Added new enums values for NET_2_0.
* IsolatedStorageFilePermissionAttribute.cs: Removed unrequired using
clause.
* IsolatedStorageFilePermission.cs: Updated to use the common template.
Completed TODOs and now pass all unit tests.
* IsolatedStoragePermission.cs: Updated to use the common template.
Completed TODOs and now pass all unit tests.
svn path=/trunk/mcs/; revision=32490
Diffstat (limited to 'mcs/class/corlib/System.Security.Permissions')
5 files changed, 162 insertions, 89 deletions
diff --git a/mcs/class/corlib/System.Security.Permissions/ChangeLog b/mcs/class/corlib/System.Security.Permissions/ChangeLog index 353dfacd204..be0f63655df 100644 --- a/mcs/class/corlib/System.Security.Permissions/ChangeLog +++ b/mcs/class/corlib/System.Security.Permissions/ChangeLog @@ -1,5 +1,12 @@ 2004-08-18 Sebastien Pouliot <sebastien@ximian.com> + * IsolatedStorageContainment.cs: Added new enums values for NET_2_0. + * IsolatedStorageFilePermissionAttribute.cs: Removed unrequired using + clause. + * IsolatedStorageFilePermission.cs: Updated to use the common template. + Completed TODOs and now pass all unit tests. + * IsolatedStoragePermission.cs: Updated to use the common template. + Completed TODOs and now pass all unit tests. * GacIdentityPermission.cs: Update to use the common template. Now pass all unit tests. * GacIdentityPermissionAttribute.cs: Added FIXME comment. diff --git a/mcs/class/corlib/System.Security.Permissions/IsolatedStorageContainment.cs b/mcs/class/corlib/System.Security.Permissions/IsolatedStorageContainment.cs index de2e91f0d4e..e31bbe6dfc4 100755 --- a/mcs/class/corlib/System.Security.Permissions/IsolatedStorageContainment.cs +++ b/mcs/class/corlib/System.Security.Permissions/IsolatedStorageContainment.cs @@ -1,3 +1,4 @@ +// // IsolatedStorageContainment.cs // // This code was automatically generated from @@ -8,8 +9,6 @@ // URL: http://devresource.hp.com/devresource/Docs/TechPapers/CSharp/all.xml // // (C) 2001 Ximian, Inc. http://www.ximian.com - -// // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -32,7 +31,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // - namespace System.Security.Permissions { [Serializable] @@ -45,6 +43,12 @@ namespace System.Security.Permissions { AssemblyIsolationByRoamingUser = 0x60, AdministerIsolatedStorageByUser = 0x70, UnrestrictedIsolatedStorage = 0xF0, - }; - -} // System.Security.Permissions +#if NET_2_0 + ApplicationIsolationByUser = 0x25, + DomainIsolationByMachine = 0x30, + AssemblyIsolationByMachine = 0x40, + ApplicationIsolationByMachine = 0x45, + ApplicationIsolationByRoamingUser = 0x65, +#endif + } +} diff --git a/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermission.cs b/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermission.cs index e7e59db6080..39bf4dca0e2 100644 --- a/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermission.cs +++ b/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermission.cs @@ -2,12 +2,9 @@ // System.Security.Permissions.IsolatedStorageFilePermission.cs // // Author -// Sebastien Pouliot <spouliot@motus.com> +// Sebastien Pouliot <sebastien@ximian.com> // // Copyright (C) 2003 Motus Technologies. http://www.motus.com -// - -// // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -30,51 +27,122 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; - namespace System.Security.Permissions { [Serializable] public sealed class IsolatedStorageFilePermission : IsolatedStoragePermission, IBuiltInPermission { + private const int version = 1; + // Constructors - public IsolatedStorageFilePermission (PermissionState state) : base (state) {} + [MonoTODO ("usage/quota calculated from evidences/policy")] + public IsolatedStorageFilePermission (PermissionState state) : base (state) + { + if (!IsUnrestricted ()) { + // TODO + } + } // Properties // Methods - [MonoTODO] public override IPermission Copy () { IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None); - // TODO add stuff into p + p.m_userQuota = m_userQuota; + p.m_machineQuota = m_machineQuota; + p.m_expirationDays = m_expirationDays; + p.m_permanentData = m_permanentData; + p.m_allowed = m_allowed; return p; } - [MonoTODO] public override IPermission Intersect (IPermission target) { - return null; + IsolatedStorageFilePermission isfp = Cast (target); + if (isfp == null) + return null; + if (IsEmpty () && isfp.IsEmpty ()) + return null; + + IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None); + p.m_userQuota = (m_userQuota < isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota; + p.m_machineQuota = (m_machineQuota < isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota; + p.m_expirationDays = (m_expirationDays < isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays; + p.m_permanentData = (m_permanentData && isfp.m_permanentData); + // UsageAllowed == Unrestricted is a special case handled by the property + p.UsageAllowed = (m_allowed < isfp.m_allowed) ? m_allowed : isfp.m_allowed; + return p; } - [MonoTODO] public override bool IsSubsetOf (IPermission target) { - return false; + IsolatedStorageFilePermission isfp = Cast (target); + if (isfp == null) + return IsEmpty (); + if (isfp.IsUnrestricted ()) + return true; + + if (m_userQuota > isfp.m_userQuota) + return false; + if (m_machineQuota > isfp.m_machineQuota) + return false; + if (m_expirationDays > isfp.m_expirationDays) + return false; + if (m_permanentData != isfp.m_permanentData) + return false; + if (m_allowed > isfp.m_allowed) + return false; + return true; + } + + public override IPermission Union (IPermission target) + { + IsolatedStorageFilePermission isfp = Cast (target); + if (isfp == null) + return Copy (); + + IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None); + p.m_userQuota = (m_userQuota > isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota; + p.m_machineQuota = (m_machineQuota > isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota; + p.m_expirationDays = (m_expirationDays > isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays; + p.m_permanentData = (m_permanentData || isfp.m_permanentData); + // UsageAllowed == Unrestricted is a special case handled by the property + p.UsageAllowed = (m_allowed > isfp.m_allowed) ? m_allowed : isfp.m_allowed; + return p; } +#if NET_2_0 [MonoTODO] - public override IPermission Union (IPermission target) + public override SecurityElement ToXml () { - return null; + SecurityElement se = base.ToXml (); + // TODO - something must have been added ??? + return se; } +#endif // IBuiltInPermission int IBuiltInPermission.GetTokenIndex () { - return 3; + return (int) BuiltInToken.IsolatedStorageFile; + } + + // helpers + + private IsolatedStorageFilePermission Cast (IPermission target) + { + if (target == null) + return null; + + IsolatedStorageFilePermission isfp = (target as IsolatedStorageFilePermission); + if (isfp == null) { + ThrowInvalidPermission (target, typeof (IsolatedStorageFilePermission)); + } + + return isfp; } } -}
\ No newline at end of file +} diff --git a/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermissionAttribute.cs b/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermissionAttribute.cs index a84ea4af2f6..f1a6c25a371 100644 --- a/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermissionAttribute.cs +++ b/mcs/class/corlib/System.Security.Permissions/IsolatedStorageFilePermissionAttribute.cs @@ -3,13 +3,10 @@ // // Authors // Duncan Mak <duncan@ximian.com> -// Sebastien Pouliot (spouliot@motus.com) +// Sebastien Pouliot <sebastien@ximian.com> // // (C) 2002 Ximian, Inc. http://www.ximian.com // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com) -// - -// // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -32,8 +29,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; - namespace System.Security.Permissions { [AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | diff --git a/mcs/class/corlib/System.Security.Permissions/IsolatedStoragePermission.cs b/mcs/class/corlib/System.Security.Permissions/IsolatedStoragePermission.cs index 87c676873da..351dd12e06e 100644 --- a/mcs/class/corlib/System.Security.Permissions/IsolatedStoragePermission.cs +++ b/mcs/class/corlib/System.Security.Permissions/IsolatedStoragePermission.cs @@ -1,12 +1,11 @@ // // System.Security.Permissions.IsolatedStoragePermission.cs // -// Piers Haken <piersh@friskit.com> +// Authors: +// Piers Haken <piersh@friskit.com> +// Sebastien Pouliot <sebastien@ximian.com> // // (C) 2002 Ximian, Inc. http://www.ximian.com -// - -// // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining @@ -29,15 +28,15 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System; using System.Globalization; -using System.Security.Permissions; -namespace System.Security.Permissions -{ +namespace System.Security.Permissions { + [Serializable] - public abstract class IsolatedStoragePermission : CodeAccessPermission, IUnrestrictedPermission - { + public abstract class IsolatedStoragePermission : CodeAccessPermission, IUnrestrictedPermission { + + private const int version = 1; + internal long m_userQuota; internal long m_machineQuota; internal long m_expirationDays; @@ -46,39 +45,31 @@ namespace System.Security.Permissions public IsolatedStoragePermission (PermissionState state) { - if (state == PermissionState.None) - { - m_userQuota = 0; - m_machineQuota = 0; - m_expirationDays = 0; - m_permanentData = false; - m_allowed = IsolatedStorageContainment.None; - } - else if (state == PermissionState.Unrestricted) - { - m_userQuota = Int64.MaxValue; - m_machineQuota = Int64.MaxValue; - m_expirationDays = Int64.MaxValue ; - m_permanentData = true; - m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage; - } - else - { - throw new ArgumentException("Invalid Permission state"); + if (CheckPermissionState (state, true) == PermissionState.Unrestricted) { + UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage; } } - public long UserQuota - { - set { m_userQuota = value; } + public long UserQuota { get { return m_userQuota; } + set { m_userQuota = value; } } - - public IsolatedStorageContainment UsageAllowed - { - set { m_allowed = value; } + public IsolatedStorageContainment UsageAllowed { get { return m_allowed; } + set { + if (!Enum.IsDefined (typeof (IsolatedStorageContainment), value)) { + string msg = String.Format (Locale.GetText ("Invalid enum {0}"), value); + throw new ArgumentException (msg, "IsolatedStorageContainment"); + } + m_allowed = value; + if (m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage) { + m_userQuota = Int64.MaxValue; + m_machineQuota = Int64.MaxValue; + m_expirationDays = Int64.MaxValue ; + m_permanentData = true; + } + } } @@ -89,39 +80,47 @@ namespace System.Security.Permissions public override SecurityElement ToXml () { - SecurityElement e = new SecurityElement ("IPermission"); - e.AddAttribute ("class", GetType ().AssemblyQualifiedName); - e.AddAttribute ("version", "1"); + SecurityElement se = Element (version); if (m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage) - e.AddAttribute ("Unrestricted", "true"); - - else if (m_allowed == IsolatedStorageContainment.None) - e.AddAttribute ("Allowed", "None"); + se.AddAttribute ("Unrestricted", "true"); + else + se.AddAttribute ("Allowed", m_allowed.ToString ()); - return e; + return se; } - public override void FromXml (SecurityElement esd) { - if (esd == null) - throw new ArgumentNullException ( - Locale.GetText ("The argument is null.")); - - if (esd.Attribute ("class") != GetType ().AssemblyQualifiedName) - throw new ArgumentException ( - Locale.GetText ("The argument is not valid")); + // General validation in CodeAccessPermission + CheckSecurityElement (esd, "esd", version, version); + // Note: we do not (yet) care about the return value + // as we only accept version 1 (min/max values) + + m_userQuota = 0; + m_machineQuota = 0; + m_expirationDays = 0; + m_permanentData = false; + m_allowed = IsolatedStorageContainment.None; + + if (IsUnrestricted (esd)) { + UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage; + } + else { + string a = esd.Attribute ("Allowed"); + if (a != null) { + UsageAllowed = (IsolatedStorageContainment) Enum.Parse ( + typeof (IsolatedStorageContainment), a); + } + } + } - if (esd.Attribute ("version") != "1") - throw new ArgumentException ( - Locale.GetText ("The argument is not valid")); - - if (esd.Attribute ("Unrestricted") == "true") - m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage; + // helpers - else if (esd.Attribute ("Allowed") == "None") - m_allowed = IsolatedStorageContainment.None; + internal bool IsEmpty () + { + // should we include internals ? or just publics ? + return ((m_userQuota == 0) && (m_allowed == IsolatedStorageContainment.None)); } } } |