次の方法で共有


IssuedTokenServiceCredential.CustomCertificateValidator プロパティ

定義

カスタム X.509 証明書検証を取得または設定します。

public:
 property System::IdentityModel::Selectors::X509CertificateValidator ^ CustomCertificateValidator { System::IdentityModel::Selectors::X509CertificateValidator ^ get(); void set(System::IdentityModel::Selectors::X509CertificateValidator ^ value); };
public System.IdentityModel.Selectors.X509CertificateValidator CustomCertificateValidator { get; set; }
member this.CustomCertificateValidator : System.IdentityModel.Selectors.X509CertificateValidator with get, set
Public Property CustomCertificateValidator As X509CertificateValidator

プロパティ値

カスタム X.509 証明書検証。

このプロパティにアクセスして設定する方法を次のコードに示します。

serviceHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode =
    X509CertificateValidationMode.Custom;
serviceHost.Credentials.ClientCertificate.Authentication.CustomCertificateValidator =
    new MyX509CertificateValidator("CN=Contoso.com");

前のコードで参照されているカスタムの検証コントロールは、次のコードで定義されます。

public class MyX509CertificateValidator : X509CertificateValidator
{
    string allowedIssuerName;

    public MyX509CertificateValidator(string allowedIssuerName)
    {
        if (allowedIssuerName == null)
        {
            throw new ArgumentNullException("allowedIssuerName");
        }

        this.allowedIssuerName = allowedIssuerName;
    }

    public override void Validate(X509Certificate2 certificate)
    {
        // Check that there is a certificate.
        if (certificate == null)
        {
            throw new ArgumentNullException("certificate");
        }

        // Check that the certificate issuer matches the configured issuer.
        if (allowedIssuerName != certificate.IssuerName.Name)
        {
            throw new SecurityTokenValidationException
              ("Certificate was not issued by a trusted issuer");
        }
    }
}

適用対象