【问题标题】:How do I cause SecurityTokenServiceConfiguration to load configuration information from the app.config?如何使 SecurityTokenServiceConfiguration 从 app.config 加载配置信息?
【发布时间】:2013-01-09 18:55:28
【问题描述】:

我正在使用 .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 传递给SecurityTokenServiceConfiguration 构造函数的loadConfig 参数,文档中说:

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

我的配置文件中有一个identityConfiguration 元素,但它似乎没有被加载。我可以更改配置文件 f.e.我可以更改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>

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

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

【问题讨论】:

  • 我撤回了我的回答,因为你不喜欢它,但无论如何都会尽力帮助你:Thinktecture 的东西只是你正在使用的东西的包装器,not需要编程配置。它具有广泛的基于文件的配置机制。
  • Thinktecture 的东西使用程序化配置。不管那个程序化配置是否由配置文件驱动,它仍然是程序化配置。我想使用内置的xml配置基础设施。

标签: c# wcf wif sts-securitytokenservice


【解决方案1】:

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

//
// 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);

【讨论】:

  • 您能否详细说明它与public SecurityTokenServiceConfiguration(bool loadConfig) 的行为有何不同?无论我使用此构造函数还是您在此处提出的构造函数,我都会得到相同的结果:我的配置部分未加载。
猜你喜欢
  • 1970-01-01
  • 2013-06-05
  • 2018-01-07
  • 2012-05-31
  • 1970-01-01
  • 2013-01-05
  • 1970-01-01
  • 2019-09-28
  • 2010-11-25
相关资源
最近更新 更多