1 // 2 // FederatedMessageSecurityOverHttpElement.cs 3 // 4 // Author: 5 // Atsushi Enomoto <atsushi@ximian.com> 6 // 7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com 8 // 9 // Permission is hereby granted, free of charge, to any person obtaining 10 // a copy of this software and associated documentation files (the 11 // "Software"), to deal in the Software without restriction, including 12 // without limitation the rights to use, copy, modify, merge, publish, 13 // distribute, sublicense, and/or sell copies of the Software, and to 14 // permit persons to whom the Software is furnished to do so, subject to 15 // the following conditions: 16 // 17 // The above copyright notice and this permission notice shall be 18 // included in all copies or substantial portions of the Software. 19 // 20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 // 28 29 using System; 30 using System.Collections; 31 using System.Collections.Generic; 32 using System.Collections.ObjectModel; 33 using System.ComponentModel; 34 using System.Configuration; 35 using System.Net; 36 using System.Net.Security; 37 using System.Reflection; 38 using System.Security.Cryptography.X509Certificates; 39 using System.Security.Principal; 40 using System.IdentityModel.Claims; 41 using System.IdentityModel.Policy; 42 using System.IdentityModel.Tokens; 43 using System.ServiceModel; 44 using System.ServiceModel.Channels; 45 using System.ServiceModel.Description; 46 using System.ServiceModel.Diagnostics; 47 using System.ServiceModel.Dispatcher; 48 using System.ServiceModel.MsmqIntegration; 49 using System.ServiceModel.PeerResolvers; 50 using System.ServiceModel.Security; 51 using System.Runtime.Serialization; 52 using System.Text; 53 using System.Xml; 54 55 namespace System.ServiceModel.Configuration 56 { 57 [MonoTODO] 58 public sealed partial class FederatedMessageSecurityOverHttpElement 59 : ConfigurationElement 60 { 61 // Static Fields 62 static ConfigurationPropertyCollection properties; 63 static ConfigurationProperty algorithm_suite; 64 static ConfigurationProperty claim_type_requirements; 65 static ConfigurationProperty establish_security_context; 66 static ConfigurationProperty issued_key_type; 67 static ConfigurationProperty issued_token_type; 68 static ConfigurationProperty issuer; 69 static ConfigurationProperty issuer_metadata; 70 static ConfigurationProperty negotiate_service_credential; 71 static ConfigurationProperty token_request_parameters; 72 FederatedMessageSecurityOverHttpElement()73 static FederatedMessageSecurityOverHttpElement () 74 { 75 properties = new ConfigurationPropertyCollection (); 76 algorithm_suite = new ConfigurationProperty ("algorithmSuite", 77 typeof (SecurityAlgorithmSuite), "Default", new SecurityAlgorithmSuiteConverter (), null, 78 ConfigurationPropertyOptions.None); 79 80 claim_type_requirements = new ConfigurationProperty ("claimTypeRequirements", 81 typeof (ClaimTypeElementCollection), null, null/* FIXME: get converter for ClaimTypeElementCollection*/, null, 82 ConfigurationPropertyOptions.None); 83 84 establish_security_context = new ConfigurationProperty ("establishSecurityContext", 85 typeof (bool), "true", new BooleanConverter (), null, 86 ConfigurationPropertyOptions.None); 87 88 issued_key_type = new ConfigurationProperty ("issuedKeyType", 89 typeof (SecurityKeyType), "SymmetricKey", null/* FIXME: get converter for SecurityKeyType*/, null, 90 ConfigurationPropertyOptions.None); 91 92 issued_token_type = new ConfigurationProperty ("issuedTokenType", 93 typeof (string), "", new StringConverter (), null, 94 ConfigurationPropertyOptions.None); 95 96 issuer = new ConfigurationProperty ("issuer", 97 typeof (IssuedTokenParametersEndpointAddressElement), null, null/* FIXME: get converter for IssuedTokenParametersEndpointAddressElement*/, null, 98 ConfigurationPropertyOptions.None); 99 100 issuer_metadata = new ConfigurationProperty ("issuerMetadata", 101 typeof (EndpointAddressElementBase), null, null/* FIXME: get converter for EndpointAddressElementBase*/, null, 102 ConfigurationPropertyOptions.None); 103 104 negotiate_service_credential = new ConfigurationProperty ("negotiateServiceCredential", 105 typeof (bool), "true", new BooleanConverter (), null, 106 ConfigurationPropertyOptions.None); 107 108 token_request_parameters = new ConfigurationProperty ("tokenRequestParameters", 109 typeof (XmlElementElementCollection), null, null/* FIXME: get converter for XmlElementElementCollection*/, null, 110 ConfigurationPropertyOptions.None); 111 112 properties.Add (algorithm_suite); 113 properties.Add (claim_type_requirements); 114 properties.Add (establish_security_context); 115 properties.Add (issued_key_type); 116 properties.Add (issued_token_type); 117 properties.Add (issuer); 118 properties.Add (issuer_metadata); 119 properties.Add (negotiate_service_credential); 120 properties.Add (token_request_parameters); 121 } 122 FederatedMessageSecurityOverHttpElement()123 public FederatedMessageSecurityOverHttpElement () 124 { 125 } 126 127 128 // Properties 129 130 [TypeConverter (typeof (SecurityAlgorithmSuiteConverter))] 131 [ConfigurationProperty ("algorithmSuite", 132 Options = ConfigurationPropertyOptions.None, 133 DefaultValue = "Default")] 134 public SecurityAlgorithmSuite AlgorithmSuite { 135 get { return (SecurityAlgorithmSuite) base [algorithm_suite]; } 136 set { base [algorithm_suite] = value; } 137 } 138 139 [ConfigurationProperty ("claimTypeRequirements", 140 Options = ConfigurationPropertyOptions.None)] 141 public ClaimTypeElementCollection ClaimTypeRequirements { 142 get { return (ClaimTypeElementCollection) base [claim_type_requirements]; } 143 } 144 145 [ConfigurationProperty ("establishSecurityContext", 146 Options = ConfigurationPropertyOptions.None, 147 DefaultValue = true)] 148 public bool EstablishSecurityContext { 149 get { return (bool) base [establish_security_context]; } 150 set { base [establish_security_context] = value; } 151 } 152 153 [ConfigurationProperty ("issuedKeyType", 154 Options = ConfigurationPropertyOptions.None, 155 DefaultValue = "SymmetricKey")] 156 public SecurityKeyType IssuedKeyType { 157 get { return (SecurityKeyType) base [issued_key_type]; } 158 set { base [issued_key_type] = value; } 159 } 160 161 [StringValidator ( MinLength = 0, 162 MaxLength = int.MaxValue, 163 InvalidCharacters = null)] 164 [ConfigurationProperty ("issuedTokenType", 165 Options = ConfigurationPropertyOptions.None, 166 DefaultValue = "")] 167 public string IssuedTokenType { 168 get { return (string) base [issued_token_type]; } 169 set { base [issued_token_type] = value; } 170 } 171 172 [ConfigurationProperty ("issuer", 173 Options = ConfigurationPropertyOptions.None)] 174 public IssuedTokenParametersEndpointAddressElement Issuer { 175 get { return (IssuedTokenParametersEndpointAddressElement) base [issuer]; } 176 } 177 178 [ConfigurationProperty ("issuerMetadata", 179 Options = ConfigurationPropertyOptions.None)] 180 public EndpointAddressElementBase IssuerMetadata { 181 get { return (EndpointAddressElementBase) base [issuer_metadata]; } 182 } 183 184 [ConfigurationProperty ("negotiateServiceCredential", 185 Options = ConfigurationPropertyOptions.None, 186 DefaultValue = true)] 187 public bool NegotiateServiceCredential { 188 get { return (bool) base [negotiate_service_credential]; } 189 set { base [negotiate_service_credential] = value; } 190 } 191 192 protected override ConfigurationPropertyCollection Properties { 193 get { return properties; } 194 } 195 196 [ConfigurationProperty ("tokenRequestParameters", 197 Options = ConfigurationPropertyOptions.None)] 198 public XmlElementElementCollection TokenRequestParameters { 199 get { return (XmlElementElementCollection) base [token_request_parameters]; } 200 } 201 202 // Methods ApplyConfiguration(FederatedMessageSecurityOverHttp s)203 internal void ApplyConfiguration (FederatedMessageSecurityOverHttp s) 204 { 205 s.AlgorithmSuite = AlgorithmSuite; 206 foreach (ClaimTypeElement cte in ClaimTypeRequirements) 207 s.ClaimTypeRequirements.Add (cte.Create ()); 208 s.EstablishSecurityContext = EstablishSecurityContext; 209 s.IssuedKeyType = IssuedKeyType; 210 s.IssuedTokenType = IssuedTokenType; 211 if (Issuer.Address != null) 212 s.IssuerAddress = new EndpointAddress (Issuer.Address, Issuer.Identity.Create (), Issuer.Headers.Headers); 213 if (!String.IsNullOrEmpty (Issuer.Binding)) 214 s.IssuerBinding = ConfigUtil.CreateBinding (Issuer.Binding, Issuer.BindingConfiguration); 215 if (IssuerMetadata.Address != null) 216 s.IssuerMetadataAddress = new EndpointAddress (IssuerMetadata.Address, IssuerMetadata.Identity.Create (), IssuerMetadata.Headers.Headers); 217 s.NegotiateServiceCredential = NegotiateServiceCredential; 218 foreach (XmlElementElement xee in TokenRequestParameters) 219 s.TokenRequestParameters.Add (xee.XmlElement); 220 } 221 } 222 223 } 224