Beispiel #1
0
        private void Snippet1()
        {
            //<snippet1>
            // Create a service host.
            Uri         httpUri = new Uri("http://localhost/Calculator");
            ServiceHost sh      = new ServiceHost(typeof(Calculator), httpUri);

            // Create a binding that uses a username/password credential.
            WSHttpBinding b = new WSHttpBinding(SecurityMode.Message);

            b.Security.Message.ClientCredentialType = MessageCredentialType.UserName;

            // Add an endpoint.
            sh.AddServiceEndpoint(typeof(ICalculator), b, "UserNamePasswordCalculator");

            // Get a reference to the UserNamePasswordServiceCredential object.
            UserNamePasswordServiceCredential unpCredential =
                sh.Credentials.UserNameAuthentication;

            // Print out values.
            Console.WriteLine("IncludeWindowsGroup: {0}",
                              unpCredential.IncludeWindowsGroups);
            Console.WriteLine("UserNamePasswordValidationMode: {0}",
                              unpCredential.UserNamePasswordValidationMode);
            Console.WriteLine("CachedLogonTokenLifetime.Minutes: {0}",
                              unpCredential.CachedLogonTokenLifetime.Minutes);
            Console.WriteLine("CacheLogonTokens: {0}",
                              unpCredential.CacheLogonTokens);
            Console.WriteLine("MaxCachedLogonTokens: {0}",
                              unpCredential.MaxCachedLogonTokens);

            Console.ReadLine();
            //</snippet1>
        }
 internal void ApplyConfiguration(UserNamePasswordServiceCredential userName)
 {
     if (userName == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("userName");
     }
     userName.UserNamePasswordValidationMode = this.UserNamePasswordValidationMode;
     userName.IncludeWindowsGroups           = this.IncludeWindowsGroups;
     userName.CacheLogonTokens         = this.CacheLogonTokens;
     userName.MaxCachedLogonTokens     = this.MaxCachedLogonTokens;
     userName.CachedLogonTokenLifetime = this.CachedLogonTokenLifetime;
     if (base.ElementInformation.Properties["membershipProviderName"].ValueOrigin != PropertyValueOrigin.Default)
     {
         userName.MembershipProvider = SystemWebHelper.GetMembershipProvider(this.MembershipProviderName);
         if (userName.MembershipProvider == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("InvalidMembershipProviderSpecifiedInConfig", new object[] { this.MembershipProviderName })));
         }
     }
     else if (userName.UserNamePasswordValidationMode == System.ServiceModel.Security.UserNamePasswordValidationMode.MembershipProvider)
     {
         userName.MembershipProvider = SystemWebHelper.GetMembershipProvider();
     }
     if (!string.IsNullOrEmpty(this.CustomUserNamePasswordValidatorType))
     {
         Type c = Type.GetType(this.CustomUserNamePasswordValidatorType, true);
         if (!typeof(UserNamePasswordValidator).IsAssignableFrom(c))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidUserNamePasswordValidatorType", new object[] { this.CustomUserNamePasswordValidatorType, typeof(UserNamePasswordValidator).ToString() })));
         }
         userName.CustomUserNamePasswordValidator = (UserNamePasswordValidator)Activator.CreateInstance(c);
     }
 }
Beispiel #3
0
 public ServiceCredentials()
 {
     UserNameAuthentication           = new UserNamePasswordServiceCredential();
     ClientCertificate                = new X509CertificateInitiatorServiceCredential();
     ServiceCertificate               = new X509CertificateRecipientServiceCredential();
     WindowsAuthentication            = new WindowsServiceCredential();
     IssuedTokenAuthentication        = new IssuedTokenServiceCredential();
     SecureConversationAuthentication = new SecureConversationServiceCredential();
     _exceptionMapper = new ExceptionMapper();
 }
Beispiel #4
0
 public ServiceCredentials()
 {
     userName                = new UserNamePasswordServiceCredential();
     clientCertificate       = new X509CertificateInitiatorServiceCredential();
     serviceCertificate      = new X509CertificateRecipientServiceCredential();
     windows                 = new WindowsServiceCredential();
     this.issuedToken        = new IssuedTokenServiceCredential();
     this.secureConversation = new SecureConversationServiceCredential();
     exceptionMapper         = new ExceptionMapper();
 }
 public ServiceCredentials()
 {
     this.userName           = new UserNamePasswordServiceCredential();
     this.clientCertificate  = new X509CertificateInitiatorServiceCredential();
     this.serviceCertificate = new X509CertificateRecipientServiceCredential();
     this.windows            = new WindowsServiceCredential();
     this.issuedToken        = new IssuedTokenServiceCredential();
     this.peer = new PeerCredential();
     this.secureConversation = new SecureConversationServiceCredential();
 }
 protected ServiceCredentials(ServiceCredentials other)
 {
     if (other == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("other");
     }
     this.userName           = new UserNamePasswordServiceCredential(other.userName);
     this.clientCertificate  = new X509CertificateInitiatorServiceCredential(other.clientCertificate);
     this.serviceCertificate = new X509CertificateRecipientServiceCredential(other.serviceCertificate);
     this.windows            = new WindowsServiceCredential(other.windows);
     this.issuedToken        = new IssuedTokenServiceCredential(other.issuedToken);
     this.peer = new PeerCredential(other.peer);
     this.secureConversation = new SecureConversationServiceCredential(other.secureConversation);
 }
Beispiel #7
0
 protected ServiceCredentials(ServiceCredentials other)
 {
     if (other == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(other));
     }
     UserNameAuthentication           = new UserNamePasswordServiceCredential(other.UserNameAuthentication);
     ClientCertificate                = new X509CertificateInitiatorServiceCredential(other.ClientCertificate);
     ServiceCertificate               = new X509CertificateRecipientServiceCredential(other.ServiceCertificate);
     WindowsAuthentication            = new WindowsServiceCredential(other.WindowsAuthentication);
     IssuedTokenAuthentication        = new IssuedTokenServiceCredential(other.IssuedTokenAuthentication);
     SecureConversationAuthentication = new SecureConversationServiceCredential(other.SecureConversationAuthentication);
     _saveBootstrapTokenInSession     = other._saveBootstrapTokenInSession;
     _exceptionMapper = other._exceptionMapper;
 }
Beispiel #8
0
 protected ServiceCredentials(ServiceCredentials other)
 {
     if (other == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(other));
     }
     userName                    = new UserNamePasswordServiceCredential(other.userName);
     clientCertificate           = new X509CertificateInitiatorServiceCredential(other.clientCertificate);
     serviceCertificate          = new X509CertificateRecipientServiceCredential(other.serviceCertificate);
     windows                     = new WindowsServiceCredential(other.windows);
     this.issuedToken            = new IssuedTokenServiceCredential(other.issuedToken);
     this.secureConversation     = new SecureConversationServiceCredential(other.secureConversation);
     saveBootstrapTokenInSession = other.saveBootstrapTokenInSession;
     exceptionMapper             = other.exceptionMapper;
 }