/// <summary> /// Creates a custom behavior based on the settings of this configuration element. /// </summary> /// <returns>A custom behavior based on the settings of this configuration element.</returns> protected override object CreateBehavior() { // This custom behavior will prompt the user for credentials before using a channel. PromptedClientCredentials customClientCredentials = new PromptedClientCredentials(); base.ApplyConfiguration(customClientCredentials); return(customClientCredentials); }
/// <summary> /// Initializes a new instance of a UserNameChannelInitializer class. /// </summary> /// <param name="promptedClientCredentials">The credentials that are to be initialized.</param> public UserNameChannelInitializer(PromptedClientCredentials promptedClientCredentials) : base(promptedClientCredentials) { // If credentials were supplied by the channel, then they will override the static credentials stored in the settings file. if (!String.IsNullOrEmpty(promptedClientCredentials.UserName.UserName)) { // This will create a set of prompted credentials from the channel's credentials. this.Credentials = new DistinguishedNameCredential() { DistinguishedName = promptedClientCredentials.UserName.UserName, SecurePassword = Cryptography.ToSecureString(promptedClientCredentials.UserName.Password), RememberCredentials = true, }; // Explicitly providing credentials will defeat the prompting by design. UserNameChannelInitializer.IsPrompted = false; } }
public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement securityTokenRequirement) { // Validate the argument before using it. if (securityTokenRequirement == null) { throw new ArgumentNullException("securityTokenRequirement"); } // The actual credentials are held by the PromptedClientCredentials object. There are examles out there where the properties of the channel are used to // pass the credentials back to the security token manager, but the TCP stack doesn't appear to have this collection, so we've chosen to use a property // of this class to communicate the credentials. if (this.ClientCredentials is PromptedClientCredentials) { // A set of credentials is maintained by the PromptedClientCredentials and populated by the channel initializers with input from the user. PromptedClientCredentials promptedClientCredentials = this.ClientCredentials as PromptedClientCredentials; // This will create the appropriate security token provider based on the key usage required. switch (securityTokenRequirement.KeyUsage) { case SecurityKeyUsage.Signature: // This will create a security token for distinguished user names and passwords. if (securityTokenRequirement.TokenType == SecurityTokenTypes.UserName) { DistinguishedNameCredential distinguishedNameCredential = promptedClientCredentials.Credentials as DistinguishedNameCredential; return(new UserNameSecurityTokenProvider(distinguishedNameCredential.DistinguishedName, distinguishedNameCredential.Password)); } // This will create a security token for certificates. if (securityTokenRequirement.TokenType == SecurityTokenTypes.X509Certificate) { X509Certificate2 x509Certificate2 = promptedClientCredentials.Credentials as X509Certificate2; return(new X509SecurityTokenProvider(x509Certificate2)); } break; } } // Any configuration not handled by the logic above is given a generic token handler. return(base.CreateSecurityTokenProvider(securityTokenRequirement)); }
/// <summary> /// Initializes a new instance of a CertificateChannelInitializer class. /// </summary> /// <param name="promptedClientCredentials">The credentials that are to be initialized.</param> public CertificateChannelInitializer(PromptedClientCredentials promptedClientCredentials) : base(promptedClientCredentials) { }
/// <summary> /// Initializes a new instance of a ChannelInitializer class. /// </summary> /// <param name="promptedClientCredentials">The credentials that are to be initialized.</param> protected InteractiveChannelInitializer(PromptedClientCredentials promptedClientCredentials) { // Initialize the object. this.promptedClientCredentials = promptedClientCredentials; }
/// <summary> /// Initializes a new instance of the PromptedCredentials class. /// </summary> /// <param name="promptedClientCredentials">The original PromptedClientCredentials object.</param> PromptedClientCredentials(PromptedClientCredentials promptedClientCredentials) : base(promptedClientCredentials) { }