merge -r 98047:98048
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / MachineKeySection.cs
1 //
2 // System.Web.Configuration.MachineKeySection
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (c) Copyright 2005 Novell, Inc (http://www.novell.com)
8 //
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
31 using System;
32 using System.ComponentModel;
33 using System.Configuration;
34 using System.Security.Cryptography;
35
36 #if NET_2_0
37
38 namespace System.Web.Configuration {
39
40         public sealed class MachineKeySection : ConfigurationSection
41         {
42                 static ConfigurationProperty decryptionProp;
43                 static ConfigurationProperty decryptionKeyProp;
44                 static ConfigurationProperty validationProp;
45                 static ConfigurationProperty validationKeyProp;
46                 static ConfigurationPropertyCollection properties;
47
48                 static MachineKeySection ()
49                 {
50                         decryptionProp = new ConfigurationProperty ("decryption", typeof (string), "Auto",
51                                                                     PropertyHelper.WhiteSpaceTrimStringConverter,
52                                                                     PropertyHelper.NonEmptyStringValidator,
53                                                                     ConfigurationPropertyOptions.None);
54                         decryptionKeyProp = new ConfigurationProperty ("decryptionKey", typeof (string), "AutoGenerate,IsolateApps",
55                                                                        PropertyHelper.WhiteSpaceTrimStringConverter,
56                                                                        PropertyHelper.NonEmptyStringValidator,
57                                                                        ConfigurationPropertyOptions.None);
58                         validationProp = new ConfigurationProperty ("validation", typeof (MachineKeyValidation), MachineKeyValidation.SHA1,
59                                                                     new MachineKeyValidationConverter (),
60                                                                     PropertyHelper.DefaultValidator,
61                                                                     ConfigurationPropertyOptions.None);
62                         validationKeyProp = new ConfigurationProperty ("validationKey", typeof (string), "AutoGenerate,IsolateApps",
63                                                                        PropertyHelper.WhiteSpaceTrimStringConverter,
64                                                                        PropertyHelper.NonEmptyStringValidator,
65                                                                        ConfigurationPropertyOptions.None);
66
67                         properties = new ConfigurationPropertyCollection ();
68
69                         properties.Add (decryptionProp);
70                         properties.Add (decryptionKeyProp);
71                         properties.Add (validationProp);
72                         properties.Add (validationKeyProp);
73
74                         MachineKeySectionUtils.AutoGenKeys ();
75                 }
76
77                 protected override void Reset (ConfigurationElement parentElement)
78                 {
79                         base.Reset (parentElement);
80                 }
81
82                 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
83                 [StringValidator (MinLength = 1)]
84                 [ConfigurationProperty ("decryption", DefaultValue = "Auto")]
85                 public string Decryption {
86                         get { return (string) base [decryptionProp];}
87                         set { base[decryptionProp] = value; }
88                 }
89
90                 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
91                 [StringValidator (MinLength = 1)]
92                 [ConfigurationProperty ("decryptionKey", DefaultValue = "AutoGenerate,IsolateApps")]
93                 public string DecryptionKey {
94                         get { return (string) base [decryptionKeyProp];}
95                         set {
96                                 base[decryptionKeyProp] = value;
97                                 MachineKeySectionUtils.SetDecryptionKey (value);
98                         }
99                 }
100
101                 [TypeConverter (typeof (MachineKeyValidationConverter))]
102                 [ConfigurationProperty ("validation", DefaultValue = "SHA1")]
103                 public MachineKeyValidation Validation {
104                         get { return (MachineKeyValidation) base [validationProp];}
105                         set { base[validationProp] = value; }
106                 }
107
108                 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
109                 [StringValidator (MinLength = 1)]
110                 [ConfigurationProperty ("validationKey", DefaultValue = "AutoGenerate,IsolateApps")]
111                 public string ValidationKey {
112                         get { return (string) base [validationKeyProp];}
113                         set {
114                                 base[validationKeyProp] = value;
115                                 MachineKeySectionUtils.SetValidationKey (value);
116                         }
117                 }
118
119                 protected override ConfigurationPropertyCollection Properties {
120                         get { return properties; }
121                 }
122         }
123 }
124
125 #endif