2 // System.Security.AccessControl.ObjectSecurity<T>
6 // James Bellinger <jfb@zer7.com>
8 // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
9 // Copyright (C) 2012 James Bellinger
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.Runtime.InteropServices;
33 using System.Security.Principal;
35 namespace System.Security.AccessControl
37 public abstract class ObjectSecurity<T> : NativeObjectSecurity where T : struct
39 protected ObjectSecurity (bool isContainer,
40 ResourceType resourceType)
41 : base (isContainer, resourceType)
46 protected ObjectSecurity (bool isContainer,
47 ResourceType resourceType,
48 SafeHandle safeHandle,
49 AccessControlSections includeSections)
50 : base (isContainer, resourceType, safeHandle, includeSections)
55 protected ObjectSecurity (bool isContainer,
56 ResourceType resourceType,
58 AccessControlSections includeSections)
59 : base (isContainer, resourceType, name, includeSections)
64 protected ObjectSecurity (bool isContainer,
65 ResourceType resourceType,
66 SafeHandle safeHandle,
67 AccessControlSections includeSections,
68 ExceptionFromErrorCode exceptionFromErrorCode,
69 object exceptionContext)
70 : base (isContainer, resourceType, safeHandle, includeSections,
71 exceptionFromErrorCode, exceptionContext)
76 protected ObjectSecurity (bool isContainer,
77 ResourceType resourceType,
79 AccessControlSections includeSections,
80 ExceptionFromErrorCode exceptionFromErrorCode,
81 object exceptionContext)
82 : base (isContainer, resourceType, name, includeSections,
83 exceptionFromErrorCode, exceptionContext)
88 public override Type AccessRightType {
89 get { return typeof (T); }
92 public override Type AccessRuleType {
93 get { return typeof (AccessRule<T>); }
96 public override Type AuditRuleType {
97 get { return typeof (AuditRule<T>); }
100 public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask,
101 bool isInherited, InheritanceFlags inheritanceFlags,
102 PropagationFlags propagationFlags, AccessControlType type)
104 return new AccessRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
107 public virtual void AddAccessRule (AccessRule<T> rule)
109 AddAccessRule ((AccessRule)rule);
112 public virtual bool RemoveAccessRule (AccessRule<T> rule)
114 return RemoveAccessRule ((AccessRule)rule);
117 public virtual void RemoveAccessRuleAll (AccessRule<T> rule)
119 RemoveAccessRuleAll ((AccessRule)rule);
122 public virtual void RemoveAccessRuleSpecific (AccessRule<T> rule)
124 RemoveAccessRuleSpecific ((AccessRule)rule);
127 public virtual void ResetAccessRule (AccessRule<T> rule)
129 ResetAccessRule ((AccessRule)rule);
132 public virtual void SetAccessRule (AccessRule<T> rule)
134 SetAccessRule ((AccessRule)rule);
137 public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask,
138 bool isInherited, InheritanceFlags inheritanceFlags,
139 PropagationFlags propagationFlags, AuditFlags flags)
141 return new AuditRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
144 public virtual void AddAuditRule (AuditRule<T> rule)
146 AddAuditRule ((AuditRule)rule);
149 public virtual bool RemoveAuditRule (AuditRule<T> rule)
151 return RemoveAuditRule((AuditRule)rule);
154 public virtual void RemoveAuditRuleAll (AuditRule<T> rule)
156 RemoveAuditRuleAll((AuditRule)rule);
159 public virtual void RemoveAuditRuleSpecific (AuditRule<T> rule)
161 RemoveAuditRuleSpecific((AuditRule)rule);
164 public virtual void SetAuditRule (AuditRule<T> rule)
166 SetAuditRule((AuditRule)rule);
169 protected void Persist (SafeHandle handle)
173 Persist (handle, AccessControlSectionsModified);
179 protected void Persist (string name)
183 Persist (name, AccessControlSectionsModified);