AuthConfig.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. using System;
  10. using System.Collections;
  11. using System.Configuration;
  12. using System.Xml;
  13. namespace System.Web.Configuration
  14. {
  15. class AuthConfig
  16. {
  17. AuthenticationMode mode;
  18. string cookieName;
  19. string cookiePath;
  20. string loginUrl;
  21. FormsProtectionEnum protection;
  22. int timeout;
  23. FormsAuthPasswordFormat pwdFormat;
  24. Hashtable credentialUsers;
  25. bool has_parent;
  26. #if NET_1_1
  27. bool requireSSL;
  28. bool slidingExpiration;
  29. #endif
  30. internal AuthConfig (object parent)
  31. {
  32. if (parent is AuthConfig) {
  33. has_parent = true;
  34. AuthConfig p = (AuthConfig) parent;
  35. mode = p.mode;
  36. cookieName = p.cookieName;
  37. cookiePath = p.cookiePath;
  38. loginUrl = p.loginUrl;
  39. protection = p.protection;
  40. timeout = p.timeout;
  41. pwdFormat = p.pwdFormat;
  42. #if NET_1_1
  43. requireSSL = p.requireSSL;
  44. slidingExpiration = p.slidingExpiration;
  45. #endif
  46. credentialUsers = new Hashtable (p.CredentialUsers);
  47. }
  48. }
  49. internal void SetMode (string m)
  50. {
  51. if (m == null) {
  52. // we default to Forms authentication mode, MS defaults to Windows
  53. if (!has_parent)
  54. Mode = AuthenticationMode.Forms;
  55. return;
  56. }
  57. Mode = (AuthenticationMode) Enum.Parse (typeof (AuthenticationMode), m, true);
  58. }
  59. internal void SetProtection (string prot)
  60. {
  61. if (prot == null) {
  62. if (!has_parent)
  63. Protection = FormsProtectionEnum.All;
  64. return;
  65. }
  66. Protection = (FormsProtectionEnum) Enum.Parse (typeof (FormsProtectionEnum),
  67. prot,
  68. true);
  69. }
  70. internal void SetTimeout (string minutes)
  71. {
  72. if (minutes != null) {
  73. Timeout = Int32.Parse (minutes);
  74. return;
  75. }
  76. if (!has_parent)
  77. Timeout = 30;
  78. }
  79. internal void SetPasswordFormat (string pwdFormat)
  80. {
  81. if (pwdFormat == null) {
  82. if (!has_parent)
  83. PasswordFormat = FormsAuthPasswordFormat.Clear;
  84. return;
  85. }
  86. PasswordFormat =
  87. (FormsAuthPasswordFormat) Enum.Parse (typeof (FormsAuthPasswordFormat),
  88. pwdFormat,
  89. true);
  90. }
  91. internal AuthenticationMode Mode {
  92. get { return mode; }
  93. set { mode = value; }
  94. }
  95. internal string CookieName {
  96. get {
  97. if (cookieName == null)
  98. cookieName = ".ASPXAUTH";
  99. return cookieName;
  100. }
  101. set {
  102. if (value == null)
  103. return;
  104. cookieName = value;
  105. }
  106. }
  107. internal string CookiePath {
  108. get {
  109. if (cookiePath == null)
  110. cookiePath = "/";
  111. return cookiePath;
  112. }
  113. set {
  114. if (value == null)
  115. return;
  116. cookiePath = value;
  117. }
  118. }
  119. internal string LoginUrl {
  120. get {
  121. if (loginUrl == null)
  122. loginUrl = "login.aspx";
  123. return loginUrl;
  124. }
  125. set {
  126. if (value == null)
  127. return;
  128. loginUrl = value;
  129. }
  130. }
  131. internal FormsProtectionEnum Protection {
  132. get { return protection; }
  133. set { protection = value; }
  134. }
  135. internal int Timeout {
  136. get { return timeout; }
  137. set {
  138. if (value <= 0)
  139. throw new ArgumentException ("Timeout must be > 0", "value");
  140. timeout = value;
  141. }
  142. }
  143. internal FormsAuthPasswordFormat PasswordFormat {
  144. get { return pwdFormat; }
  145. set { pwdFormat = value; }
  146. }
  147. internal Hashtable CredentialUsers {
  148. get {
  149. if (credentialUsers == null)
  150. credentialUsers = new Hashtable ();
  151. return credentialUsers;
  152. }
  153. }
  154. #if NET_1_1
  155. internal bool RequireSSL {
  156. get { return requireSSL; }
  157. set { requireSSL = value; }
  158. }
  159. internal bool SlidingExpiration {
  160. get { return slidingExpiration; }
  161. set { slidingExpiration = value; }
  162. }
  163. #endif
  164. }
  165. }