| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- // System.Security.Policy.CodeGroup
- //
- // Author(s):
- // Nick Drochak ([email protected])
- //
- // (C) 2001 Nick Drochak, All rights reserved.
- using System.Security.Policy;
- using System.Security.Permissions;
- using System.Collections;
- using System; // for MonoTODO attribute
- namespace System.Security.Policy
- {
- [Serializable]
- public abstract class CodeGroup
- {
- PolicyStatement m_policy = null;
- IMembershipCondition m_membershipCondition = null;
- string m_description = null;
- string m_name = null;
- ArrayList m_children = new ArrayList();
- PolicyLevel m_level;
- public CodeGroup(IMembershipCondition membershipCondition,
- PolicyStatement policy)
- {
- if (null == membershipCondition)
- throw new ArgumentNullException("Value cannot be null.");
- m_policy = policy;
- m_membershipCondition = membershipCondition;
- }
- public abstract CodeGroup Copy();
- public abstract string MergeLogic {get;}
- public abstract PolicyStatement Resolve( Evidence evidence);
- public abstract CodeGroup ResolveMatchingCodeGroups(Evidence evidence);
- public PolicyStatement PolicyStatement
- {
- get
- {
- return m_policy;
- }
- set
- {
- m_policy = value;
- }
- }
- public string Description
- {
- get
- {
- return m_description;
- }
- set
- {
- m_description = value;
- }
- }
- public IMembershipCondition MembershipCondition
- {
- get
- {
- return m_membershipCondition;
- }
- set
- {
- if (null == value)
- throw new ArgumentException("Value cannot be null");
- m_membershipCondition = value;
- }
- }
- public string Name
- {
- get
- {
- return m_name;
- }
- set
- {
- m_name = value;
- }
- }
- public IList Children
- {
- get
- {
- return m_children;
- }
- set
- {
- if (null == value)
- throw new ArgumentException("Value cannot be null");
- m_children = new ArrayList(value);
- }
- }
- public virtual string AttributeString
- {
- get
- {
- if (null != m_policy)
- return m_policy.AttributeString;
- return null;
- }
- }
- public virtual string PermissionSetName
- {
- get
- {
- if (m_policy.PermissionSet is Security.NamedPermissionSet)
- return ((NamedPermissionSet)(m_policy.PermissionSet)).Name;
- return null;
- }
- }
- public void AddChild(CodeGroup group)
- {
- if (null == group)
- throw new ArgumentNullException("The group parameter cannot be null");
- m_children.Add(group);
- }
- public override bool Equals(object o)
- {
- if (!(o is CodeGroup))
- return false;
- return Equals((CodeGroup)o, false);
- }
- public bool Equals(CodeGroup cg, bool compareChildren)
- {
- if (cg.Name != this.Name)
- return false;
- if (cg.Description != this.Description)
- return false;
- if (cg.MembershipCondition != this.MembershipCondition)
- return false;
- if (compareChildren)
- {
- int childCount = cg.Children.Count;
- if (this.Children.Count != childCount)
- return false;
- for (int index = 0; index < childCount; index++)
- {
- // LAMESPEC: are we supposed to check child equality recursively?
- // The docs imply 'no' but it seems natural to do a 'deep' compare.
- // Will check the children's children, and so-on unless we find out that
- // we shouldn't
- if (!((CodeGroup)(this.Children[index])).Equals((CodeGroup)(cg.Children[index]), true))
- return false;
- }
- }
- return true;
- }
- public void RemoveChild(CodeGroup group)
- {
- if (!m_children.Contains(group))
- throw new ArgumentException();
- m_children.Remove(group);
- }
- [MonoTODO]
- public override int GetHashCode()
- {
- return 42;
- }
- public void FromXml(SecurityElement e)
- {
- FromXml(e, (PolicyLevel)null);
- }
- [MonoTODO]
- public void FromXml(SecurityElement e, PolicyLevel level )
- {
- if (null == e)
- throw new ArgumentNullException("e");
- // Not sure what might be serialized in this XML, so just do the strings for now
- // and null's for everything else
- m_children = null;
- m_policy = null;
- m_membershipCondition = null;
- m_name = e.Attribute("Name");
- m_description = e.Attribute("Description");
- // seems like we might need this to Resolve() in subclasses
- m_level = level;
- ParseXml(e, level);
- }
- protected virtual void ParseXml(SecurityElement e, PolicyLevel level)
- {
- }
-
- public SecurityElement ToXml()
- {
- return ToXml(null);
- }
- [MonoTODO("Not sure what to do with PolicyLevel parameter")]
- 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 (null != PolicyStatement)
- e.AddChild(PolicyStatement.PermissionSet.ToXml());
- foreach (CodeGroup child in Children)
- e.AddChild(child.ToXml());
- CreateXml(e, level);
- return e;
- }
-
- protected virtual void CreateXml(SecurityElement element, PolicyLevel level)
- {
- }
- } // public abstract class CodeGroup
- } // namespace System.Security.Policy
|