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.
33 using System.Runtime.InteropServices;
34 using System.Security.Principal;
36 namespace System.Security.AccessControl
38 public abstract class ObjectSecurity<T> : NativeObjectSecurity where T : struct
40 protected ObjectSecurity (bool isContainer,
41 ResourceType resourceType)
42 : base (isContainer, resourceType)
47 protected ObjectSecurity (bool isContainer,
48 ResourceType resourceType,
49 SafeHandle safeHandle,
50 AccessControlSections includeSections)
51 : base (isContainer, resourceType, safeHandle, includeSections)
56 protected ObjectSecurity (bool isContainer,
57 ResourceType resourceType,
59 AccessControlSections includeSections)
60 : base (isContainer, resourceType, name, includeSections)
65 protected ObjectSecurity (bool isContainer,
66 ResourceType resourceType,
67 SafeHandle safeHandle,
68 AccessControlSections includeSections,
69 ExceptionFromErrorCode exceptionFromErrorCode,
70 object exceptionContext)
71 : base (isContainer, resourceType, safeHandle, includeSections,
72 exceptionFromErrorCode, exceptionContext)
77 protected ObjectSecurity (bool isContainer,
78 ResourceType resourceType,
80 AccessControlSections includeSections,
81 ExceptionFromErrorCode exceptionFromErrorCode,
82 object exceptionContext)
83 : base (isContainer, resourceType, name, includeSections,
84 exceptionFromErrorCode, exceptionContext)
89 public override Type AccessRightType {
90 get { return typeof (T); }
93 public override Type AccessRuleType {
94 get { return typeof (AccessRule<T>); }
97 public override Type AuditRuleType {
98 get { return typeof (AuditRule<T>); }
101 public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask,
102 bool isInherited, InheritanceFlags inheritanceFlags,
103 PropagationFlags propagationFlags, AccessControlType type)
105 return new AccessRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
108 public void AddAccessRule (AccessRule<T> rule)
110 AddAccessRule ((AccessRule)rule);
113 public bool RemoveAccessRule (AccessRule<T> rule)
115 return RemoveAccessRule ((AccessRule)rule);
118 public void RemoveAccessRuleAll (AccessRule<T> rule)
120 RemoveAccessRuleAll ((AccessRule)rule);
123 public void RemoveAccessRuleSpecific (AccessRule<T> rule)
125 RemoveAccessRuleSpecific ((AccessRule)rule);
128 public void ResetAccessRule (AccessRule<T> rule)
130 ResetAccessRule ((AccessRule)rule);
133 public void SetAccessRule (AccessRule<T> rule)
135 SetAccessRule ((AccessRule)rule);
138 public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask,
139 bool isInherited, InheritanceFlags inheritanceFlags,
140 PropagationFlags propagationFlags, AuditFlags flags)
142 return new AuditRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
145 public void AddAuditRule (AuditRule<T> rule)
147 AddAuditRule ((AuditRule)rule);
150 public bool RemoveAuditRule (AuditRule<T> rule)
152 return RemoveAuditRule((AuditRule)rule);
155 public void RemoveAuditRuleAll (AuditRule<T> rule)
157 RemoveAuditRuleAll((AuditRule)rule);
160 public void RemoveAuditRuleSpecific (AuditRule<T> rule)
162 RemoveAuditRuleSpecific((AuditRule)rule);
165 public void SetAuditRule (AuditRule<T> rule)
167 SetAuditRule((AuditRule)rule);
170 protected void Persist (SafeHandle handle)
174 Persist (handle, AccessControlSectionsModified);
180 protected void Persist (string name)
184 Persist (name, AccessControlSectionsModified);