Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casing for WCF owned classes WsXxxx->WSXxxx #4384

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static void WSFederationHttpBindingTests_Succeeds()
var issuerBinding = new WSHttpBinding(SecurityMode.Transport);
issuerBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

WsFederationHttpBinding federationBinding = new WsFederationHttpBinding(
new WsTrustTokenParameters
WSFederationHttpBinding federationBinding = new WSFederationHttpBinding(
new WSTrustTokenParameters
{
IssuerAddress = issuerAddress,
IssuerBinding = issuerBinding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,53 @@ public SamlAssertionKeyIdentifierClause(string assertionId) : base(assertionId,

namespace System.ServiceModel.Federation
{
internal class WsFederationBindingElement : System.ServiceModel.Channels.BindingElement
internal class WSFederationBindingElement : System.ServiceModel.Channels.BindingElement
{
public WsFederationBindingElement(WsTrustTokenParameters wsTrustTokenParameters, System.ServiceModel.Channels.SecurityBindingElement securityBindingElement) { }
public WsTrustTokenParameters WsTrustTokenParameters { get => default; }
public WSFederationBindingElement(WSTrustTokenParameters wsTrustTokenParameters, System.ServiceModel.Channels.SecurityBindingElement securityBindingElement) { }
public WSTrustTokenParameters WSTrustTokenParameters { get => default; }
public System.ServiceModel.Channels.SecurityBindingElement SecurityBindingElement { get => default; }
public override System.ServiceModel.Channels.BindingElement Clone() => default;
public override T GetProperty<T>(System.ServiceModel.Channels.BindingContext context) => default;
public override System.ServiceModel.Channels.IChannelFactory<TChannel> BuildChannelFactory<TChannel>(System.ServiceModel.Channels.BindingContext context) => default;
}
public class WsFederationHttpBinding : System.ServiceModel.WSHttpBinding
public class WSFederationHttpBinding : System.ServiceModel.WSHttpBinding
{
public WsFederationHttpBinding(WsTrustTokenParameters wsTrustTokenParameters) : base(System.ServiceModel.SecurityMode.TransportWithMessageCredential) { }
public WsTrustTokenParameters WsTrustTokenParameters { get => default; }
public WSFederationHttpBinding(WSTrustTokenParameters wsTrustTokenParameters) : base(System.ServiceModel.SecurityMode.TransportWithMessageCredential) { }
public WSTrustTokenParameters WSTrustTokenParameters { get => default; }
protected override System.ServiceModel.Channels.SecurityBindingElement CreateMessageSecurity() => default;
public override System.ServiceModel.Channels.BindingElementCollection CreateBindingElements() => default;
protected override System.ServiceModel.Channels.TransportBindingElement GetTransport() => default;
}
public class WsTrustChannelClientCredentials : System.ServiceModel.Description.ClientCredentials
public class WSTrustChannelClientCredentials : System.ServiceModel.Description.ClientCredentials
{
public WsTrustChannelClientCredentials() : base() { }
public WsTrustChannelClientCredentials(System.ServiceModel.Description.ClientCredentials clientCredentials) : base(clientCredentials) { }
protected WsTrustChannelClientCredentials(WsTrustChannelClientCredentials other) : base(other) { }
public WSTrustChannelClientCredentials() : base() { }
public WSTrustChannelClientCredentials(System.ServiceModel.Description.ClientCredentials clientCredentials) : base(clientCredentials) { }
protected WSTrustChannelClientCredentials(WSTrustChannelClientCredentials other) : base(other) { }
public System.ServiceModel.Description.ClientCredentials ClientCredentials { get => default; private set { } }
protected override System.ServiceModel.Description.ClientCredentials CloneCore() => default;
public override System.IdentityModel.Selectors.SecurityTokenManager CreateSecurityTokenManager() => default;
}
public class WsTrustChannelSecurityTokenManager : System.ServiceModel.ClientCredentialsSecurityTokenManager
public class WSTrustChannelSecurityTokenManager : System.ServiceModel.ClientCredentialsSecurityTokenManager
{
public WsTrustChannelSecurityTokenManager(WsTrustChannelClientCredentials wsTrustChannelClientCredentials) : base(wsTrustChannelClientCredentials) { }
public WSTrustChannelSecurityTokenManager(WSTrustChannelClientCredentials wsTrustChannelClientCredentials) : base(wsTrustChannelClientCredentials) { }
public override System.IdentityModel.Selectors.SecurityTokenProvider CreateSecurityTokenProvider(System.IdentityModel.Selectors.SecurityTokenRequirement tokenRequirement) => default;
}
public class WsTrustChannelSecurityTokenProvider : System.IdentityModel.Selectors.SecurityTokenProvider
public class WSTrustChannelSecurityTokenProvider : System.IdentityModel.Selectors.SecurityTokenProvider
{
public WsTrustChannelSecurityTokenProvider(System.IdentityModel.Selectors.SecurityTokenRequirement tokenRequirement) { }
public WSTrustChannelSecurityTokenProvider(System.IdentityModel.Selectors.SecurityTokenRequirement tokenRequirement) { }
protected virtual Microsoft.IdentityModel.Protocols.WsTrust.WsTrustRequest CreateWsTrustRequest() => default;
protected override System.IdentityModel.Tokens.SecurityToken GetTokenCore(TimeSpan timeout) => default;
public override bool SupportsTokenCancellation => default;
public override bool SupportsTokenRenewal => default;
}
public class WsTrustTokenParameters : System.ServiceModel.Security.Tokens.IssuedSecurityTokenParameters
public class WSTrustTokenParameters : System.ServiceModel.Security.Tokens.IssuedSecurityTokenParameters
{
public static readonly bool DefaultCacheIssuedTokens = default;
public static readonly int DefaultIssuedTokenRenewalThresholdPercentage = default;
public static readonly TimeSpan DefaultMaxIssuedTokenCachingTime = default;
public static readonly System.IdentityModel.Tokens.SecurityKeyType DefaultSecurityKeyType = default;
public WsTrustTokenParameters() { }
protected WsTrustTokenParameters(WsTrustTokenParameters other) : base(other) { }
public WSTrustTokenParameters() { }
protected WSTrustTokenParameters(WSTrustTokenParameters other) : base(other) { }
protected override System.ServiceModel.Security.Tokens.SecurityTokenParameters CloneCore() => default;
public System.Collections.Generic.ICollection<System.Xml.XmlElement> AdditionalRequestParameters => default;
public bool CacheIssuedTokens { get => default; set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace System.ServiceModel.Federation
/// <summary>
/// Custom WSTrustChannelSecurityTokenProvider that returns a SAML assertion
/// </summary>
public class WsTrustChannelSecurityTokenProvider : SecurityTokenProvider
public class WSTrustChannelSecurityTokenProvider : SecurityTokenProvider
{
private const int DefaultPublicKeySize = 1024;
private const string Namespace = "http://schemas.microsoft.com/ws/2006/05/servicemodel/securitytokenrequirement";
Expand All @@ -38,20 +38,20 @@ public class WsTrustChannelSecurityTokenProvider : SecurityTokenProvider
private const string SecurityBindingElementProperty = Namespace + "/SecurityBindingElement";
private const string TargetAddressProperty = Namespace + "/TargetAddress";

//private readonly WsTrustTokenParameters _issuedTokenParameters;
//private readonly WSTrustTokenParameters _issuedTokenParameters;
private SecurityKeyEntropyMode _keyEntropyMode;
private ChannelFactory<IRequestChannel> _channelFactory;
private readonly SecurityAlgorithmSuite _securityAlgorithmSuite;
private WsSerializationContext _requestSerializationContext;

public WsTrustChannelSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
public WSTrustChannelSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
{
SecurityTokenRequirement = tokenRequirement ?? throw new ArgumentNullException(nameof(tokenRequirement));
SecurityTokenRequirement.TryGetProperty(SecurityAlgorithmSuiteProperty, out _securityAlgorithmSuite);
WsTrustTokenParameters = SecurityTokenRequirement.GetProperty<IssuedSecurityTokenParameters>(IssuedSecurityTokenParametersProperty) as WsTrustTokenParameters;
WSTrustTokenParameters = SecurityTokenRequirement.GetProperty<IssuedSecurityTokenParameters>(IssuedSecurityTokenParametersProperty) as WSTrustTokenParameters;
InitializeKeyEntropyMode();
SetInboundSerializationContext();
RequestContext = string.IsNullOrEmpty(WsTrustTokenParameters.RequestContext) ? Guid.NewGuid().ToString() : WsTrustTokenParameters.RequestContext;
RequestContext = string.IsNullOrEmpty(WSTrustTokenParameters.RequestContext) ? Guid.NewGuid().ToString() : WSTrustTokenParameters.RequestContext;
}

private DateTime AddTicks(DateTime time, long ticks)
Expand Down Expand Up @@ -81,7 +81,7 @@ private WsTrustResponse CachedResponse

private void CacheSecurityTokenResponse(WsTrustRequest request, WsTrustResponse response)
{
if (WsTrustTokenParameters.CacheIssuedTokens)
if (WSTrustTokenParameters.CacheIssuedTokens)
{
// If cached respones are stored in a shared cache in the future, that cache should be written
// to here, possibly including serializing the WsTrustResponse if the cache stores byte[] (as
Expand All @@ -100,7 +100,7 @@ internal virtual ChannelFactory<IRequestChannel> ChannelFactory
{
if (_channelFactory == null)
{
_channelFactory = new ChannelFactory<IRequestChannel>(IssuerBinding, WsTrustTokenParameters.IssuerAddress);
_channelFactory = new ChannelFactory<IRequestChannel>(IssuerBinding, WSTrustTokenParameters.IssuerAddress);
if (ClientCredentials != null)
{
_channelFactory.Endpoint.EndpointBehaviors.Remove(typeof(ClientCredentials));
Expand All @@ -121,7 +121,7 @@ protected virtual WsTrustRequest CreateWsTrustRequest()
int keySize;
string keyType;

switch (WsTrustTokenParameters.KeyType)
switch (WSTrustTokenParameters.KeyType)
{
case SecurityKeyType.AsymmetricKey:
keySize = DefaultPublicKeySize;
Expand All @@ -140,7 +140,7 @@ protected virtual WsTrustRequest CreateWsTrustRequest()
}

Entropy entropy = null;
if (WsTrustTokenParameters.KeyType != SecurityKeyType.BearerKey &&
if (WSTrustTokenParameters.KeyType != SecurityKeyType.BearerKey &&
(KeyEntropyMode == SecurityKeyEntropyMode.ClientEntropy || KeyEntropyMode == SecurityKeyEntropyMode.CombinedEntropy))
{
byte[] entropyBytes = new byte[keySize / 8];
Expand Down Expand Up @@ -173,7 +173,7 @@ protected virtual WsTrustRequest CreateWsTrustRequest()

private WsTrustResponse GetCachedResponse(WsTrustRequest request)
{
if (WsTrustTokenParameters.CacheIssuedTokens && CachedResponse != null)
if (WSTrustTokenParameters.CacheIssuedTokens && CachedResponse != null)
{
// If cached responses are read from shared caches in the future, then that cache should be read here
// and, if necessary, translated (perhaps via deserialization) into a WsTrustResponse.
Expand Down Expand Up @@ -397,7 +397,7 @@ private void InitializeKeyEntropyMode()
// That scenario does not seem to be needed in .NET Core WsTrust scenarios, so key entropy mode is simply being read from the issuer's
// security binding element. If, in the future, it's necessary to change the default (if some scenarios don't have a security binding
// element, for example), that could be done by adding a DefaultKeyEntropyMode property to WsTrustChannelCredentials and moving
// the code that calculates KeyEntropyMode out to WsTrustChannelSecurityTokenManager since it can set this property
// the code that calculates KeyEntropyMode out to WSTrustChannelSecurityTokenManager since it can set this property
// when it creates the provider and fall back to the credentials' default value if no security binding element is present.
KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
SecurityBindingElement securityBindingElement = IssuerBinding?.CreateBindingElements().Find<SecurityBindingElement>();
Expand All @@ -413,7 +413,7 @@ private void InitializeKeyEntropyMode()
///
internal Binding IssuerBinding
{
get => WsTrustTokenParameters?.IssuerBinding;
get => WSTrustTokenParameters?.IssuerBinding;
}

private bool IsWsTrustResponseExpired(WsTrustResponse response)
Expand All @@ -434,8 +434,8 @@ private bool IsWsTrustResponseExpired(WsTrustResponse response)
DateTime toTime = responseLifetime.Expires.Value.ToUniversalTime();

long interval = toTime.Ticks - fromTime.Ticks;
long effectiveInterval = (long)((WsTrustTokenParameters.IssuedTokenRenewalThresholdPercentage / (double)100) * interval);
DateTime effectiveExpiration = AddTicks(fromTime, Math.Min(effectiveInterval, WsTrustTokenParameters.MaxIssuedTokenCachingTime.Ticks));
long effectiveInterval = (long)((WSTrustTokenParameters.IssuedTokenRenewalThresholdPercentage / (double)100) * interval);
DateTime effectiveExpiration = AddTicks(fromTime, Math.Min(effectiveInterval, WSTrustTokenParameters.MaxIssuedTokenCachingTime.Ticks));

return effectiveExpiration < DateTime.UtcNow;
}
Expand Down Expand Up @@ -486,12 +486,12 @@ internal SecurityTokenRequirement SecurityTokenRequirement
/// </summary>
private void SetInboundSerializationContext()
{
// WsTrustTokenParameters.MessageSecurityVersion can be checked directly instead of
// extracting MessageSecurityVersion from the issuer binding, because the WsFederationHttpBinding
// creates its security binding element using the MessageSecurityVersion from its WsTrustTokenParameters.
MessageSecurityVersion messageSecurityVersion = WsTrustTokenParameters.MessageSecurityVersion;
// WSTrustTokenParameters.MessageSecurityVersion can be checked directly instead of
// extracting MessageSecurityVersion from the issuer binding, because the WSFederationHttpBinding
// creates its security binding element using the MessageSecurityVersion from its WSTrustTokenParameters.
MessageSecurityVersion messageSecurityVersion = WSTrustTokenParameters.MessageSecurityVersion;
if (messageSecurityVersion == null)
messageSecurityVersion = WsTrustTokenParameters.DefaultMessageSecurityVersion;
messageSecurityVersion = WSTrustTokenParameters.DefaultMessageSecurityVersion;

if (messageSecurityVersion == null)
{
Expand All @@ -511,6 +511,6 @@ private void SetInboundSerializationContext()

public override bool SupportsTokenRenewal => false;

internal WsTrustTokenParameters WsTrustTokenParameters { get; }
internal WSTrustTokenParameters WSTrustTokenParameters { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

namespace System.ServiceModel.Federation
{
internal class WsFederationBindingElement : BindingElement
internal class WSFederationBindingElement : BindingElement
{
public WsFederationBindingElement(WsTrustTokenParameters wsTrustTokenParameters, SecurityBindingElement securityBindingElement)
public WSFederationBindingElement(WSTrustTokenParameters wsTrustTokenParameters, SecurityBindingElement securityBindingElement)
{
WsTrustTokenParameters = wsTrustTokenParameters;
WSTrustTokenParameters = wsTrustTokenParameters;
SecurityBindingElement = securityBindingElement;
}

public WsTrustTokenParameters WsTrustTokenParameters { get; }
public WSTrustTokenParameters WSTrustTokenParameters { get; }

public SecurityBindingElement SecurityBindingElement { get; }

public override BindingElement Clone()
{
return new WsFederationBindingElement(WsTrustTokenParameters, SecurityBindingElement);
return new WSFederationBindingElement(WSTrustTokenParameters, SecurityBindingElement);
}

public override T GetProperty<T>(BindingContext context)
Expand All @@ -31,19 +31,19 @@ public override T GetProperty<T>(BindingContext context)

public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
{
WsTrustChannelClientCredentials trustCredentials = Find<WsTrustChannelClientCredentials>(context.BindingParameters);
WSTrustChannelClientCredentials trustCredentials = Find<WSTrustChannelClientCredentials>(context.BindingParameters);
if (trustCredentials == null)
{
var clientCredentials = Find<ClientCredentials>(context.BindingParameters);
if (clientCredentials != null)
{
trustCredentials = new WsTrustChannelClientCredentials(clientCredentials);
trustCredentials = new WSTrustChannelClientCredentials(clientCredentials);
context.BindingParameters.Remove(typeof(ClientCredentials));
context.BindingParameters.Add(trustCredentials);
}
else
{
trustCredentials = new WsTrustChannelClientCredentials();
trustCredentials = new WSTrustChannelClientCredentials();
context.BindingParameters.Add(trustCredentials);
}
}
Expand Down
Loading