使用UserNameOverTransport保护Silverlight WCF SOAP服务通过HTTP工作以实现网络体系结构

时间:2011-02-23 23:19:07

标签: silverlight wcf security wcf-security

我有一个使用WCF SOAP服务的Silverlight 4应用程序。每次调用都会进行身份验证/授权(准RESTful)。这是通过使用authenticationMode = UserNameOverTransport来完成的 - 这基本上意味着该用户名/密码在每个WCF调用中,但受每个消息的SSL加密保护。这个方案的好处在于我可以在web.config中配置一个成员资格提供程序来进行身份验证,使其适用于不同的安装。

我有一个客户想要在他们的网络上设置这个网站,其中的方案是:Internet< = SSL Traffic =>面向外部SSL的转发服务器< =内部网络中的不安全HTTP =>托管我的应用程序的服务器他们向我保证这是一个常见的架构,我相信它们,我不是那个经验丰富的互联网应用程序开发人员。

由于我的应用程序设置为启用SSL的服务器(UserNameWithTransport通过SSL),我不知道该怎么办。在普通的HTTP我不知道如何获得我需要提供用户特定应用程序数据的用户名。 WCF不提供“UserNameWithNoTransport”authenticationMode,因为这意味着以纯文本形式发送用户名/密码,这很愚蠢。现在,我的服务器端代码从ServiceSecurityContext.Current.PrimaryIdentity.Name获取用户,因为他知道Web服务器已经处理了SSL加密和用户身份验证。如何以一种在HTTP解决方案中有意义的方式开展此工作?

我想要一个解决方案,允许我将我的解决方案配置为在web.config的HTTP和HTTPS情况下工作,如果这不可能得到任何其他建议。感谢

我会在几天内给这个问题一个赏金,如果你在那之前给出一个好的答案你就会得到它。

编辑:这是所要求的网络配置:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

  <system.web>
        <pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/>
    <membership defaultProvider="SampleProvider">
      <providers>
        <add name="SampleProvider" type="MyNamespace.NullMembershipProvider, MyDLL"/>
      </providers>
    </membership>    
  </system.web>

  <appSettings>
    ...
  </appSettings>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <bindings>
      <customBinding>
        <binding name="BinaryCustomBinding" sendTimeout="00:10:00">
          <security authenticationMode="UserNameOverTransport"/>
          <binaryMessageEncoding />
          <httpsTransport maxBufferSize="100000" maxReceivedMessageSize="100000" />
        </binding>
      </customBinding>
    </bindings>

    <services>
      <service name="MyNamespace.MyService">
        <endpoint
                    binding="customBinding" bindingConfiguration="BinaryCustomBinding"
                    name="MyService" contract="MyNamespace.IServiceContract" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata
            httpsGetEnabled="true"
            httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <userNameAuthentication
              userNamePasswordValidationMode="MembershipProvider"
              membershipProviderName="SampleProvider"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel> 


  <log4net>
...
  </log4net>
</configuration>

1 个答案:

答案 0 :(得分:2)

在.NET 4中允许UserNameOverTransport通过HTTP,但我认为在Silverlight中不可能。您需要设置security元素的allowInsecureTransport属性:

<customBinding>         
  <binding name="BinaryCustomBinding" sendTimeout="00:10:00">           
    <security authenticationMode="UserNameOverTransport" allowInsecureTranposrt="true"/>             
    <binaryMessageEncoding />           
    <httpTransport maxBufferSize="100000" maxReceivedMessageSize="100000" />           
  </binding>       
</customBinding>

问题在于allowInsecureTranposrtnot available in Silverlight。如果没有这个,你就不能在不安全的通道上使用UserName令牌。

相关问题