1 // System.Security.Policy.FirstMatchCodeGroup
4 // Jackson Harper (Jackson@LatitudeGeo.com)
6 // (C) 2002 Jackson Harper, All rights reserved.
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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 namespace System.Security.Policy {
36 public sealed class FirstMatchCodeGroup : CodeGroup {
38 public FirstMatchCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy) :
39 base (membershipCondition, policy) {}
41 // for PolicyLevel (to avoid validation duplication)
42 internal FirstMatchCodeGroup (SecurityElement e) : base (e) {}
48 public override string MergeLogic
50 get { return "First Match"; }
57 public override CodeGroup Copy()
59 FirstMatchCodeGroup copy = CopyNoChildren ();
60 foreach (CodeGroup child in Children) {
61 copy.AddChild (child.Copy ()); // deep copy
66 public override PolicyStatement Resolve(Evidence evidence)
68 PolicyStatement policy = null;
69 PolicyStatement child_policy;
72 throw new ArgumentNullException ();
74 if (MembershipCondition.Check (evidence)) {
75 if (null != PolicyStatement) {
76 policy = PolicyStatement;
78 // Loop through all children breaking on the first one that resolves
79 foreach (CodeGroup child in Children) {
80 if (null == (child_policy = child.Resolve (evidence)))
82 policy = child_policy;
91 public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
93 CodeGroup group = null;
96 throw new ArgumentNullException ();
98 if (MembershipCondition.Check (evidence)) {
99 group = CopyNoChildren ();
101 // Add the first child that resolves
102 foreach (CodeGroup child in Children) {
103 if ( null == child.Resolve (evidence))
105 group.AddChild (child);
117 private FirstMatchCodeGroup CopyNoChildren()
119 FirstMatchCodeGroup copy = new FirstMatchCodeGroup (MembershipCondition, PolicyStatement);
122 copy.Description = Description;