3

我正在使用 .NET 4.5 中包含的 WIF 框架创建 STS。我正在使用WSTrustServiceHost该类自行托管此 STS(目前)。为此,我正在执行以下操作:

var conf = new SecurityTokenServiceConfiguration("isser name here", true)
{
    DisableWsdl          = true,
    SecurityTokenService = typeof(MyTokenService),
};
var ct   = new WSTrustServiceContract(conf);
var host = new WSTrustServiceHost(ct);

host.Open();
// ...

如您所见,我正在传递true给构造函数的loadConfig参数,SecurityTokenServiceConfiguration文档中说:

true从配置文件加载设置;否则为假

我的配置文件中有一个identityConfiguration元素,但似乎没有加载。我可以更改配置文件,我可以securityTokenHandlers更改SecurityTokenServiceConfiguration.

在我的 app.config 文件中,我有以下内容:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="sts_behavior">
                <serviceCredentials useIdentityConfiguration="true" identityConfiguration="the_issuer_id">
                    <serviceCertificate findValue="7A5D7EB05EC741E45BF4EDA7E574F58DC31EF290" x509FindType="FindByThumbprint" storeName="My" storeLocation="LocalMachine" />
                </serviceCredentials>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <ws2007HttpBinding>
            <binding name="sts_binding">
                <security mode="Message">
                    <message clientCredentialType="UserName" />
                </security>
            </binding>
        </ws2007HttpBinding>
    </bindings>
    <services>
        <service name="System.ServiceModel.Security.WSTrustServiceContract" behaviorConfiguration="sts_behavior">
            <endpoint address="http://my-machine:54512/tokens" binding="ws2007HttpBinding" contract="System.ServiceModel.Security.IWSTrust13SyncContract" bindingConfiguration="sts_binding" />
        </service>
    </services>
</system.serviceModel>

可以看到,<serviceCredentials>元素是指<identityConfiguration>配置文件中存在的元素,如果我将这个名称更改为与该<identityConfiguration>元素不匹配,则在打开服务主机时会引发错误。然而,这个<identityConfiguration>元素仍然没有被使用,因为我可以<clear/>使用安全令牌处理程序,并且当请求进来时仍然使用令牌处理程序。

如何以最少的编程配置配置和自托管自定义 STS?

4

1 回答 1

2

经过大量探索,我发现SecurityTokenServiceConfiguration构造函数的重载之一允许指定<identityConfiguration>从中加载配置的元素的名称:

//
// Summary:
//     Initializes a new instance of the System.IdentityModel.Configuration.SecurityTokenServiceConfiguration
//     class that has the specified issuer name and signing credentials. Settings
//     are loaded from the specified named configuration.
//
// Parameters:
//   issuerName:
//     The issuer name. Sets the System.IdentityModel.Configuration.SecurityTokenServiceConfiguration.TokenIssuerName
//     property.
//
//   signingCredentials:
//     The signing credentials for the STS. Sets the System.IdentityModel.Configuration.SecurityTokenServiceConfiguration.SigningCredentials
//     property.
//
//   serviceName:
//     The name of the <identityConfiguration> element from which the configuration
//     is to be loaded.
public SecurityTokenServiceConfiguration(string issuerName, SigningCredentials signingCredentials, string serviceName);
于 2013-01-28T17:43:50.210 回答