AuthConfig.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. internal AuthConfig (object parent)
  27. {
  28. if (parent is AuthConfig) {
  29. has_parent = true;
  30. AuthConfig p = (AuthConfig) parent;
  31. mode = p.mode;
  32. cookieName = p.cookieName;
  33. cookiePath = p.cookiePath;
  34. loginUrl = p.loginUrl;
  35. protection = p.protection;
  36. timeout = p.timeout;
  37. pwdFormat = p.pwdFormat;
  38. credentialUsers = new Hashtable (p.CredentialUsers);
  39. }
  40. }
  41. internal void SetMode (string m)
  42. {
  43. if (m == null) {
  44. // we default to Forms authentication mode, MS defaults to Windows
  45. if (!has_parent)
  46. Mode = AuthenticationMode.Forms;
  47. return;
  48. }
  49. Mode = (AuthenticationMode) Enum.Parse (typeof (AuthenticationMode), m, true);
  50. }
  51. internal void SetProtection (string prot)
  52. {
  53. if (prot == null) {
  54. if (!has_parent)
  55. Protection = FormsProtectionEnum.All;
  56. return;
  57. }
  58. Protection = (FormsProtectionEnum) Enum.Parse (typeof (FormsProtectionEnum),
  59. prot,
  60. true);
  61. }
  62. internal void SetTimeout (string minutes)
  63. {
  64. if (minutes != null) {
  65. Timeout = Int32.Parse (minutes);
  66. return;
  67. }
  68. if (!has_parent)
  69. Timeout = 30;
  70. }
  71. internal void SetPasswordFormat (string pwdFormat)
  72. {
  73. if (pwdFormat == null) {
  74. if (!has_parent)
  75. PasswordFormat = FormsAuthPasswordFormat.Clear;
  76. return;
  77. }
  78. PasswordFormat =
  79. (FormsAuthPasswordFormat) Enum.Parse (typeof (FormsAuthPasswordFormat),
  80. pwdFormat,
  81. true);
  82. }
  83. internal AuthenticationMode Mode {
  84. get { return mode; }
  85. set { mode = value; }
  86. }
  87. internal string CookieName {
  88. get {
  89. if (cookieName == null)
  90. cookieName = ".ASPXAUTH";
  91. return cookieName;
  92. }
  93. set {
  94. if (value == null)
  95. return;
  96. cookieName = value;
  97. }
  98. }
  99. internal string CookiePath {
  100. get {
  101. if (cookiePath == null)
  102. cookiePath = "/";
  103. return cookiePath;
  104. }
  105. set {
  106. if (value == null)
  107. return;
  108. cookiePath = value;
  109. }
  110. }
  111. internal string LoginUrl {
  112. get {
  113. if (loginUrl == null)
  114. loginUrl = "login.aspx";
  115. return loginUrl;
  116. }
  117. set {
  118. if (value == null)
  119. return;
  120. loginUrl = value;
  121. }
  122. }
  123. internal FormsProtectionEnum Protection {
  124. get { return protection; }
  125. set { protection = value; }
  126. }
  127. internal int Timeout {
  128. get { return timeout; }
  129. set {
  130. if (value <= 0)
  131. throw new ArgumentException ("Timeout must be > 0", "value");
  132. timeout = value;
  133. }
  134. }
  135. internal FormsAuthPasswordFormat PasswordFormat {
  136. get { return pwdFormat; }
  137. set { pwdFormat = value; }
  138. }
  139. internal Hashtable CredentialUsers {
  140. get {
  141. if (credentialUsers == null)
  142. credentialUsers = new Hashtable ();
  143. return credentialUsers;
  144. }
  145. }
  146. }
  147. }