Merge pull request #303 from ermshiperete/5278
[mono.git] / mcs / class / corlib / System.Security.AccessControl / ObjectSecurity_T.cs
1 //
2 // System.Security.AccessControl.ObjectSecurity<T>
3 //
4 // Authors:
5 //      ?
6 //      James Bellinger  <jfb@zer7.com>
7 //
8 // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
9 // Copyright (C) 2012 James Bellinger
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 #if NET_4_0
32
33 using System.Runtime.InteropServices;
34 using System.Security.Principal;
35
36 namespace System.Security.AccessControl
37 {
38         public abstract class ObjectSecurity<T> : NativeObjectSecurity where T : struct
39         {
40                 protected ObjectSecurity (bool isContainer,
41                                           ResourceType resourceType)
42                         : base (isContainer, resourceType)
43                 {
44
45                 }
46                 
47                 protected ObjectSecurity (bool isContainer,
48                                           ResourceType resourceType,
49                                           SafeHandle safeHandle,
50                                           AccessControlSections includeSections)
51                         : base (isContainer, resourceType, safeHandle, includeSections)
52                 {
53
54                 }
55                 
56                 protected ObjectSecurity (bool isContainer,
57                                           ResourceType resourceType,
58                                           string name,
59                                           AccessControlSections includeSections)
60                         : base (isContainer, resourceType, name, includeSections)
61                 {
62
63                 }
64                 
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)
73                 {
74
75                 }
76                 
77                 protected ObjectSecurity (bool isContainer,
78                                           ResourceType resourceType,
79                                           string name,
80                                           AccessControlSections includeSections,
81                                           ExceptionFromErrorCode exceptionFromErrorCode,
82                                           object exceptionContext)
83                         : base (isContainer, resourceType, name, includeSections,
84                                 exceptionFromErrorCode, exceptionContext)
85                 {
86
87                 }
88
89                 public override Type AccessRightType {
90                         get { return typeof (T); }
91                 }
92                 
93                 public override Type AccessRuleType {
94                         get { return typeof (AccessRule<T>); }
95                 }
96                 
97                 public override Type AuditRuleType {
98                         get { return typeof (AuditRule<T>); }
99                 }
100                 
101                 public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask,
102                                                              bool isInherited, InheritanceFlags inheritanceFlags,
103                                                              PropagationFlags propagationFlags, AccessControlType type)
104                 {
105                         return new AccessRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
106                 }
107                 
108                 public void AddAccessRule (AccessRule<T> rule)
109                 {
110                         AddAccessRule ((AccessRule)rule);
111                 }
112                 
113                 public bool RemoveAccessRule (AccessRule<T> rule)
114                 {
115                         return RemoveAccessRule ((AccessRule)rule);
116                 }
117                 
118                 public void RemoveAccessRuleAll (AccessRule<T> rule)
119                 {
120                         RemoveAccessRuleAll ((AccessRule)rule);
121                 }
122                 
123                 public void RemoveAccessRuleSpecific (AccessRule<T> rule)
124                 {
125                         RemoveAccessRuleSpecific ((AccessRule)rule);
126                 }
127                 
128                 public void ResetAccessRule (AccessRule<T> rule)
129                 {
130                         ResetAccessRule ((AccessRule)rule);
131                 }
132                 
133                 public void SetAccessRule (AccessRule<T> rule)
134                 {
135                         SetAccessRule ((AccessRule)rule);
136                 }
137                 
138                 public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask,
139                                                            bool isInherited, InheritanceFlags inheritanceFlags,
140                                                            PropagationFlags propagationFlags, AuditFlags flags)
141                 {
142                         return new AuditRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
143                 }
144                 
145                 public void AddAuditRule (AuditRule<T> rule)
146                 {
147                         AddAuditRule ((AuditRule)rule);
148                 }
149                 
150                 public bool RemoveAuditRule (AuditRule<T> rule)
151                 {
152                         return RemoveAuditRule((AuditRule)rule);
153                 }
154                 
155                 public void RemoveAuditRuleAll (AuditRule<T> rule)
156                 {
157                         RemoveAuditRuleAll((AuditRule)rule);
158                 }
159                 
160                 public void RemoveAuditRuleSpecific (AuditRule<T> rule)
161                 {
162                         RemoveAuditRuleSpecific((AuditRule)rule);
163                 }
164                 
165                 public void SetAuditRule (AuditRule<T> rule)
166                 {
167                         SetAuditRule((AuditRule)rule);
168                 }
169                 
170                 protected void Persist (SafeHandle handle)
171                 {
172                         WriteLock ();
173                         try {
174                                 Persist (handle, AccessControlSectionsModified);
175                         } finally {
176                                 WriteUnlock ();
177                         }
178                 }
179                 
180                 protected void Persist (string name)
181                 {
182                         WriteLock ();
183                         try {
184                                 Persist (name, AccessControlSectionsModified);
185                         } finally {
186                                 WriteUnlock ();
187                         }
188                 }
189         }
190 }
191         
192 #endif
193