1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
|
//------------------------------------------------------------------------------
// <copyright file="FormsAuthenticationConfiguration.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*****************************************************************************
From machine.config
<!--
authentication Attributes:
mode="[Windows|Forms|Passport|None]"
-->
<authentication mode="Windows">
<!--
forms Attributes:
name="[cookie name]" - Name of the cookie used for Forms Authentication
loginUrl="[url]" - Url to redirect client to for Authentication
protection="[All|None|Encryption|Validation]" - Protection mode for data in cookie
timeout="[minutes]" - Duration of time for cookie to be valid (reset on each request)
path="/" - Sets the path for the cookie
requireSSL="[true|false]" - Should the forms-authentication cookie be sent only over SSL
slidingExpiration="[true|false]" - Should the forms-authentication-cookie and ticket be re-issued if they are about to expire
defaultUrl="string" - Page to redirect to after login, if none has been specified
cookieless="[UseCookies|UseUri|AutoDetect|UseDeviceProfile]" - Use Cookies or the URL path to store the forms authentication ticket
domain="string" - Domain of the cookie
-->
<forms
name=".ASPXAUTH"
loginUrl="login.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" >
<!--
credentials Attributes:
passwordFormat="[Clear|SHA1|MD5]" - format of user password value stored in <user>
-->
<credentials passwordFormat="SHA1">
<!-- <user name="UserName" password="password" /> -->
</credentials>
</forms>
<!--
passport Attributes:
redirectUrl=["url"] - Specifies the page to redirect to, if the page requires authentication, and the user has not signed on with passport
-->
<passport redirectUrl="internal" />
</authentication>
<authentication mode="Windows">
<forms
name=".ASPXAUTH"
loginUrl="login.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" >
<credentials passwordFormat="SHA1">
</credentials>
</forms>
<passport redirectUrl="internal" />
</authentication>
******************************************************************************/
namespace System.Web.Configuration {
using System;
using System.Xml;
using System.Configuration;
using System.Collections.Specialized;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Text;
using System.Web.Util;
using System.ComponentModel;
using System.Security.Permissions;
public sealed class FormsAuthenticationConfiguration : ConfigurationElement {
private static readonly ConfigurationElementProperty s_elemProperty =
new ConfigurationElementProperty(new CallbackValidator(typeof(FormsAuthenticationConfiguration), Validate));
private static ConfigurationPropertyCollection _properties;
private static readonly ConfigurationProperty _propCredentials =
new ConfigurationProperty("credentials",
typeof(FormsAuthenticationCredentials),
null,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propName =
new ConfigurationProperty("name",
typeof(string),
".ASPXAUTH",
null,
StdValidatorsAndConverters.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propLoginUrl =
new ConfigurationProperty("loginUrl",
typeof(string),
"login.aspx",
null,
StdValidatorsAndConverters.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propDefaultUrl =
new ConfigurationProperty("defaultUrl",
typeof(string),
"default.aspx",
null,
StdValidatorsAndConverters.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propProtection =
new ConfigurationProperty("protection",
typeof(FormsProtectionEnum),
FormsProtectionEnum.All,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propTimeout =
new ConfigurationProperty("timeout",
typeof(TimeSpan),
TimeSpan.FromMinutes(30.0),
StdValidatorsAndConverters.TimeSpanMinutesConverter,
new TimeSpanValidator(TimeSpan.FromMinutes(1), TimeSpan.MaxValue),
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propPath =
new ConfigurationProperty("path",
typeof(string),
"/",
null,
StdValidatorsAndConverters.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propRequireSSL =
new ConfigurationProperty("requireSSL",
typeof(bool),
false,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propSlidingExpiration =
new ConfigurationProperty("slidingExpiration",
typeof(bool),
true,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propCookieless =
new ConfigurationProperty("cookieless",
typeof(HttpCookieMode),
HttpCookieMode.UseDeviceProfile,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propDomain =
new ConfigurationProperty("domain",
typeof(string),
null,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propEnableCrossAppRedirects =
new ConfigurationProperty("enableCrossAppRedirects",
typeof(bool),
false,
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propTicketCompatibilityMode =
new ConfigurationProperty("ticketCompatibilityMode",
typeof(TicketCompatibilityMode),
TicketCompatibilityMode.Framework20,
ConfigurationPropertyOptions.None);
static FormsAuthenticationConfiguration() {
// Property initialization
_properties = new ConfigurationPropertyCollection();
_properties.Add(_propCredentials);
_properties.Add(_propName);
_properties.Add(_propLoginUrl);
_properties.Add(_propDefaultUrl);
_properties.Add(_propProtection);
_properties.Add(_propTimeout);
_properties.Add(_propPath);
_properties.Add(_propRequireSSL);
_properties.Add(_propSlidingExpiration);
_properties.Add(_propCookieless);
_properties.Add(_propDomain);
_properties.Add(_propEnableCrossAppRedirects);
_properties.Add(_propTicketCompatibilityMode);
}
public FormsAuthenticationConfiguration() {
}
protected override ConfigurationPropertyCollection Properties {
get {
return _properties;
}
}
[ConfigurationProperty("credentials")]
public FormsAuthenticationCredentials Credentials {
get {
return (FormsAuthenticationCredentials)base[_propCredentials];
}
}
[ConfigurationProperty("name", DefaultValue = ".ASPXAUTH")]
[StringValidator(MinLength = 1)]
public string Name {
get {
return (string)base[_propName];
}
set {
if (String.IsNullOrEmpty(value)) {
base[_propName] = _propName.DefaultValue;
}
else {
base[_propName] = value;
}
}
}
[ConfigurationProperty("loginUrl", DefaultValue = "login.aspx")]
[StringValidator(MinLength = 1)]
public string LoginUrl {
get {
return (string)base[_propLoginUrl];
}
set {
if (String.IsNullOrEmpty(value)) {
base[_propLoginUrl] = _propLoginUrl.DefaultValue;
}
else {
base[_propLoginUrl] = value;
}
}
}
[ConfigurationProperty("defaultUrl", DefaultValue = "default.aspx")]
[StringValidator(MinLength = 1)]
public string DefaultUrl {
get {
return (string)base[_propDefaultUrl];
}
set {
if (String.IsNullOrEmpty(value)) {
base[_propDefaultUrl] = _propDefaultUrl.DefaultValue;
}
else {
base[_propDefaultUrl] = value;
}
}
}
[ConfigurationProperty("protection", DefaultValue = FormsProtectionEnum.All)]
public FormsProtectionEnum Protection {
get {
return (FormsProtectionEnum)base[_propProtection];
}
set {
base[_propProtection] = value;
}
}
[ConfigurationProperty("timeout", DefaultValue = "00:30:00")]
[TimeSpanValidator(MinValueString="00:01:00", MaxValueString=TimeSpanValidatorAttribute.TimeSpanMaxValue)]
[TypeConverter(typeof(TimeSpanMinutesConverter))]
public TimeSpan Timeout {
get {
return (TimeSpan)base[_propTimeout];
}
set {
base[_propTimeout] = value;
}
}
[ConfigurationProperty("path", DefaultValue = "/")]
[StringValidator(MinLength = 1)]
public string Path {
get {
return (string)base[_propPath];
}
set {
if (String.IsNullOrEmpty(value)) {
base[_propPath] = _propPath.DefaultValue;
}
else {
base[_propPath] = value;
}
}
}
[ConfigurationProperty("requireSSL", DefaultValue = false)]
public bool RequireSSL {
get {
return (bool)base[_propRequireSSL];
}
set {
base[_propRequireSSL] = value;
}
}
[ConfigurationProperty("slidingExpiration", DefaultValue = true)]
public bool SlidingExpiration {
get {
return (bool)base[_propSlidingExpiration];
}
set {
base[_propSlidingExpiration] = value;
}
}
[ConfigurationProperty("enableCrossAppRedirects", DefaultValue = false)]
public bool EnableCrossAppRedirects {
get {
return (bool)base[_propEnableCrossAppRedirects];
}
set {
base[_propEnableCrossAppRedirects] = value;
}
}
[ConfigurationProperty("cookieless", DefaultValue = HttpCookieMode.UseDeviceProfile)]
public HttpCookieMode Cookieless {
get {
return (HttpCookieMode)base[_propCookieless];
}
set {
base[_propCookieless] = value;
}
}
[ConfigurationProperty("domain", DefaultValue = "")]
public string Domain {
get {
return (string)base[_propDomain];
}
set {
base[_propDomain] = value;
}
}
[ConfigurationProperty("ticketCompatibilityMode", DefaultValue = TicketCompatibilityMode.Framework20)]
public TicketCompatibilityMode TicketCompatibilityMode {
get {
return (TicketCompatibilityMode)base[_propTicketCompatibilityMode];
}
set {
base[_propTicketCompatibilityMode] = value;
}
}
protected override ConfigurationElementProperty ElementProperty {
get {
return s_elemProperty;
}
}
private static void Validate(object value) {
if (value == null) {
throw new ArgumentNullException("forms");
}
FormsAuthenticationConfiguration elem = (FormsAuthenticationConfiguration)value;
if (StringUtil.StringStartsWith(elem.LoginUrl, "\\\\") ||
(elem.LoginUrl.Length > 1 && elem.LoginUrl[1] == ':')) {
throw new ConfigurationErrorsException(SR.GetString(SR.Auth_bad_url),
elem.ElementInformation.Properties["loginUrl"].Source,
elem.ElementInformation.Properties["loginUrl"].LineNumber);
}
if (StringUtil.StringStartsWith(elem.DefaultUrl, "\\\\") ||
(elem.DefaultUrl.Length > 1 && elem.DefaultUrl[1] == ':')) {
throw new ConfigurationErrorsException(SR.GetString(SR.Auth_bad_url),
elem.ElementInformation.Properties["defaultUrl"].Source,
elem.ElementInformation.Properties["defaultUrl"].LineNumber);
}
}
} // class FormsAuthenticationConfiguration
}
|