1 //------------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------------------------
5 namespace System.ServiceModel.Configuration
8 using System.Collections.Generic;
9 using System.ComponentModel;
10 using System.Configuration;
12 using System.ServiceModel;
13 using System.ServiceModel.Description;
14 using System.ServiceModel.Security;
16 public sealed partial class IssuedTokenClientElement : ConfigurationElement
18 public IssuedTokenClientElement()
22 [ConfigurationProperty(ConfigurationStrings.LocalIssuer)]
23 public IssuedTokenParametersEndpointAddressElement LocalIssuer
25 get { return (IssuedTokenParametersEndpointAddressElement)base[ConfigurationStrings.LocalIssuer]; }
28 [ConfigurationProperty(ConfigurationStrings.LocalIssuerChannelBehaviors, DefaultValue = "")]
29 [StringValidator(MinLength = 0)]
30 public string LocalIssuerChannelBehaviors
32 get { return (string)base[ConfigurationStrings.LocalIssuerChannelBehaviors]; }
35 if (String.IsNullOrEmpty(value))
39 base[ConfigurationStrings.LocalIssuerChannelBehaviors] = value;
43 [ConfigurationProperty(ConfigurationStrings.IssuerChannelBehaviors)]
44 public IssuedTokenClientBehaviorsElementCollection IssuerChannelBehaviors
46 get { return (IssuedTokenClientBehaviorsElementCollection)base[ConfigurationStrings.IssuerChannelBehaviors]; }
49 [ConfigurationProperty(ConfigurationStrings.CacheIssuedTokens, DefaultValue = SpnegoTokenProvider.defaultClientCacheTokens)]
50 public bool CacheIssuedTokens
52 get { return (bool)base[ConfigurationStrings.CacheIssuedTokens]; }
53 set { base[ConfigurationStrings.CacheIssuedTokens] = value; }
56 [ConfigurationProperty(ConfigurationStrings.MaxIssuedTokenCachingTime, DefaultValue = SpnegoTokenProvider.defaultClientMaxTokenCachingTimeString)]
57 [TypeConverter(typeof(TimeSpanOrInfiniteConverter))]
58 [ServiceModelTimeSpanValidator(MinValueString = ConfigurationStrings.TimeSpanZero)]
59 public TimeSpan MaxIssuedTokenCachingTime
61 get { return (TimeSpan)base[ConfigurationStrings.MaxIssuedTokenCachingTime]; }
62 set { base[ConfigurationStrings.MaxIssuedTokenCachingTime] = value; }
65 [ConfigurationProperty(ConfigurationStrings.DefaultKeyEntropyMode, DefaultValue = System.ServiceModel.Security.AcceleratedTokenProvider.defaultKeyEntropyMode)]
66 [ServiceModelEnumValidator(typeof(SecurityKeyEntropyModeHelper))]
67 public SecurityKeyEntropyMode DefaultKeyEntropyMode
69 get { return (SecurityKeyEntropyMode)base[ConfigurationStrings.DefaultKeyEntropyMode]; }
70 set { base[ConfigurationStrings.DefaultKeyEntropyMode] = value; }
73 [ConfigurationProperty(ConfigurationStrings.IssuedTokenRenewalThresholdPercentage, DefaultValue = SpnegoTokenProvider.defaultServiceTokenValidityThresholdPercentage)]
74 [IntegerValidator(MinValue = 0, MaxValue = 100)]
75 public int IssuedTokenRenewalThresholdPercentage
77 get { return (int)base[ConfigurationStrings.IssuedTokenRenewalThresholdPercentage]; }
78 set { base[ConfigurationStrings.IssuedTokenRenewalThresholdPercentage] = value; }
81 public void Copy(IssuedTokenClientElement from)
83 if (this.IsReadOnly())
85 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
89 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("from");
92 this.DefaultKeyEntropyMode = from.DefaultKeyEntropyMode;
93 this.CacheIssuedTokens = from.CacheIssuedTokens;
94 this.MaxIssuedTokenCachingTime = from.MaxIssuedTokenCachingTime;
95 this.IssuedTokenRenewalThresholdPercentage = from.IssuedTokenRenewalThresholdPercentage;
97 #pragma warning suppress 56506 //Microsoft; from.ElementInformation.Properties[ConfigurationStrings.LocalIssuerIssuedTokenParameters] can never be null (underlying configuration system guarantees)
98 if (PropertyValueOrigin.Default != from.ElementInformation.Properties[ConfigurationStrings.LocalIssuer].ValueOrigin)
100 this.LocalIssuer.Copy(from.LocalIssuer);
102 #pragma warning suppress 56506 //Microsoft; from.ElementInformation.Properties[ConfigurationStrings.LocalIssuerChannelBehaviors] can never be null (underlying configuration system guarantees)
103 if (PropertyValueOrigin.Default != from.ElementInformation.Properties[ConfigurationStrings.LocalIssuerChannelBehaviors].ValueOrigin)
105 this.LocalIssuerChannelBehaviors = from.LocalIssuerChannelBehaviors;
107 #pragma warning suppress 56506 //Microsoft; from.ElementInformation.Properties[ConfigurationStrings.IssuerChannelBehaviors] can never be null (underlying configuration system guarantees)
108 if (PropertyValueOrigin.Default != from.ElementInformation.Properties[ConfigurationStrings.IssuerChannelBehaviors].ValueOrigin)
110 foreach (IssuedTokenClientBehaviorsElement element in from.IssuerChannelBehaviors)
112 this.IssuerChannelBehaviors.Add(element);
117 internal void ApplyConfiguration(IssuedTokenClientCredential issuedToken)
119 if (issuedToken == null)
121 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("issuedToken");
123 issuedToken.CacheIssuedTokens = this.CacheIssuedTokens;
124 issuedToken.DefaultKeyEntropyMode = this.DefaultKeyEntropyMode;
125 issuedToken.MaxIssuedTokenCachingTime = this.MaxIssuedTokenCachingTime;
126 issuedToken.IssuedTokenRenewalThresholdPercentage = this.IssuedTokenRenewalThresholdPercentage;
127 if (PropertyValueOrigin.Default != this.ElementInformation.Properties[ConfigurationStrings.LocalIssuer].ValueOrigin)
129 this.LocalIssuer.Validate();
130 issuedToken.LocalIssuerAddress = ConfigLoader.LoadEndpointAddress(this.LocalIssuer);
131 if (!string.IsNullOrEmpty(this.LocalIssuer.Binding))
133 issuedToken.LocalIssuerBinding = ConfigLoader.LookupBinding(this.LocalIssuer.Binding, this.LocalIssuer.BindingConfiguration, this.EvaluationContext);
136 if (!string.IsNullOrEmpty(this.LocalIssuerChannelBehaviors))
138 ConfigLoader.LoadChannelBehaviors(this.LocalIssuerChannelBehaviors, this.EvaluationContext, issuedToken.LocalIssuerChannelBehaviors);
140 if (PropertyValueOrigin.Default != this.ElementInformation.Properties[ConfigurationStrings.IssuerChannelBehaviors].ValueOrigin)
142 foreach (IssuedTokenClientBehaviorsElement issuerBehaviorElement in this.IssuerChannelBehaviors)
144 if (!string.IsNullOrEmpty(issuerBehaviorElement.BehaviorConfiguration))
146 KeyedByTypeCollection<IEndpointBehavior> issuerBehaviors = new KeyedByTypeCollection<IEndpointBehavior>();
147 ConfigLoader.LoadChannelBehaviors(issuerBehaviorElement.BehaviorConfiguration, this.EvaluationContext, issuerBehaviors);
148 issuedToken.IssuerChannelBehaviors.Add(new Uri(issuerBehaviorElement.IssuerAddress), issuerBehaviors);