File: RoleManagerSection.cs

package info (click to toggle)
mono 6.12.0.199%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,296,836 kB
  • sloc: cs: 11,181,803; xml: 2,850,076; ansic: 699,709; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,853; makefile: 20,405; sh: 15,009; python: 4,839; pascal: 925; sql: 859; sed: 16; php: 1
file content (338 lines) | stat: -rw-r--r-- 16,000 bytes parent folder | download | duplicates (7)
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
//------------------------------------------------------------------------------
// <copyright file="RoleManagerSection.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

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.ComponentModel;
    using System.Web.Security; // for CookieProtection Enum
    using System.Security.Permissions;

    /*         <!-- Configuration for roleManager:
                enabled="[true|false]"                            Feature is enabled?
                cacheRolesInCookie="[true|false]"                 Cache roles in cookie?
                cookieName=".ASPXROLES"                           Cookie Name
                createPersistentCookie="[true|false]"             Creates a persistent cookie or session cookie?
                cookieTimeout="30"                                Cookie Timeout
                cookiePath="/"                                    Cookie Path
                cookieRequireSSL="[true|false]"                   Set Secure bit in Cookie
                cookieSlidingExpiration="[true|false]"          Reissue expiring cookies?
                cookieProtection="[None|Validation|Encryption|All]"    How to protect cookies from being read/tampered
                defaultProvider="string"                          Name of provider to use by default
                domain="[domain]"                                 Enables output of the "domain" cookie attribute set to the specified value
                maxCachedResults="int"                            Maximum number of roles to cache in cookie
               Child nodes:
                <providers>              Providers (class must inherit from RoleProvider)

                    <add                 Add a provider
                        name="string"    Name to identify this provider instance by
                        type="string"   Class that implements RoleProvider
                        provider-specific-configuration />

                    <remove              Remove a provider
                        name="string" /> Name of provider to remove
                    <clear/>             Remove all providers
                </providers>


                <providers> type="TypeName"                        Class that inherits from System.Web.Security.RoleProvider
                    providerSpecificConfig                        Config for the provider


           Configuration for SqlRoleProvider and AccessRoleProvider:
                   connectionStringName="string"  Name corresponding to the entry in <connectionStrings> section where the connection string for the provider is specified
                   description="string"           Description of what the provider does
                   commandTimeout="int"           Command timeout value for SQL command

           Configuration for AuthorizationStoreProvider:
                   connectionStringName="string"  Name corresponding to the entry in <connectionStrings> section where the connection string for the provider is specified
                   description="string"           Description of what the provider does
                   cacheRefreshInterval="int"     The number of minutes between forced refreshes of the cached policy store data

           Configuration for WindowsTokenRoleProvider:
                 description="string"           Description of what the provider does
        -->


        <roleManager
                enabled="false" cacheRolesInCookie="false" cookieName=".ASPXROLES" cookieTimeout="30"
                cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" createPersistentCookie="false"
                cookieProtection="All" defaultProvider="AspNetSqlRoleProvider" domain=""  >
           <providers>
               <add  name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=%ASSEMBLY_VERSION%, Culture=neutral, PublicKeyToken=%MICROSOFT_PUBLICKEY%"
                     connectionStringName="LocalSqlServer"
                     applicationName="/"
                     description="Stores and retrieves roles data from the local Microsoft SQL Server database" />

               <add name="AspNetWindowsTokenRoleProvider"
                    type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=%ASSEMBLY_VERSION%, Culture=neutral, PublicKeyToken=%MICROSOFT_PUBLICKEY%"
                    description="Retrieves roles data from the Windows authenticated token for the request" />


                <add name="AspNetAuthorizationStoreRoleProvider"
                    type="System.Web.Security.AuthorizationRoleProvider, System.Web, Version=%ASSEMBLY_VERSION%, Culture=neutral, PublicKeyToken=%MICROSOFT_PUBLICKEY%"
                    connectionStringName="AuthorizationStore"
                    cacheRefreshInterval="60"
                    applicationName="MyApplication"
                    scopeName="MyScope"
                    description="Stores and retrieves roles data from the authorization store" />
           </providers>

        </roleManager>
 */
    public sealed class RoleManagerSection : ConfigurationSection {
        private static ConfigurationPropertyCollection _properties;
        private static readonly ConfigurationProperty _propEnabled =
            new ConfigurationProperty("enabled",
                                        typeof(bool),
                                        false,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propUseCookies =
            new ConfigurationProperty("cacheRolesInCookie",
                                        typeof(bool),
                                        false,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCookieName =
            new ConfigurationProperty("cookieName",
                                        typeof(string),
                                        ".ASPXROLES",
                                        StdValidatorsAndConverters.WhiteSpaceTrimStringConverter,
                                        StdValidatorsAndConverters.NonEmptyStringValidator,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCookieTimeout =
            new ConfigurationProperty("cookieTimeout",
                                        typeof(TimeSpan),
                                        TimeSpan.FromMinutes(30.0),
                                        StdValidatorsAndConverters.TimeSpanMinutesOrInfiniteConverter,
                                        StdValidatorsAndConverters.PositiveTimeSpanValidator,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCookiePath =
            new ConfigurationProperty("cookiePath",
                                        typeof(string),
                                        "/",
                                        StdValidatorsAndConverters.WhiteSpaceTrimStringConverter,
                                        StdValidatorsAndConverters.NonEmptyStringValidator,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCookieRequireSSL =
            new ConfigurationProperty("cookieRequireSSL",
                                        typeof(bool),
                                        false,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCookieSlidingExpiration =
            new ConfigurationProperty("cookieSlidingExpiration",
                                        typeof(bool),
                                        true,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCookieProtection =
            new ConfigurationProperty("cookieProtection",
                                        typeof(CookieProtection),
                                        CookieProtection.All,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propDefaultProvider =
            new ConfigurationProperty("defaultProvider",
                                        typeof(string),
                                        "AspNetSqlRoleProvider",
                                        null,
                                        StdValidatorsAndConverters.NonEmptyStringValidator,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propProviders =
            new ConfigurationProperty("providers",
                                        typeof(ProviderSettingsCollection),
                                        null,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCreatePersistentCookie =
            new ConfigurationProperty("createPersistentCookie",
                                        typeof(bool),
                                        false,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propDomain =
            new ConfigurationProperty("domain",
                                        typeof(string),
                                        null,
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propMaxCachedResults =
            new ConfigurationProperty("maxCachedResults",
                                        typeof(int),
                                        25,
                                        ConfigurationPropertyOptions.None);

        private enum InheritedType {
            inNeither = 0,
            inParent = 1,
            inSelf = 2,
            inBothSame = 3,
            inBothDiff = 4,
        }

        static RoleManagerSection() {
            // Property initialization
            _properties = new ConfigurationPropertyCollection();
            _properties.Add(_propEnabled);
            _properties.Add(_propUseCookies);
            _properties.Add(_propCookieName);
            _properties.Add(_propCookieTimeout);
            _properties.Add(_propCookiePath);
            _properties.Add(_propCookieRequireSSL);
            _properties.Add(_propCookieSlidingExpiration);
            _properties.Add(_propCookieProtection);
            _properties.Add(_propDefaultProvider);
            _properties.Add(_propProviders);
            _properties.Add(_propCreatePersistentCookie);
            _properties.Add(_propDomain);
            _properties.Add(_propMaxCachedResults);
        }

        public RoleManagerSection() {
        }

        protected override ConfigurationPropertyCollection Properties {
            get {
                return _properties;
            }
        }

        [ConfigurationProperty("enabled", DefaultValue = false)]
        public bool Enabled {
            get {
                return (bool)base[_propEnabled];
            }
            set {
                base[_propEnabled] = value;
            }
        }

        [ConfigurationProperty("createPersistentCookie", DefaultValue = false)]
        public bool CreatePersistentCookie {
            get {
                return (bool)base[_propCreatePersistentCookie];
            }
            set {
                base[_propCreatePersistentCookie] = value;
            }
        }

        [ConfigurationProperty("cacheRolesInCookie", DefaultValue = false)]
        public bool CacheRolesInCookie {
            get {
                return (bool)base[_propUseCookies];
            }
            set {
                base[_propUseCookies] = value;
            }
        }

        [ConfigurationProperty("cookieName", DefaultValue = ".ASPXROLES")]
        [TypeConverter(typeof(WhiteSpaceTrimStringConverter))]
        [StringValidator(MinLength = 1)]
        public string CookieName {
            get {
                return (string)base[_propCookieName];
            }
            set {
                base[_propCookieName] = value;
            }
        }

        [ConfigurationProperty("cookieTimeout", DefaultValue = "00:30:00")]
        [TypeConverter(typeof(TimeSpanMinutesOrInfiniteConverter))]
        [TimeSpanValidator(MinValueString="00:00:00", MaxValueString=TimeSpanValidatorAttribute.TimeSpanMaxValue)]
        public TimeSpan CookieTimeout {
            get {
                return (TimeSpan)base[_propCookieTimeout];
            }
            set {
                base[_propCookieTimeout] = value;
            }
        }

        [ConfigurationProperty("cookiePath", DefaultValue = "/")]
        [TypeConverter(typeof(WhiteSpaceTrimStringConverter))]
        [StringValidator(MinLength = 1)]
        public string CookiePath {
            get {
                return (string)base[_propCookiePath];
            }
            set {
                base[_propCookiePath] = value;
            }
        }

        [ConfigurationProperty("cookieRequireSSL", DefaultValue = false)]
        public bool CookieRequireSSL {
            get {
                return (bool)base[_propCookieRequireSSL];
            }
            set {
                base[_propCookieRequireSSL] = value;
            }
        }

        [ConfigurationProperty("cookieSlidingExpiration", DefaultValue = true)]
        public bool CookieSlidingExpiration {
            get {
                return (bool)base[_propCookieSlidingExpiration];
            }
            set {
                base[_propCookieSlidingExpiration] = value;
            }
        }

        [ConfigurationProperty("cookieProtection", DefaultValue = CookieProtection.All)]
        public CookieProtection CookieProtection {
            get {
                return (CookieProtection)base[_propCookieProtection];
            }
            set {
                base[_propCookieProtection] = value;
            }
        }

        [ConfigurationProperty("defaultProvider", DefaultValue = "AspNetSqlRoleProvider")]
        [TypeConverter(typeof(WhiteSpaceTrimStringConverter))]
        [StringValidator(MinLength = 1)]
        public string DefaultProvider {
            get {
                return (string)base[_propDefaultProvider];
            }
            set                     {
                        base[_propDefaultProvider] = value;
                    }
                }

                [ConfigurationProperty("providers")]
                public ProviderSettingsCollection Providers                 {
                    get                     {
                        return (ProviderSettingsCollection)base[_propProviders];
            }
        }

        [ConfigurationProperty("domain")]
        public string Domain {
            get {
                return (string)base[_propDomain];
            }
            set {
                base[_propDomain] = value;
            }
        }

        [ConfigurationProperty("maxCachedResults", DefaultValue = 25)]
        public int MaxCachedResults {
            get {
                return (int)base[_propMaxCachedResults];
            }
            set {
                base[_propMaxCachedResults] = value;
            }
        }
    } // class RoleManagerSection
}