Implemented the .NET 4.0 generic versions of AccessRule and AuditRule.
authorJames Bellinger <jfb@zer7.com>
Sat, 30 Jun 2012 17:21:46 +0000 (13:21 -0400)
committerJames Bellinger <jfb@zer7.com>
Sat, 30 Jun 2012 17:21:46 +0000 (13:21 -0400)
Details worth being aware of, that aren't well documented in MS.NET:

(1) The Rights property is just a casted AccessMask.
I've checked this by testing with MS.NET -- if you use AccessRule<Test>
with an arbitrary struct Test { }, MS.NET has an InvalidCastException
on the Rights getter if you create with ObjectSecurity's factory method
(which is passed an int), and in the constructor if you use AccessRule's
constructor.

(2) The string constructor overloads call 'new NTAccount(identity)'.
What these methods do for AccessRule is not documented by MS.NET,
but this *is* documented for SemaphoreAccessRule, and my testing
with C# shows AccessRule does the same thing. So, I've implemented
this behavior to match.

I will submit a separate patch afterwards to make AuthorizationRule's
accept NTAccount, which is required for the string overloads to work.
Contrary to the MS.NET *documentation* (which Mono follows), AuthorizationRule
actually accepts NTAccount as well as (the documented) SecurityIdentifier.
I verified this by deriving a class from AuthorizationRule.

mcs/class/corlib/System.Security.AccessControl/AccessRule_T.cs [new file with mode: 0644]
mcs/class/corlib/System.Security.AccessControl/AuditRule_T.cs [new file with mode: 0644]
mcs/class/corlib/System.Security.AccessControl/ChangeLog
mcs/class/corlib/System.Security.AccessControl/ObjectSecurity_T.cs
mcs/class/corlib/corlib.dll.sources

diff --git a/mcs/class/corlib/System.Security.AccessControl/AccessRule_T.cs b/mcs/class/corlib/System.Security.AccessControl/AccessRule_T.cs
new file mode 100644 (file)
index 0000000..9550f8b
--- /dev/null
@@ -0,0 +1,70 @@
+// System.Security.AccessControl.AccessRule<T>
+//
+// Copyright 2012 James F. Bellinger
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#if NET_4_0
+
+using System;
+using System.Security.Principal;
+
+namespace System.Security.AccessControl
+{
+       public class AccessRule<T> : AccessRule where T : struct
+       {
+               public AccessRule (string identity, T rights, AccessControlType type)
+                       : this (new NTAccount (identity), rights, type)
+               {
+
+               }
+
+               public AccessRule (IdentityReference identity, T rights, AccessControlType type)
+                       : this (identity, rights, InheritanceFlags.None, PropagationFlags.None, type)
+               {
+
+               }
+
+               public AccessRule (string identity, T rights, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
+                       : this (new NTAccount (identity), rights, inheritanceFlags, propagationFlags, type)
+               {
+
+               }
+
+               public AccessRule (IdentityReference identity, T rights, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
+                       : this (identity, (int)(object)rights, false, inheritanceFlags, propagationFlags, type)
+               {
+
+               }
+
+               internal AccessRule (IdentityReference identity, int rights, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
+                       : base (identity, rights, isInherited, inheritanceFlags, propagationFlags, type)
+               {
+
+               }
+
+               public T Rights {
+                       get { return (T)(object)AccessMask; }
+               }
+       }
+}
+
+#endif
+
diff --git a/mcs/class/corlib/System.Security.AccessControl/AuditRule_T.cs b/mcs/class/corlib/System.Security.AccessControl/AuditRule_T.cs
new file mode 100644 (file)
index 0000000..4d6c71c
--- /dev/null
@@ -0,0 +1,70 @@
+// System.Security.AccessControl.AuditRule<T>
+//
+// Copyright 2012 James F. Bellinger
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#if NET_4_0
+
+using System;
+using System.Security.Principal;
+
+namespace System.Security.AccessControl
+{
+       public class AuditRule<T> : AuditRule where T : struct
+       {
+               public AuditRule (string identity, T rights, AuditFlags flags)
+                       : this (new NTAccount (identity), rights, flags)
+               {
+
+               }
+
+               public AuditRule (IdentityReference identity, T rights, AuditFlags flags)
+                       : this (identity, rights, InheritanceFlags.None, PropagationFlags.None, flags)
+               {
+
+               }
+
+               public AuditRule (string identity, T rights, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
+                       : this (new NTAccount (identity), rights, inheritanceFlags, propagationFlags, flags)
+               {
+
+               }
+
+               public AuditRule (IdentityReference identity, T rights, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
+                       : this (identity, (int)(object)rights, false, inheritanceFlags, propagationFlags, flags)
+               {
+
+               }
+
+               internal AuditRule (IdentityReference identity, int rights, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
+                       : base (identity, rights, isInherited, inheritanceFlags, propagationFlags, flags)
+               {
+
+               }
+
+               public T Rights {
+                       get { return (T)(object)AccessMask; }
+               }
+       }
+}
+
+#endif
+
index 90da37c6dee2216b759be834331d7aa155392858..fc6d066bc143b50e24496b0f763ed805823344d6 100644 (file)
@@ -1,3 +1,9 @@
+2012-06-30  James Bellinger  <jfb@zer7.com>
+
+       * AccessRule_T.cs AuditRule_T.cs: Implemented .NET 4.0 generic
+       versions of AccessRule and AuditRule.
+       * ObjectSecurity_T.cs: Type returns are now correct.
+
 2009-08-29  Zoltan Varga  <vargaz@gmail.com>
 
        * ObjectSecurity_T.cs: New file, empty stub for new net 4.0 class.
index 30beec0dab3709c2cb7e9791936c47371c9bb9c4..862670629372b65b074cd998a67a50118133c3ee 100644 (file)
@@ -33,32 +33,32 @@ namespace System.Security.AccessControl
        {
                public override Type AccessRightType {
                        get {
-                               return null;
+                               return typeof(T);
                        }
                }
                
                public override Type AccessRuleType {
                        get {
-                               return null;
+                               return typeof (AccessRule<T>);
                        }
                }
                
                public override Type AuditRuleType {
                        get {
-                               return null;
+                               return typeof (AuditRule<T>);
                        }
                }
                
                public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
                {
-                       return null;
+                       return new AccessRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
                }
                
                public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
                {
-                       return null;
+                       return new AuditRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
                }
        }
 }
        
-#endif
\ No newline at end of file
+#endif
index 73433d1c3e4dcb7afd5d0f3ecc1b3156fce1510d..a4bba228bb4ed3ae4b23ecc97b44328201b7298b 100644 (file)
@@ -1197,12 +1197,14 @@ System.Security.AccessControl/AccessControlModification.cs
 System.Security.AccessControl/AccessControlSections.cs
 System.Security.AccessControl/AccessControlType.cs
 System.Security.AccessControl/AccessRule.cs
+System.Security.AccessControl/AccessRule_T.cs
 System.Security.AccessControl/AceEnumerator.cs
 System.Security.AccessControl/AceFlags.cs
 System.Security.AccessControl/AceQualifier.cs
 System.Security.AccessControl/AceType.cs
 System.Security.AccessControl/AuditFlags.cs
 System.Security.AccessControl/AuditRule.cs
+System.Security.AccessControl/AuditRule_T.cs
 System.Security.AccessControl/AuthorizationRule.cs
 System.Security.AccessControl/AuthorizationRuleCollection.cs
 System.Security.AccessControl/CommonAce.cs