//
// System.Security.Policy.UnionCodeGroup.cs
//
-// Author
+// Authors
// Duncan Mak (duncan@ximian.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Ximian, Inc (http://www.ximian.com)
-//
-
-//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.Globalization;
using System.Security.Permissions;
-using System.Security.Policy;
namespace System.Security.Policy {
- [Serializable]
- public sealed class UnionCodeGroup : CodeGroup {
+ [Serializable]
+ public sealed class UnionCodeGroup : CodeGroup {
- public UnionCodeGroup (
- IMembershipCondition membershipCondition,
- PolicyStatement policyStatement)
- : base (membershipCondition, policyStatement)
- {
- }
+ public UnionCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policyStatement)
+ : base (membershipCondition, policyStatement)
+ {
+ }
// for PolicyLevel (to avoid validation duplication)
- internal UnionCodeGroup (SecurityElement e) : base (e) {}
+ internal UnionCodeGroup (SecurityElement e, PolicyLevel level)
+ : base (e, level)
+ {
+ }
- public override CodeGroup Copy ()
- {
- UnionCodeGroup copy = new UnionCodeGroup (MembershipCondition, PolicyStatement);
- foreach (CodeGroup child in Children) {
- copy.AddChild (child.Copy ()); // deep copy
+ public override CodeGroup Copy ()
+ {
+ return Copy (true);
+ }
+
+ internal CodeGroup Copy (bool childs)
+ {
+ UnionCodeGroup copy = new UnionCodeGroup (MembershipCondition, PolicyStatement);
+ copy.Name = Name;
+ copy.Description = Description;
+ if (childs) {
+ foreach (CodeGroup child in Children) {
+ copy.AddChild (child.Copy ());
+ }
}
return copy;
- }
+ }
+
- [MonoTODO]
- public override PolicyStatement Resolve (Evidence evidence)
- {
- if (evidence == null)
- throw new ArgumentNullException ("evidence");
+ public override PolicyStatement Resolve (Evidence evidence)
+ {
+ if (evidence == null)
+ throw new ArgumentNullException ("evidence");
- throw new NotImplementedException ();
- }
+ if (!MembershipCondition.Check (evidence))
+ return null;
- [MonoTODO]
- public override CodeGroup ResolveMatchingCodeGroups (Evidence evidence)
- {
- if (evidence == null)
+ PolicyStatement pst = this.PolicyStatement.Copy ();
+
+ if (this.Children.Count > 0) {
+ foreach (CodeGroup child_cg in this.Children) {
+ PolicyStatement child_pst = child_cg.Resolve (evidence);
+ if (child_pst != null) {
+ foreach (IPermission perm in child_pst.PermissionSet) {
+ pst.PermissionSet.AddPermission (perm);
+ }
+ }
+ }
+ }
+ return pst;
+ }
+
+ public override CodeGroup ResolveMatchingCodeGroups (Evidence evidence)
+ {
+ if (evidence == null)
throw new ArgumentNullException ("evidence");
- throw new NotImplementedException ();
- }
+ if (!MembershipCondition.Check (evidence))
+ return null;
+
+ // Copy() would add the child (even if they didn't match)
+ CodeGroup match = Copy (false);
+ if (this.Children.Count > 0) {
+ foreach (CodeGroup cg in this.Children) {
+ CodeGroup child = cg.ResolveMatchingCodeGroups (evidence);
+ if (child != null)
+ match.AddChild (child);
+ }
+ }
+ return match;
+ }
- public override string MergeLogic {
- get {
- return "Union";
- }
- }
- }
+ public override string MergeLogic {
+ get { return "Union"; }
+ }
+ }
}