【问题标题】:Custom X509SecurityTokenManager ignored自定义 X509SecurityTokenManager 被忽略
【发布时间】:2010-09-10 00:36:52
【问题描述】:

我有一个 Web 服务,它在 WSE 3.0 中使用带有 X.509 证书的消息层安全性。该服务使用 X509v3 策略对 soapheader 中的各种元素进行签名。

我需要对证书进行一些自定义检查,因此我尝试实现自定义 X509SecurityTokenManager 并在 web.config 中添加了一个部分。

当我使用 Wseproxy 调用该服务时,我预计会出现错误 (NotImplementedException),但调用失败了,并且在下面的示例中,控制台上会打印“foo”。

问题是:错过了什么? web.config 中的 binarySecurityTokenManager 类型与 RDI.Server.X509TokenManager 的完整类名匹配。 X509TokenManager 继承自 X509SecurityTokenManager(虽然方法只是存根)。

using System;
using System.Xml;
using System.Security.Permissions;
using System.Security.Cryptography;
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Security.Tokens;

namespace RDI.Server
{

[SecurityPermissionAttribute(SecurityAction.Demand,Flags = SecurityPermissionFlag.UnmanagedCode)]
public class X509TokenManager : Microsoft.Web.Services3.Security.Tokens.X509SecurityTokenManager
{
    public X509TokenManager() : base()
    {
        throw new NotImplementedException("Stub");
    }

    public X509TokenManager(XmlNodeList configData) : base(configData)
    {
        throw new NotImplementedException("Stub");
    }

    protected override void AuthenticateToken(X509SecurityToken token)
    {
        base.AuthenticateToken(token);
        throw new NotImplementedException("Stub");
    }
}
}

我的 web.config 的前几行,为简洁而编辑

<?xml version="1.0"?>
  <configuration><configSections><section name="microsoft.web.services3" type="..." />
  </configSections>
  <microsoft.web.services3>
    <policy fileName="wse3policyCache.config" />
    <security>
      <binarySecurityTokenManager>
        <add type="RDI.Server.X509TokenManager" valueType="http://docs.oasis-open.org/..." />
      </binarySecurityTokenManager>
    </security>
  </microsoft.web.services3>`

(顺便说一句,stackoverflow 上的一种 xml 格式如何很好地进行?)

Administration.AdministrationWse test = new TestConnector.Administration.AdministrationWse();

X509Certificate2 cert = GetCert("RDIDemoUser2");
X509SecurityToken x509Token = new X509SecurityToken(cert);
test.SetPolicy("X509");
test.SetClientCredential(x509Token);

string message = test.Ping("foo");

Console.WriteLine(message);

我暂时停留在 .NET 2.0 (VS2005),所以我认为 WCF 是不可能的,否则互操作性不是问题,因为我将控制系统中的客户端和服务。

【问题讨论】:

    标签: c# web-services certificate x509


    【解决方案1】:

    问题出在其他地方。我的服务器项目是一个网络应用程序,某些选项不适用于仅适用于网站的网络应用程序。所以我做了一个小型网站项目并比较了 web.configs 并注意到有些行有差异。

    这些行在网站 web.config 中,但不在我的其他项目中

      <soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <soapExtensionImporterTypes>
        <add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </soapExtensionImporterTypes>
    

    添加这些行后,我得到了预期的错误。

    【讨论】:

      【解决方案2】:

      我知道不是特别有建设性的建议,但如果我是你,我会尽快离开 WSE3.0。今年早些时候,我们做了一些工作,试图让它与 WCF 和 Java 客户端互操作,但它是一个过时的 KNIGHTMARE。

      另一方面,WCF 实际上是理智的,关于此类领域的文档非常好。这对你来说是一个选择吗?

      【讨论】:

        猜你喜欢
        • 2014-10-09
        • 2013-10-10
        • 2021-05-13
        • 2010-10-04
        • 2017-05-12
        • 1970-01-01
        • 2020-08-21
        • 2017-04-05
        • 1970-01-01
        相关资源
        最近更新 更多