2010-05-27 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / System.Security.AccessControl / CommonObjectSecurity.cs
blob3addb6c5f564adf50ecdf89a3a7d49de78230458
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.
30 using System.Collections.Generic;
32 namespace System.Security.AccessControl {
34 [MonoTODO ("required for NativeObjectSecurity - implementation is missing")]
35 public abstract class CommonObjectSecurity : ObjectSecurity {
37 protected CommonObjectSecurity (bool isContainer)
38 : base (isContainer, false)
42 List<AccessRule> access_rules = new List<AccessRule> ();
43 List<AuditRule> audit_rules = new List<AuditRule> ();
45 public AuthorizationRuleCollection GetAccessRules (bool includeExplicit, bool includeInherited, Type targetType)
47 throw new NotImplementedException ();
50 public AuthorizationRuleCollection GetAuditRules (bool includeExplicit, bool includeInherited, Type targetType)
52 throw new NotImplementedException ();
55 // Access
57 protected void AddAccessRule (AccessRule rule)
59 access_rules.Add (rule);
60 AccessRulesModified = true;
63 protected bool RemoveAccessRule (AccessRule rule)
65 throw new NotImplementedException ();
68 protected void RemoveAccessRuleAll (AccessRule rule)
70 throw new NotImplementedException ();
73 protected void RemoveAccessRuleSpecific (AccessRule rule)
75 throw new NotImplementedException ();
78 protected void ResetAccessRule (AccessRule rule)
80 throw new NotImplementedException ();
83 protected void SetAccessRule (AccessRule rule)
85 throw new NotImplementedException ();
88 protected override bool ModifyAccess (AccessControlModification modification, AccessRule rule, out bool modified)
90 foreach (AccessRule r in access_rules) {
91 if (rule != r)
92 continue;
93 switch (modification) {
94 case AccessControlModification.Add:
95 AddAccessRule (rule);
96 break;
97 case AccessControlModification.Set:
98 SetAccessRule (rule);
99 break;
100 case AccessControlModification.Reset:
101 ResetAccessRule (rule);
102 break;
103 case AccessControlModification.Remove:
104 RemoveAccessRule (rule);
105 break;
106 case AccessControlModification.RemoveAll:
107 RemoveAccessRuleAll (rule);
108 break;
109 case AccessControlModification.RemoveSpecific:
110 RemoveAccessRuleSpecific (rule);
111 break;
113 modified = true;
114 return true;
116 modified = false;
117 return false;
120 // Audit
122 protected void AddAuditRule (AuditRule rule)
124 audit_rules.Add (rule);
125 AuditRulesModified = true;
128 protected bool RemoveAuditRule (AuditRule rule)
130 throw new NotImplementedException ();
133 protected void RemoveAuditRuleAll (AuditRule rule)
135 throw new NotImplementedException ();
138 protected void RemoveAuditRuleSpecific (AuditRule rule)
140 throw new NotImplementedException ();
143 protected void SetAuditRule (AuditRule rule)
145 throw new NotImplementedException ();
148 protected override bool ModifyAudit (AccessControlModification modification, AuditRule rule, out bool modified)
150 foreach (AuditRule r in audit_rules) {
151 if (rule != r)
152 continue;
153 switch (modification) {
154 case AccessControlModification.Add:
155 AddAuditRule (rule);
156 break;
157 case AccessControlModification.Set:
158 SetAuditRule (rule);
159 break;
160 //case AccessControlModification.Reset:
161 // ResetAuditRule (rule);
162 // break;
163 case AccessControlModification.Remove:
164 RemoveAuditRule (rule);
165 break;
166 case AccessControlModification.RemoveAll:
167 RemoveAuditRuleAll (rule);
168 break;
169 case AccessControlModification.RemoveSpecific:
170 RemoveAuditRuleSpecific (rule);
171 break;
173 AuditRulesModified = true;
174 modified = true;
175 return true;
177 modified = false;
178 return false;