2014-03-25 51 views
0

我試圖在使用ADFS的WCF服務上添加基於聲明的安全性。我已經成功完成了Web應用程序(被動聯邦),但由於缺乏有關該主題的文檔,我發現自己陷入了困境。如何使用AD FS製作安全的WCF服務

我一直在玩Web.Config文件,使其工作...但是,我似乎只是從一個問題到下一個。這裏是客戶端web.config的安全部分:

<system.serviceModel> 
     <behaviors> 
     <endpointBehaviors> 
      <behavior> 
      <clientCredentials> 
       <serviceCertificate> 
       <authentication certificateValidationMode="None"/> 
       </serviceCertificate> 
      </clientCredentials> 
      </behavior> 
    </endpointBehaviors> 
     </behaviors> 
     <bindings> 
      <ws2007FederationHttpBinding> 
       <binding name="WS2007FederationHttpBinding_IService1"> 
        <security mode="Message"> 
         <message> 
          <issuer address="https://myIssuer/adfs/services/trust/13/windows" binding="basicHttpsBinding" /> 
          <issuerMetadata address="https://myIssuer/adfs/services/trust/mex" /> 
          <tokenRequestParameters> 
           <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"> 
            <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey</trust:KeyType> 
            <trust:KeySize xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">256</trust:KeySize> 
            <trust:KeyWrapAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p</trust:KeyWrapAlgorithm> 
            <trust:EncryptWith xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptWith> 
            <trust:SignWith xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2000/09/xmldsig#hmac-sha1</trust:SignWith> 
            <trust:CanonicalizationAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm> 
            <trust:EncryptionAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm> 
           </trust:SecondaryParameters> 
          </tokenRequestParameters> 
         </message> 
        </security> 
       </binding> 
      </ws2007FederationHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost/Services/Service1.svc" 
       binding="ws2007FederationHttpBinding" bindingConfiguration="WS2007FederationHttpBinding_IService1" 
       contract="ServiceRef.XISecurity.IService1" name="WS2007FederationHttpBinding_IService1" /> 
     </client> 
    </system.serviceModel> 

我不確定我是否在這裏使用正確的綁定類型或端點。當我運行下面的代碼:

 Service1Client obj = new Service1Client(); 
    string str = obj.GetData(5); 

我得到以下異常:

尋址版本 'AddressingNone(http://schemas.microsoft.com/ws/2005/05/addressing/none)' 不被支持。有一個很好的,一步一步的教程就如何建立我的web.config文件是:

這是我在服務器端

<configuration> 
    <configSections> 
    <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
    </configSections> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    <add key="ida:FederationMetadataLocation" value="https://myIssuer/FederationMetadata/2007-06/FederationMetadata.xml" /> 
    <add key="ida:ProviderSelection" value="productionSTS" /> 
    </appSettings> 
    <location path="FederationMetadata"> 
    <system.web> 
     <authorization> 
     <allow users="*" /> 
     </authorization> 
    </system.web> 
    </location> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
      <serviceCredentials useIdentityConfiguration="true"> 
      <!--Certificate added by Identity and Access Tool for Visual Studio.--> 
      <serviceCertificate findValue="CN=localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName" /> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add scheme="http" binding="ws2007FederationHttpBinding" /> 
     <!--<add binding="basicHttpsBinding" scheme="https" />--> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    <bindings> 
     <ws2007FederationHttpBinding> 
     <binding name=""> 
      <security mode="Message"> 
      <message> 
       <issuerMetadata address="https://myIssuer/adfs/services/trust/mex" /> 
      </message> 
      </security> 
     </binding> 
     </ws2007FederationHttpBinding> 
    </bindings> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true" /> 
    </system.webServer> 
    <system.identityModel> 
    <identityConfiguration> 
     <audienceUris> 
     <add value="http://localhost:2017/Service1.svc" /> 
     </audienceUris> 
     <issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry"> 
     <authority name="http://myIssuer/adfs/services/trust"> 
      <keys> 
      <add thumbprint="7502424014D0A1BD87A5DEEF0D1EB13390101F07" /> 
      </keys> 
      <validIssuers> 
      <add name="http://myIssuer/adfs/services/trust" /> 
      </validIssuers> 
     </authority> 
     </issuerNameRegistry> 
     <!--certificationValidationMode set to "None" by the the Identity and Access Tool for Visual Studio. For development purposes.--> 
     <certificateValidation certificateValidationMode="None" /> 
    </identityConfiguration> 
    </system.identityModel> 
</configuration> 

我的第一個問題是web.config文件?理想情況下,與.NET 4.5?

第二個問題:我很困惑要使用哪個綁定ADFS端點或綁定。這是它目前的設置。

<issuer address="https://myIssuer/adfs/services/trust/13/windows" binding="basicHttpsBinding" /> 

任何幫助將非常感激。謝謝

回答

0

在回答第二個問題時,您可以在端點http://technet.microsoft.com/en-us/library/adfs2-help-endpoints(WS.10).aspx找到一些信息。端點基本上指定可用於與ADFS服務器進行通信的地址。端點類型還會告訴您一些有關其要求的內容,例如您是否需要提供證書或用戶名。
在端點和WIF綁定之間也有一個映射,位於http://blogs.msdn.com/b/alikl/archive/2011/10/01/how-to-use-ad-fs-endpoints-when-developing-claims-aware-wcf-services-using-wif.aspx。當我使用代碼而不是配置文件與端點通信時,這對我很有幫助。