AuthorizationRule.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // System.Web.Configuration.AuthorizationRule
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections.Specialized;
  31. using System.Configuration;
  32. using System.ComponentModel;
  33. using System.Xml;
  34. #if NET_2_0
  35. namespace System.Web.Configuration {
  36. public sealed class AuthorizationRule : ConfigurationElement
  37. {
  38. static ConfigurationProperty rolesProp;
  39. static ConfigurationProperty usersProp;
  40. static ConfigurationProperty verbsProp;
  41. static ConfigurationPropertyCollection properties;
  42. AuthorizationRuleAction action;
  43. static AuthorizationRule ()
  44. {
  45. rolesProp = new ConfigurationProperty ("roles", typeof (StringCollection));
  46. usersProp = new ConfigurationProperty ("users", typeof (StringCollection));
  47. verbsProp = new ConfigurationProperty ("verbs", typeof (StringCollection));
  48. properties = new ConfigurationPropertyCollection ();
  49. properties.Add (rolesProp);
  50. properties.Add (usersProp);
  51. properties.Add (verbsProp);
  52. }
  53. public AuthorizationRule (AuthorizationRuleAction action)
  54. {
  55. this.action = action;
  56. }
  57. public override bool Equals (object obj)
  58. {
  59. AuthorizationRule auth = obj as AuthorizationRule;
  60. if (auth == null)
  61. return false;
  62. if (action != auth.Action)
  63. return false;
  64. if (Roles.Count != auth.Roles.Count
  65. || Users.Count != auth.Users.Count
  66. || Verbs.Count != auth.Verbs.Count)
  67. return false;
  68. int i;
  69. for (i = 0; i < Roles.Count; i ++)
  70. if (Roles[i] != auth.Roles[i])
  71. return false;
  72. for (i = 0; i < Users.Count; i ++)
  73. if (Users[i] != auth.Users[i])
  74. return false;
  75. for (i = 0; i < Verbs.Count; i ++)
  76. if (Verbs[i] != auth.Verbs[i])
  77. return false;
  78. return true;
  79. }
  80. public override int GetHashCode ()
  81. {
  82. int hashCode = (int)action;
  83. int i;
  84. for (i = 0; i < Roles.Count; i ++)
  85. hashCode += Roles[i].GetHashCode();
  86. for (i = 0; i < Users.Count; i ++)
  87. hashCode += Users[i].GetHashCode();
  88. for (i = 0; i < Verbs.Count; i ++)
  89. hashCode += Verbs[i].GetHashCode();
  90. return hashCode;
  91. }
  92. [MonoTODO]
  93. protected override bool IsModified ()
  94. {
  95. throw new NotImplementedException ();
  96. }
  97. [MonoTODO]
  98. protected override void PostDeserialize ()
  99. {
  100. base.PostDeserialize();
  101. }
  102. [MonoTODO]
  103. protected override void PreSerialize (XmlWriter writer)
  104. {
  105. base.PreSerialize (writer);
  106. }
  107. [MonoTODO]
  108. protected override void Reset (ConfigurationElement parentElement)
  109. {
  110. base.Reset (parentElement);
  111. }
  112. [MonoTODO]
  113. protected override void ResetModified ()
  114. {
  115. base.ResetModified ();
  116. }
  117. [MonoTODO]
  118. protected override bool SerializeElement (XmlWriter writer, bool serializeCollectionKey)
  119. {
  120. bool ret = base.SerializeElement (writer, serializeCollectionKey);
  121. /* XXX more here? .. */
  122. return ret;
  123. }
  124. [MonoTODO]
  125. protected override void SetReadOnly ()
  126. {
  127. base.SetReadOnly();
  128. }
  129. [MonoTODO]
  130. protected override void Unmerge (ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
  131. {
  132. base.Unmerge (sourceElement, parentElement, saveMode);
  133. }
  134. public AuthorizationRuleAction Action {
  135. get { return action; }
  136. set { action = value; }
  137. }
  138. #if notyet
  139. [TypeConverter (typeof (CommaDelimitedStringCollectionConverter))]
  140. #endif
  141. [ConfigurationProperty ("roles")]
  142. public StringCollection Roles {
  143. get { return (StringCollection) base [rolesProp];}
  144. }
  145. #if notyet
  146. [TypeConverter (typeof (CommaDelimitedStringCollectionConverter))]
  147. #endif
  148. [ConfigurationProperty ("users")]
  149. public StringCollection Users {
  150. get { return (StringCollection) base [usersProp];}
  151. }
  152. #if notyet
  153. [TypeConverter (typeof (CommaDelimitedStringCollectionConverter))]
  154. #endif
  155. [ConfigurationProperty ("verbs")]
  156. public StringCollection Verbs {
  157. get { return (StringCollection) base [verbsProp];}
  158. }
  159. protected override ConfigurationPropertyCollection Properties {
  160. get { return properties; }
  161. }
  162. }
  163. }
  164. #endif