public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence) { if (evidence == null) { throw new ArgumentNullException("evidence"); } CodeGroup return_group = null; if (MembershipCondition.Check(evidence)) { return_group = Copy(); foreach (CodeGroup child_group in Children) { CodeGroup matching = child_group.ResolveMatchingCodeGroups(evidence); if (matching == null) { continue; } return_group.AddChild(matching); } } return(return_group); }
public SecurityElement ToXml(PolicyLevel level) { SecurityElement e = new SecurityElement("CodeGroup"); e.AddAttribute("class", this.GetType().AssemblyQualifiedName); e.AddAttribute("version", "1"); if (null != Name) { e.AddAttribute("Name", Name); } if (null != Description) { e.AddAttribute("Description", Description); } if (null != MembershipCondition) { e.AddChild(MembershipCondition.ToXml()); } if ((PolicyStatement != null) && (PolicyStatement.PermissionSet != null)) { e.AddChild(PolicyStatement.PermissionSet.ToXml()); } foreach (CodeGroup child in Children) { e.AddChild(child.ToXml()); } CreateXml(e, level); return(e); }
// Resolve code groups that match specific evidence. public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence) { NetCodeGroup newGroup; CodeGroup child; // Validate the parameter. if (evidence == null) { throw new ArgumentNullException("evidence"); } // Check the membership condition. if (!MembershipCondition.Check(evidence)) { return(null); } // Clone this group, except for the children. newGroup = new NetCodeGroup(MembershipCondition); newGroup.Name = Name; newGroup.Description = Description; // Resolve and add the children. foreach (CodeGroup group in Children) { child = group.ResolveMatchingCodeGroups(evidence); if (child != null) { newGroup.AddChild(child); } } // Return the result. return(newGroup); }
// Resolve the policy for this code group. public override PolicyStatement Resolve(Evidence evidence) { if (evidence == null) { throw new ArgumentNullException("evidence"); } if (!MembershipCondition.Check(evidence)) { return(null); } PolicyStatement stmt = PolicyStatement; PolicyStatement childStmt; foreach (CodeGroup group in Children) { childStmt = group.Resolve(evidence); if (childStmt != null) { if ((stmt.Attributes & PolicyStatementAttribute.Exclusive) != 0 && (childStmt.Attributes & PolicyStatementAttribute.Exclusive) != 0) { throw new PolicyException(_("Security_Exclusive")); } stmt.PermissionSetNoCopy = stmt.PermissionSetNoCopy.Union (childStmt.PermissionSetNoCopy); stmt.Attributes |= childStmt.Attributes; } } return(stmt); }
public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence) { if (null == evidence) { throw new ArgumentNullException("evidence"); } if (!MembershipCondition.Check(evidence)) { return(null); } FileCodeGroup matchRoot = new FileCodeGroup(MembershipCondition, m_access); foreach (CodeGroup child in Children) { CodeGroup childMatchingCodeGroup = child.ResolveMatchingCodeGroups(evidence); if (childMatchingCodeGroup != null) { matchRoot.AddChild(childMatchingCodeGroup); } } return(matchRoot); }
public override PolicyStatement Resolve(Evidence evidence) { if (evidence == null) { throw new ArgumentNullException("evidence"); } if (!MembershipCondition.Check(evidence)) { return(null); } PermissionSet ps = this.PolicyStatement.PermissionSet.Copy(); if (this.Children.Count > 0) { foreach (CodeGroup child_cg in this.Children) { PolicyStatement child_pst = child_cg.Resolve(evidence); if (child_pst != null) { ps = ps.Union(child_pst.PermissionSet); } } } PolicyStatement pst = this.PolicyStatement.Copy(); pst.PermissionSet = ps; return(pst); }
public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence) { if (evidence == null) { throw new ArgumentNullException("evidence"); } 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 bool Equals(CodeGroup cg, bool compareChildren) { if (cg == null) { return(false); } if (Name != cg.Name || Description != cg.Description || !MembershipCondition.Equals(cg.MembershipCondition)) { return(false); } if (compareChildren) { IList list1 = Children; IList list2 = cg.Children; if (list1.Count != list2.Count) { return(false); } int posn; for (posn = 0; posn < list1.Count; ++posn) { if (!((CodeGroup)(list1[posn])).Equals (((CodeGroup)(list2[posn])), true)) { return(false); } } } return(true); }
public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence) { if (evidence == null) { throw new ArgumentNullException("evidence"); } if (!MembershipCondition.Check(evidence)) { return(null); } foreach (CodeGroup child in Children) { if (child.Resolve(evidence) != null) { return(child.Copy()); // first match // FIXME copy childrens ? } } return(this.CopyNoChildren()); // default }
public override PolicyStatement Resolve(Evidence evidence) { if (evidence == null) { throw new ArgumentNullException("evidence"); } if (!MembershipCondition.Check(evidence)) { return(null); } foreach (CodeGroup child in Children) { PolicyStatement policy = child.Resolve(evidence); if (policy != null) { return(policy); // first match } } return(this.PolicyStatement); // default }
// Resolve code groups that match specific evidence. public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence) { if (evidence == null) { throw new ArgumentNullException("evidence"); } if (!MembershipCondition.Check(evidence)) { return(null); } CodeGroup groups = Copy(); CodeGroup childGroup; foreach (CodeGroup group in Children) { childGroup = group.ResolveMatchingCodeGroups(evidence); if (childGroup != null) { groups.AddChild(childGroup); } } return(groups); }
// Resolve the policy for this code group. public override PolicyStatement Resolve(Evidence evidence) { PolicyStatement stmt; PolicyStatement childStmt; IEnumerator e; Site site; UrlParser url; // Validate the parameter. if (evidence == null) { throw new ArgumentNullException("evidence"); } // Check the membership condition. if (!MembershipCondition.Check(evidence)) { return(null); } // Scan the host evidence for a policy and site. stmt = null; site = null; e = evidence.GetHostEnumerator(); while (e.MoveNext()) { if (e.Current is Url) { url = ((Url)(e.Current)).parser; stmt = MakePolicy(url.Scheme, url.Host); } else if (e.Current is Site && site == null) { site = (Site)(e.Current); } } // Create a default policy statement if necessary. if (stmt == null && site != null) { stmt = MakePolicy(null, site.Name); } else if (stmt == null) { stmt = new PolicyStatement (new PermissionSet(PermissionState.None), PolicyStatementAttribute.Nothing); } // Modify the policy statement from this code group. foreach (CodeGroup group in Children) { childStmt = group.Resolve(evidence); if (childStmt != null) { if ((stmt.Attributes & PolicyStatementAttribute.Exclusive) != 0 && (childStmt.Attributes & PolicyStatementAttribute.Exclusive) != 0) { throw new PolicyException(_("Security_Exclusive")); } } stmt.PermissionSetNoCopy = stmt.PermissionSetNoCopy.Union (childStmt.PermissionSetNoCopy); stmt.Attributes |= childStmt.Attributes; } return(stmt); }