2
0

AuthConfig.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. // Copyright (c) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  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. #if NET_2_0
  51. string cookie_domain;
  52. HttpCookieMode cookie_mode;
  53. bool cookies_supported;
  54. string default_url;
  55. bool enable_crossapp_redirects;
  56. #endif
  57. internal AuthConfig (object parent)
  58. {
  59. if (parent is AuthConfig) {
  60. has_parent = true;
  61. AuthConfig p = (AuthConfig) parent;
  62. mode = p.mode;
  63. cookieName = p.cookieName;
  64. cookiePath = p.cookiePath;
  65. loginUrl = p.loginUrl;
  66. protection = p.protection;
  67. timeout = p.timeout;
  68. pwdFormat = p.pwdFormat;
  69. #if NET_1_1
  70. requireSSL = p.requireSSL;
  71. slidingExpiration = p.slidingExpiration;
  72. #endif
  73. #if NET_2_0
  74. cookie_domain = p.cookie_domain;
  75. cookie_mode = p.cookie_mode;
  76. cookies_supported = p.cookies_supported;
  77. default_url = p.default_url;
  78. enable_crossapp_redirects = p.enable_crossapp_redirects;
  79. #endif
  80. credentialUsers = new Hashtable (p.CredentialUsers);
  81. }
  82. }
  83. internal void SetMode (string m)
  84. {
  85. if (m == null) {
  86. // we default to Forms authentication mode, MS defaults to Windows
  87. if (!has_parent)
  88. Mode = AuthenticationMode.Forms;
  89. return;
  90. }
  91. Mode = (AuthenticationMode) Enum.Parse (typeof (AuthenticationMode), m, true);
  92. }
  93. internal void SetProtection (string prot)
  94. {
  95. if (prot == null) {
  96. if (!has_parent)
  97. Protection = FormsProtectionEnum.All;
  98. return;
  99. }
  100. Protection = (FormsProtectionEnum) Enum.Parse (typeof (FormsProtectionEnum),
  101. prot,
  102. true);
  103. }
  104. internal void SetTimeout (string minutes)
  105. {
  106. if (minutes != null) {
  107. Timeout = Int32.Parse (minutes);
  108. return;
  109. }
  110. if (!has_parent)
  111. Timeout = 30;
  112. }
  113. internal void SetPasswordFormat (string pwdFormat)
  114. {
  115. if (pwdFormat == null) {
  116. if (!has_parent)
  117. PasswordFormat = FormsAuthPasswordFormat.Clear;
  118. return;
  119. }
  120. PasswordFormat =
  121. (FormsAuthPasswordFormat) Enum.Parse (typeof (FormsAuthPasswordFormat),
  122. pwdFormat,
  123. true);
  124. }
  125. internal AuthenticationMode Mode {
  126. get { return mode; }
  127. set { mode = value; }
  128. }
  129. internal string CookieName {
  130. get {
  131. if (cookieName == null)
  132. cookieName = ".ASPXAUTH";
  133. return cookieName;
  134. }
  135. set {
  136. if (value == null)
  137. return;
  138. cookieName = value;
  139. }
  140. }
  141. internal string CookiePath {
  142. get {
  143. if (cookiePath == null)
  144. cookiePath = "/";
  145. return cookiePath;
  146. }
  147. set {
  148. if (value == null)
  149. return;
  150. cookiePath = value;
  151. }
  152. }
  153. internal string LoginUrl {
  154. get {
  155. if (loginUrl == null)
  156. loginUrl = "login.aspx";
  157. return loginUrl;
  158. }
  159. set {
  160. if (value == null)
  161. return;
  162. loginUrl = value;
  163. }
  164. }
  165. internal FormsProtectionEnum Protection {
  166. get { return protection; }
  167. set { protection = value; }
  168. }
  169. internal int Timeout {
  170. get { return timeout; }
  171. set {
  172. if (value <= 0)
  173. throw new ArgumentException ("Timeout must be > 0", "value");
  174. timeout = value;
  175. }
  176. }
  177. internal FormsAuthPasswordFormat PasswordFormat {
  178. get { return pwdFormat; }
  179. set { pwdFormat = value; }
  180. }
  181. internal Hashtable CredentialUsers {
  182. get {
  183. if (credentialUsers == null)
  184. credentialUsers = new Hashtable ();
  185. return credentialUsers;
  186. }
  187. }
  188. #if NET_1_1
  189. internal bool RequireSSL {
  190. get { return requireSSL; }
  191. set { requireSSL = value; }
  192. }
  193. internal bool SlidingExpiration {
  194. get { return slidingExpiration; }
  195. set { slidingExpiration = value; }
  196. }
  197. #endif
  198. #if NET_2_0
  199. internal string CookieDomain {
  200. get { return cookie_domain; }
  201. set { cookie_domain = value; }
  202. }
  203. internal HttpCookieMode CookieMode {
  204. get { return cookie_mode; }
  205. set { cookie_mode = value; }
  206. }
  207. internal bool CookiesSupported {
  208. get { return cookies_supported; }
  209. set { cookies_supported = value; }
  210. }
  211. internal string DefaultUrl {
  212. get { return default_url; }
  213. set { default_url = value; }
  214. }
  215. internal bool EnableCrossAppRedirects {
  216. get { return enable_crossapp_redirects; }
  217. set { enable_crossapp_redirects = value; }
  218. }
  219. #endif
  220. }
  221. }