FileCodeGroup.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // System.Security.Policy.FileCodeGroup
  2. //
  3. // Author(s):
  4. // Nick Drochak ([email protected])
  5. //
  6. // (C) 2001 Nick Drochak, All rights reserved.
  7. using System.Security.Policy;
  8. using System.Security.Permissions;
  9. using System.Collections;
  10. using System; // for MonoTODO attribute
  11. namespace System.Security.Policy
  12. {
  13. [Serializable]
  14. public sealed class FileCodeGroup : CodeGroup
  15. {
  16. FileIOPermissionAccess m_access;
  17. [MonoTODO("Check if membershipCondition is valid")]
  18. public FileCodeGroup(IMembershipCondition membershipCondition,
  19. FileIOPermissionAccess access)
  20. : base(membershipCondition, null)
  21. {
  22. if (!Enum.IsDefined(typeof(FileIOPermissionAccess), access))
  23. throw new ArgumentException("Value not defined for FileIOPermissionAccess","access");
  24. m_access = access;
  25. }
  26. public override CodeGroup Copy()
  27. {
  28. FileCodeGroup copy = new FileCodeGroup(MembershipCondition, m_access);
  29. foreach (CodeGroup child in Children)
  30. {
  31. AddChild(child.Copy());
  32. }
  33. return copy;
  34. }
  35. public override string MergeLogic
  36. {
  37. get
  38. {
  39. return "Union";
  40. }
  41. }
  42. [MonoTODO]
  43. public override PolicyStatement Resolve( Evidence evidence)
  44. {
  45. if (null == evidence)
  46. throw new ArgumentNullException("evidence");
  47. if (null == PolicyStatement)
  48. throw new PolicyException();
  49. if (!MembershipCondition.Check(evidence))
  50. return null;
  51. IEnumerator hostEnumerator = evidence.GetHostEnumerator();
  52. while (hostEnumerator.MoveNext())
  53. {
  54. // FIXME: not sure what to do here
  55. // How do we check the URL and make a PolicyStatement?
  56. }
  57. throw new NotImplementedException();
  58. }
  59. public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
  60. {
  61. if (null == evidence)
  62. throw new ArgumentNullException("evidence");
  63. if (!MembershipCondition.Check(evidence))
  64. return null;
  65. FileCodeGroup matchRoot = new FileCodeGroup(MembershipCondition, m_access);
  66. foreach (CodeGroup child in Children)
  67. {
  68. CodeGroup childMatchingCodeGroup = child.ResolveMatchingCodeGroups(evidence);
  69. if (childMatchingCodeGroup != null)
  70. AddChild(childMatchingCodeGroup);
  71. }
  72. return matchRoot;
  73. }
  74. public override string AttributeString
  75. {
  76. get
  77. {
  78. return null;
  79. }
  80. }
  81. public override string PermissionSetName
  82. {
  83. get
  84. {
  85. return "Same directory FileIO - " + m_access.ToString();
  86. }
  87. }
  88. public override bool Equals(object o)
  89. {
  90. if (!(o is FileCodeGroup))
  91. return false;
  92. if (this.m_access != ((FileCodeGroup)o).m_access)
  93. return false;
  94. return Equals((CodeGroup)o, false);
  95. }
  96. [MonoTODO]
  97. public override int GetHashCode()
  98. {
  99. throw new NotImplementedException();
  100. }
  101. protected override void ParseXml(SecurityElement e, PolicyLevel level)
  102. {
  103. m_access = (FileIOPermissionAccess)Enum.Parse(typeof(FileIOPermissionAccess), e.Attribute("Access"), true);
  104. }
  105. protected override void CreateXml(SecurityElement element, PolicyLevel level)
  106. {
  107. element.AddAttribute("Access", m_access.ToString());
  108. }
  109. } // public abstract class CodeGroup
  110. } // namespace System.Security.Policy