2011-07-14 17 views
5

メッセージセキュリティモードと認証を使用して認証する2種類の認証:wcfのウィンドウとユーザー名を使用できます。自分のユーザー名認証CFG /コードが見えます:
サーバーのCFG:
WCF混合認証ユーザー名とウィンドウ

<?xml version="1.0"?> 
    <configuration> 
<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="ServiceCredentialsBehavior"> 
       <serviceCredentials> 
        <serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" /> 
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Util.CustomUserNameValidator, Util" /> 
       </serviceCredentials> 
       <serviceMetadata httpGetEnabled="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="ServiceCredentialsBehavior" name="Service"> 
      <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="MessageAndUserName"> 
       <security mode="Message"> 
        <message clientCredentialType="UserName"/> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client/> 
</system.serviceModel> 
<system.web> 
    <compilation debug="true"/> 
</system.web> 
</configuration> 

クライアントCFG:

<?xml version="1.0" encoding="utf-8"?> 
    <configuration> 
<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="LocalCertValidation"> 
       <clientCredentials> 
        <serviceCertificate> 
         <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" /> 
        </serviceCertificate> 
       </clientCredentials> 
      </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IService" > 
       <security mode="Message"> 
        <message clientCredentialType="UserName" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:48097/WCFServer/Service.svc" 
        binding="wsHttpBinding" 
        bindingConfiguration="WSHttpBinding_IService" 
        contract="ServiceReference1.IService" 
        name="WSHttpBinding_IService" behaviorConfiguration="LocalCertValidation"> 
      <identity> 
       <dns value ="cool" /> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 
</configuration> 

は何を変更するには、サーバーにアクセスするには、Windowsのアイデンティティを知るためには?

答えて

1

興味深い質問!本当に混在した認証が必要な場合は、トランスポートを1つの認証タイプとして設定し、メッセージを別の認証タイプとして設定できます。私はこれが実際に動作するかどうかは分かりませんが、別々に設定することができれば妥当と思われます:)

あなたのバインディングがWindows資格情報wsHttpBindingはWindows資格情報を処理できます)。

<security mode="Transport"> 
     <transport clientCredentialType="Whatever your authentication method is" /> 
     <message clientCredentialType="Windows" /> 
     </security> 

試してみると分かりますか?

EDIT:

ああ、according to the documentationそれは混合認証を行うことが可能です。あなたは「混在」にモードを設定する必要があり、その設定は次のようになります。

<security mode="mixed"> 
     <transport clientCredentialType="Whatever your authentication method is" /> 
     <message clientCredentialType="Windows" /> 
     </security> 

ドキュメントから:

混合セキュリティ。混在セキュリティでは、トランスポートセキュリティによってメッセージの整合性と機密性が保証され、ユーザーの資格情報と要求はメッセージセキュリティと同様にすべてのメッセージにカプセル化されます。これにより、厳密なトランスポートセキュリティメカニズムでは不可能なさまざまなユーザー資格情報を使用して、トランスポートセキュリティのパフォーマンスを活用できます。

+0

いいえ動作しません。 私は正しくWindows資格情報を設定していないかもしれませんし、サーバーから取得する方法もありますか? – croisharp

+0

本当に2つの異なる認証方法が必要ですか?クライアントのWindows資格情報をサービスに渡して、サービスを[ユーザーを偽装する]ようにすることができます(http://www.danrigsby.com/blog/index.php/2008/04/17/impersonate-a-clients- identity-in-wcf /)である。これは、認証タイプを混在させて一致させるよりも優れた解決策です。ユーザー名を確認する場合は、データベースに保存し、WindowsIdentity.GetCurrent()から返されたオブジェクトの偽装クライアントユーザーの詳細と比較することができます(ユーザー名を変更できるため、sidを格納する方が良いでしょう)。 ) – Franchesca

+0

はい私は2つの認証が必要です。メソッド+ NetSqlAzManとの認可が、私はすべての方法を知っている、これは混在認証で私の問題です.. – croisharp

関連する問題