/// <summary> /// Creates a custom behavior based on the settings of this configuration element. /// </summary> /// <returns></returns> protected override object CreateBehavior() { // Create and apply the prompted client credentials as part of the behavior of the endpoint. Once this is applied, the // user will be prompted with a custom user interface when the channel is initialized. PromptedClientCredentials customClientCredentials = new PromptedClientCredentials(); base.ApplyConfiguration(customClientCredentials); return(customClientCredentials); }
/// <summary> /// Create an initializer for a channel requiring Basic authentication. /// </summary> /// <param name="promptedClientCredentials">The credentials that are to be initialized.</param> public UserNameChannelInitializer(PromptedClientCredentials promptedClientCredentials) { // Initialize the object. this.promptedClientCredentials = promptedClientCredentials; //Overwrite with usercredentials if specified if (String.IsNullOrEmpty(promptedClientCredentials.UserName.UserName) == false) { UserNameChannelInitializer.networkCredentials.UserName = promptedClientCredentials.UserName.UserName; } if (String.IsNullOrEmpty(promptedClientCredentials.UserName.Password) == false) { UserNameChannelInitializer.networkCredentials.Password = promptedClientCredentials.UserName.Password; } // If a complete set of credentials has been stored, then the user isn't prompted for this information. if (!ChannelStatus.IsPrompted) { ChannelStatus.IsPrompted = UserNameChannelInitializer.networkCredentials.UserName == string.Empty || UserNameChannelInitializer.networkCredentials.Password == string.Empty; } }
/// <summary> /// Creates a security token provider. /// </summary> /// <param name="securityTokenRequirement">The System.IdentityModel.Selectors.SecurityTokenRequirement</param> /// <returns>A Security Token Provider.</returns> public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement securityTokenRequirement) { // The actual credentials are held by the PromptedClientCredentials object. When the channels are initialized, the // resulting credentials obtained from the user are stored in a simple collection in this class. They're used here to // create token providers based on the authentication scheme selected by the binding. 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 creates a UserName token provider. if (securityTokenRequirement.TokenType == SecurityTokenTypes.UserName) { if (promptedClientCredentials.Credential is NetworkCredential) { // Note that the domain name is concatenated with the user name. At this time, there's no // provision for authentication across domain boundaries, but it doesn't seem to hurt and it may be // useful for future features. NetworkCredential networkCredential = promptedClientCredentials.Credential as NetworkCredential; if (string.IsNullOrEmpty(networkCredential.Domain)) { return(new UserNameSecurityTokenProvider(networkCredential.UserName, networkCredential.Password)); } else { return(new UserNameSecurityTokenProvider(string.Format("{0}\\{1}", networkCredential.Domain, networkCredential.UserName), networkCredential.Password)); } } else { return(new UserNameSecurityTokenProvider(this.ClientCredentials.UserName.UserName, this.ClientCredentials.UserName.Password)); } } // This creates a Certificate token provider. if (securityTokenRequirement.TokenType == SecurityTokenTypes.X509Certificate) { if (promptedClientCredentials.Credential is X509Certificate2) { X509Certificate2 x509Certificate2 = promptedClientCredentials.Credential as X509Certificate2; return(new X509SecurityTokenProvider(x509Certificate2)); } } break; case SecurityKeyUsage.Exchange: // There is no special handling when keys are exchanged to provide security. return(base.CreateSecurityTokenProvider(securityTokenRequirement)); } } // Any configuration not handled by the logic above is given a generic token handler. return(base.CreateSecurityTokenProvider(securityTokenRequirement)); }
/// <summary> /// Create an initializer for a channel requiring Basic authentication. /// </summary> /// <param name="promptedClientCredentials">The credentials that are to be initialized.</param> public CertificateChannelInitializer(PromptedClientCredentials promptedClientCredentials) { // Initialize the object. this.promptedClientCredentials = promptedClientCredentials; }
/// <summary> /// Creates an object that allows the user to select credentials for a session. /// </summary> /// <param name="customClientCredentials">The original PromptedClientCredentials object.</param> public PromptedClientCredentials(PromptedClientCredentials customClientCredentials) : base(customClientCredentials) { }