File: FederatedMessageSecurityOverHttpElement.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (223 lines) | stat: -rw-r--r-- 8,829 bytes parent folder | download | duplicates (8)
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
//
// FederatedMessageSecurityOverHttpElement.cs
//
// Author:
//	Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc.  http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.MsmqIntegration;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel.Security;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;

namespace System.ServiceModel.Configuration
{
	[MonoTODO]
	public sealed partial class FederatedMessageSecurityOverHttpElement
		 : ConfigurationElement
	{
		// Static Fields
		static ConfigurationPropertyCollection properties;
		static ConfigurationProperty algorithm_suite;
		static ConfigurationProperty claim_type_requirements;
		static ConfigurationProperty establish_security_context;
		static ConfigurationProperty issued_key_type;
		static ConfigurationProperty issued_token_type;
		static ConfigurationProperty issuer;
		static ConfigurationProperty issuer_metadata;
		static ConfigurationProperty negotiate_service_credential;
		static ConfigurationProperty token_request_parameters;

		static FederatedMessageSecurityOverHttpElement ()
		{
			properties = new ConfigurationPropertyCollection ();
			algorithm_suite = new ConfigurationProperty ("algorithmSuite",
				typeof (SecurityAlgorithmSuite), "Default", new SecurityAlgorithmSuiteConverter (), null,
				ConfigurationPropertyOptions.None);

			claim_type_requirements = new ConfigurationProperty ("claimTypeRequirements",
				typeof (ClaimTypeElementCollection), null, null/* FIXME: get converter for ClaimTypeElementCollection*/, null,
				ConfigurationPropertyOptions.None);

			establish_security_context = new ConfigurationProperty ("establishSecurityContext",
				typeof (bool), "true", new BooleanConverter (), null,
				ConfigurationPropertyOptions.None);

			issued_key_type = new ConfigurationProperty ("issuedKeyType",
				typeof (SecurityKeyType), "SymmetricKey", null/* FIXME: get converter for SecurityKeyType*/, null,
				ConfigurationPropertyOptions.None);

			issued_token_type = new ConfigurationProperty ("issuedTokenType",
				typeof (string), "", new StringConverter (), null,
				ConfigurationPropertyOptions.None);

			issuer = new ConfigurationProperty ("issuer",
				typeof (IssuedTokenParametersEndpointAddressElement), null, null/* FIXME: get converter for IssuedTokenParametersEndpointAddressElement*/, null,
				ConfigurationPropertyOptions.None);

			issuer_metadata = new ConfigurationProperty ("issuerMetadata",
				typeof (EndpointAddressElementBase), null, null/* FIXME: get converter for EndpointAddressElementBase*/, null,
				ConfigurationPropertyOptions.None);

			negotiate_service_credential = new ConfigurationProperty ("negotiateServiceCredential",
				typeof (bool), "true", new BooleanConverter (), null,
				ConfigurationPropertyOptions.None);

			token_request_parameters = new ConfigurationProperty ("tokenRequestParameters",
				typeof (XmlElementElementCollection), null, null/* FIXME: get converter for XmlElementElementCollection*/, null,
				ConfigurationPropertyOptions.None);

			properties.Add (algorithm_suite);
			properties.Add (claim_type_requirements);
			properties.Add (establish_security_context);
			properties.Add (issued_key_type);
			properties.Add (issued_token_type);
			properties.Add (issuer);
			properties.Add (issuer_metadata);
			properties.Add (negotiate_service_credential);
			properties.Add (token_request_parameters);
		}

		public FederatedMessageSecurityOverHttpElement ()
		{
		}


		// Properties

		[TypeConverter (typeof (SecurityAlgorithmSuiteConverter))]
		[ConfigurationProperty ("algorithmSuite",
			 Options = ConfigurationPropertyOptions.None,
			 DefaultValue = "Default")]
		public SecurityAlgorithmSuite AlgorithmSuite {
			get { return (SecurityAlgorithmSuite) base [algorithm_suite]; }
			set { base [algorithm_suite] = value; }
		}

		[ConfigurationProperty ("claimTypeRequirements",
			 Options = ConfigurationPropertyOptions.None)]
		public ClaimTypeElementCollection ClaimTypeRequirements {
			get { return (ClaimTypeElementCollection) base [claim_type_requirements]; }
		}

		[ConfigurationProperty ("establishSecurityContext",
			 Options = ConfigurationPropertyOptions.None,
			DefaultValue = true)]
		public bool EstablishSecurityContext {
			get { return (bool) base [establish_security_context]; }
			set { base [establish_security_context] = value; }
		}

		[ConfigurationProperty ("issuedKeyType",
			 Options = ConfigurationPropertyOptions.None,
			 DefaultValue = "SymmetricKey")]
		public SecurityKeyType IssuedKeyType {
			get { return (SecurityKeyType) base [issued_key_type]; }
			set { base [issued_key_type] = value; }
		}

		[StringValidator ( MinLength = 0,
			MaxLength = int.MaxValue,
			 InvalidCharacters = null)]
		[ConfigurationProperty ("issuedTokenType",
			 Options = ConfigurationPropertyOptions.None,
			 DefaultValue = "")]
		public string IssuedTokenType {
			get { return (string) base [issued_token_type]; }
			set { base [issued_token_type] = value; }
		}

		[ConfigurationProperty ("issuer",
			 Options = ConfigurationPropertyOptions.None)]
		public IssuedTokenParametersEndpointAddressElement Issuer {
			get { return (IssuedTokenParametersEndpointAddressElement) base [issuer]; }
		}

		[ConfigurationProperty ("issuerMetadata",
			 Options = ConfigurationPropertyOptions.None)]
		public EndpointAddressElementBase IssuerMetadata {
			get { return (EndpointAddressElementBase) base [issuer_metadata]; }
		}

		[ConfigurationProperty ("negotiateServiceCredential",
			 Options = ConfigurationPropertyOptions.None,
			DefaultValue = true)]
		public bool NegotiateServiceCredential {
			get { return (bool) base [negotiate_service_credential]; }
			set { base [negotiate_service_credential] = value; }
		}

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

		[ConfigurationProperty ("tokenRequestParameters",
			 Options = ConfigurationPropertyOptions.None)]
		public XmlElementElementCollection TokenRequestParameters {
			get { return (XmlElementElementCollection) base [token_request_parameters]; }
		}

		// Methods
		internal void ApplyConfiguration (FederatedMessageSecurityOverHttp s)
		{
			s.AlgorithmSuite = AlgorithmSuite;
			foreach (ClaimTypeElement cte in ClaimTypeRequirements)
				s.ClaimTypeRequirements.Add (cte.Create ());
			s.EstablishSecurityContext = EstablishSecurityContext;
			s.IssuedKeyType = IssuedKeyType;
			s.IssuedTokenType = IssuedTokenType;
			if (Issuer.Address != null)
				s.IssuerAddress = new EndpointAddress (Issuer.Address, Issuer.Identity.Create (), Issuer.Headers.Headers);
			if (!String.IsNullOrEmpty (Issuer.Binding))
				s.IssuerBinding = ConfigUtil.CreateBinding (Issuer.Binding, Issuer.BindingConfiguration);
			if (IssuerMetadata.Address != null)
				s.IssuerMetadataAddress = new EndpointAddress (IssuerMetadata.Address, IssuerMetadata.Identity.Create (), IssuerMetadata.Headers.Headers);
			s.NegotiateServiceCredential = NegotiateServiceCredential;
			foreach (XmlElementElement xee in TokenRequestParameters)
				s.TokenRequestParameters.Add (xee.XmlElement);
		}
	}

}