2008-07-13 Nestor Salceda <nestor.salceda@gmail.com>
[mono.git] / mcs / class / corlib / System.Security.AccessControl / CommonObjectSecurity.cs
1 //
2 // System.Security.AccessControl.CommonObjectSecurity implementation
3 //
4 // Authors:
5 //      Dick Porter  <dick@ximian.com>
6 //      Atsushi Enomoto  <atsushi@ximian.com>
7 //
8 // Copyright (C) 2005-2007 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #if NET_2_0
31 using System.Collections.Generic;
32
33 namespace System.Security.AccessControl {
34
35         [MonoTODO ("required for NativeObjectSecurity - implementation is missing")]
36         public abstract class CommonObjectSecurity : ObjectSecurity {
37
38                 protected CommonObjectSecurity (bool isContainer)
39                         : base (isContainer, false)
40                 {
41                 }
42                 
43                 List<AccessRule> access_rules = new List<AccessRule> ();
44                 List<AuditRule> audit_rules = new List<AuditRule> ();
45                 
46                 public AuthorizationRuleCollection GetAccessRules (bool includeExplicit, bool includeInherited, Type targetType)
47                 {
48                         throw new NotImplementedException ();
49                 }
50                 
51                 public AuthorizationRuleCollection GetAuditRules (bool includeExplicit, bool includeInherited, Type targetType)
52                 {
53                         throw new NotImplementedException ();
54                 }
55                 
56                 // Access
57                 
58                 protected void AddAccessRule (AccessRule rule)
59                 {
60                         access_rules.Add (rule);
61                         AccessRulesModified = true;
62                 }
63                 
64                 protected bool RemoveAccessRule (AccessRule rule)
65                 {
66                         throw new NotImplementedException ();
67                 }
68                 
69                 protected void RemoveAccessRuleAll (AccessRule rule)
70                 {
71                         throw new NotImplementedException ();
72                 }
73                 
74                 protected void RemoveAccessRuleSpecific (AccessRule rule)
75                 {
76                         throw new NotImplementedException ();
77                 }
78                 
79                 protected void ResetAccessRule (AccessRule rule)
80                 {
81                         throw new NotImplementedException ();
82                 }
83                 
84                 protected void SetAccessRule (AccessRule rule)
85                 {
86                         throw new NotImplementedException ();
87                 }
88                 
89                 protected override bool ModifyAccess (AccessControlModification modification, AccessRule rule, out bool modified)
90                 {
91                         foreach (AccessRule r in access_rules) {
92                                 if (rule != r)
93                                         continue;
94                                 switch (modification) {
95                                 case AccessControlModification.Add:
96                                         AddAccessRule (rule);
97                                         break;
98                                 case AccessControlModification.Set:
99                                         SetAccessRule (rule);
100                                         break;
101                                 case AccessControlModification.Reset:
102                                         ResetAccessRule (rule);
103                                         break;
104                                 case AccessControlModification.Remove:
105                                         RemoveAccessRule (rule);
106                                         break;
107                                 case AccessControlModification.RemoveAll:
108                                         RemoveAccessRuleAll (rule);
109                                         break;
110                                 case AccessControlModification.RemoveSpecific:
111                                         RemoveAccessRuleSpecific (rule);
112                                         break;
113                                 }
114                                 modified = true;
115                                 return true;
116                         }
117                         modified = false;
118                         return false;
119                 }
120                 
121                 // Audit
122                 
123                 protected void AddAuditRule (AuditRule rule)
124                 {
125                         audit_rules.Add (rule);
126                         AuditRulesModified = true;
127                 }
128                 
129                 protected bool RemoveAuditRule (AuditRule rule)
130                 {
131                         throw new NotImplementedException ();
132                 }
133                 
134                 protected void RemoveAuditRuleAll (AuditRule rule)
135                 {
136                         throw new NotImplementedException ();
137                 }
138                 
139                 protected void RemoveAuditRuleSpecific (AuditRule rule)
140                 {
141                         throw new NotImplementedException ();
142                 }
143                 
144                 protected void SetAuditRule (AuditRule rule)
145                 {
146                         throw new NotImplementedException ();
147                 }
148                 
149                 protected override bool ModifyAudit (AccessControlModification modification, AuditRule rule, out bool modified)
150                 {
151                         foreach (AuditRule r in audit_rules) {
152                                 if (rule != r)
153                                         continue;
154                                 switch (modification) {
155                                 case AccessControlModification.Add:
156                                         AddAuditRule (rule);
157                                         break;
158                                 case AccessControlModification.Set:
159                                         SetAuditRule (rule);
160                                         break;
161                                 //case AccessControlModification.Reset:
162                                 //      ResetAuditRule (rule);
163                                 //      break;
164                                 case AccessControlModification.Remove:
165                                         RemoveAuditRule (rule);
166                                         break;
167                                 case AccessControlModification.RemoveAll:
168                                         RemoveAuditRuleAll (rule);
169                                         break;
170                                 case AccessControlModification.RemoveSpecific:
171                                         RemoveAuditRuleSpecific (rule);
172                                         break;
173                                 }
174                                 AuditRulesModified = true;
175                                 modified = true;
176                                 return true;
177                         }
178                         modified = false;
179                         return false;
180                 }
181         }
182 }
183
184 #endif