2011-02-23 11 views
1

こんにちは、各WCF Webサービス呼び出しでログイン情報を渡しますか?

私はWebサービス(percall)としてWCFを設定した、このWebサービスは、システムの広い範囲からの要求を取得します。今私たちはクライアントを特定するための何らかの方法が必要です。

CustomUserNamePasswordValidationを構築することは可能ですが、これにはセキュリティで保護された通信(SLL)が必要です。私たちの場合、セキュリティは必要なく、ソリューションはできるだけ簡単にセットアップする必要があります。

したがって、各呼び出しでクライアントの識別情報(ユーザ名/パスワード)を送信する方法は問題ですか?

headerに識別データを入れることができますが、例soupUIでこれをどのようにテストできるかわかりません。そして、通信するすべてのシステムがこれを問題なく処理できるかどうかはわかりませんか?

どのような訴訟ですか?

注意:私は1回の呼び出しをしたいので、ログインサービスの方法を使用する必要はありません。

答えて

1

WCFは、セキュリティで保護されていないユーザーの資格情報を送信するセンターサポートしません。これを解決するにはthe clear username bindingを使用するか、メッセージのヘッダーに資格情報を手動で追加してください(これはWCFでは簡単です)

0

のようにweb.configファイルに結合定義します。以下のようにカスタムの認証および承認のクラスを提供すると

<behavior name="Namespace.TestBehaviour"> 
     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" 
      customUserNamePasswordValidatorType="Namespace.ServiceSecurity.UserAuthenticator, Namespace" /> 
     </serviceCredentials> 
     <serviceAuthorization> 
     <authorizationPolicies> 
      <add policyType="Namespace.ServiceSecurity.MyAuthorizationPolicy, Namespace" /> 
     </authorizationPolicies> 
     </serviceAuthorization> 
    </behavior> 

その後のようなサービスの動作を定義

<basicHttpBinding> 
    <binding name="BasicAuthBinding"> 
     <security mode="Message"> 
     <message clientCredentialType="UserName"/> 
     </security> 
    </binding> 
    </basicHttpBinding> 

public class MyAuthorizationPolicy: IAuthorizationPolicy 
{ 
    public bool Evaluate(EvaluationContext evaluationContext, ref object state) 
    { 
     IList<IIdentity> identities = (IList<IIdentity>) evaluationContext.Properties["Identities"]; 

     foreach (IIdentity identity in identities) 
     { 
      if (identity.IsAuthenticated && 
       identity.AuthenticationType == "UserAuthenticator") 
      { 
       evaluationContext.Properties["Principal"] = identity.Name; 
       return true; 
      } 
     } 

     if (!evaluationContext.Properties.ContainsKey("Principal")) 
     { 
      evaluationContext.Properties["Principal"] = ""; 
     } 
     return false; 
    } 

    public ClaimSet Issuer 
    { 
     get { throw new NotImplementedException(); } 
    } 
} 

認証:

public class UserAuthenticator : UserNamePasswordValidator 
{ 
    public override void Validate(string userName, string password) 
    { 
     //authenticate me however you want 
     //then set whatever you want 
    } 
} 

あなたは、さらにセキュリティが必要な場合は、wsHttpBindingにbasicHttpBindingに変更し、証明書

EDITを使用するには:ほとんど定義されたサービスの動作を使用し、忘れてweb.configファイルでサービス・インターフェース定義に結合します。コンフィグで

public class WCF_Project_Authentification : UserNamePasswordValidator 
{ 
    #region UserNamePasswordValidator Interface Member 

    public override void Validate(string userName, string password) 
    { 
     if (userName != "Jeanc" || password != "fortin") 
     { 
      throw new FaultException("Authentification failed"); 
     } 
    } 
    #endregion 
} 

<behaviors> 
     <serviceBehaviors> 
     <behavior name="Service_Behavior"> 
      <serviceMetadata httpGetEnabled="False" httpsGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="True"/> 
      <serviceCredentials> 

      <userNameAuthentication userNamePasswordValidationMode="Custom" 
            customUserNamePasswordValidatorType="WcfService.Authentification.WCF_Project_Authentification, WcfService"/> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

そして、クライアントコードで:コードで

+0

>ありがとうございます!これを実装しましたが、サービスをブラウズするときに次の例外が発生しました。BasicHttpバインディングでは、BasicHttpBinding.Security.Message.ClientCredentialTypeが、セキュリティで保護されたメッセージのBasicHttpMessageCredentialType.Certificate資格情報タイプと同等である必要があります。 UserName資格情報の転送またはTransportWithMessageCredentialセキュリティを選択します。 – Banshee

+0

>私はこれへの結合を設定しようとしています <輸送clientCredentialTypeは=「基本」><バインディング名=「BasicAuthIntegration」> <セキュリティモード=「TransportCredentialOnly」> 、これはサービスが軌道に乗るだろうさ(ClientCredentials.UserName.UserNameとClientCredentials.UserName.Passwordを使用して)testclientからサービスを呼び出そうとすると、(クライアントで)この例外が発生します。クライアント認証スキーム「Basic」でHTTPリクエストが不正です。サーバーから受信した認証ヘッダーは 'Basic realm = "localhost"でした。 – Banshee

0

proxy.ClientCredentials.UserName.UserName = "Jeanc"; 
proxy.ClientCredentials.UserName.Password = "fortin"; 
+0

@ Jean-Chritophe>ありがとうございます。しかし、私は既にUserNamePasswordValidatorの使用方法を知っていますが、問題はクライアントのIDを渡す必要があることです。 – Banshee

関連する問題