AuthConfig.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // System.Web.Configuration.AuthConfig
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc (http://www.ximian.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;
  31. using System.Configuration;
  32. using System.Xml;
  33. namespace System.Web.Configuration
  34. {
  35. class AuthConfig
  36. {
  37. AuthenticationMode mode;
  38. string cookieName;
  39. string cookiePath;
  40. string loginUrl;
  41. FormsProtectionEnum protection;
  42. int timeout;
  43. FormsAuthPasswordFormat pwdFormat;
  44. Hashtable credentialUsers;
  45. bool has_parent;
  46. #if NET_1_1
  47. bool requireSSL;
  48. bool slidingExpiration;
  49. #endif
  50. internal AuthConfig (object parent)
  51. {
  52. if (parent is AuthConfig) {
  53. has_parent = true;
  54. AuthConfig p = (AuthConfig) parent;
  55. mode = p.mode;
  56. cookieName = p.cookieName;
  57. cookiePath = p.cookiePath;
  58. loginUrl = p.loginUrl;
  59. protection = p.protection;
  60. timeout = p.timeout;
  61. pwdFormat = p.pwdFormat;
  62. #if NET_1_1
  63. requireSSL = p.requireSSL;
  64. slidingExpiration = p.slidingExpiration;
  65. #endif
  66. credentialUsers = new Hashtable (p.CredentialUsers);
  67. }
  68. }
  69. internal void SetMode (string m)
  70. {
  71. if (m == null) {
  72. // we default to Forms authentication mode, MS defaults to Windows
  73. if (!has_parent)
  74. Mode = AuthenticationMode.Forms;
  75. return;
  76. }
  77. Mode = (AuthenticationMode) Enum.Parse (typeof (AuthenticationMode), m, true);
  78. }
  79. internal void SetProtection (string prot)
  80. {
  81. if (prot == null) {
  82. if (!has_parent)
  83. Protection = FormsProtectionEnum.All;
  84. return;
  85. }
  86. Protection = (FormsProtectionEnum) Enum.Parse (typeof (FormsProtectionEnum),
  87. prot,
  88. true);
  89. }
  90. internal void SetTimeout (string minutes)
  91. {
  92. if (minutes != null) {
  93. Timeout = Int32.Parse (minutes);
  94. return;
  95. }
  96. if (!has_parent)
  97. Timeout = 30;
  98. }
  99. internal void SetPasswordFormat (string pwdFormat)
  100. {
  101. if (pwdFormat == null) {
  102. if (!has_parent)
  103. PasswordFormat = FormsAuthPasswordFormat.Clear;
  104. return;
  105. }
  106. PasswordFormat =
  107. (FormsAuthPasswordFormat) Enum.Parse (typeof (FormsAuthPasswordFormat),
  108. pwdFormat,
  109. true);
  110. }
  111. internal AuthenticationMode Mode {
  112. get { return mode; }
  113. set { mode = value; }
  114. }
  115. internal string CookieName {
  116. get {
  117. if (cookieName == null)
  118. cookieName = ".ASPXAUTH";
  119. return cookieName;
  120. }
  121. set {
  122. if (value == null)
  123. return;
  124. cookieName = value;
  125. }
  126. }
  127. internal string CookiePath {
  128. get {
  129. if (cookiePath == null)
  130. cookiePath = "/";
  131. return cookiePath;
  132. }
  133. set {
  134. if (value == null)
  135. return;
  136. cookiePath = value;
  137. }
  138. }
  139. internal string LoginUrl {
  140. get {
  141. if (loginUrl == null)
  142. loginUrl = "login.aspx";
  143. return loginUrl;
  144. }
  145. set {
  146. if (value == null)
  147. return;
  148. loginUrl = value;
  149. }
  150. }
  151. internal FormsProtectionEnum Protection {
  152. get { return protection; }
  153. set { protection = value; }
  154. }
  155. internal int Timeout {
  156. get { return timeout; }
  157. set {
  158. if (value <= 0)
  159. throw new ArgumentException ("Timeout must be > 0", "value");
  160. timeout = value;
  161. }
  162. }
  163. internal FormsAuthPasswordFormat PasswordFormat {
  164. get { return pwdFormat; }
  165. set { pwdFormat = value; }
  166. }
  167. internal Hashtable CredentialUsers {
  168. get {
  169. if (credentialUsers == null)
  170. credentialUsers = new Hashtable ();
  171. return credentialUsers;
  172. }
  173. }
  174. #if NET_1_1
  175. internal bool RequireSSL {
  176. get { return requireSSL; }
  177. set { requireSSL = value; }
  178. }
  179. internal bool SlidingExpiration {
  180. get { return slidingExpiration; }
  181. set { slidingExpiration = value; }
  182. }
  183. #endif
  184. }
  185. }