2011-12-29 13 views
0

サーバー側でWCF Riaサービスを呼び出すユーザーを知りたいと思うことはありますか?クライアント側はsiverlightです。システムを使用するには、まずユーザーを認証する必要があります。クライアント側でSilverlightを使用して、どのユーザーがサーバー側でWCF Riaサービスを呼び出しているか知る必要はありますか?

実際に私の現在の仕事でどのユーザーがサービスを呼び出しているか知っておく必要があります。ありがとうございます。私は多くを検索しましたが、良い発見がないようです。

答えて

0

クライアント側が認証要求を正常にクリアすると、サーバーはクライアント側の呼び出し側にトークンを発行できます。その後のサーバー呼び出しでは、クライアントはトークンを引数の1つとして送信し、サーバーはトークンを検証してそれに応じて応答します。

トークンには、特定のユーザーを識別する情報セグメントを含めることができます。これを実装すると、探している機能が提供されます。

トークンを生成するための唯一のガイドラインは、一意で予測不可能であり、期限切れであることです。私はいつも私のトークンを暗号化しているので、彼らは不器用なように見えますが、これはオプションです。

0

私は解決策を得る前に、非常に「googleing」して頭痛をたくさん覚えました。 私はRIAサービスを使用しませんが、(うまくいけば)同じでなければなりません...:

SL-Clientはサーバに「ログイン要求」を送信します。 (WCF)サーバー側で

、私は(SL-ClientのLoginData =リターン・情報)次の操作を行います

public LoginData LoginRequest() { 
    (...) 
    OperationContext context = OperationContext.Current; 
    System.ServiceModel.Channels.MessageProperties prp = context.IncomingMessageProperties; 
    System.ServiceModel.Channels.RemoteEndpointMessageProperty endPrp = prp[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; 
     (...) 
     try { 
      clientIP = endPrp.Address; 
      System.Net.IPAddress ipAddress = System.Net.IPAddress.Parse(clientIP); 
      System.Net.IPHostEntry ipHostEntry = System.Net.Dns.GetHostEntry(ipAddress); 
     (...) 

あなたがユーザーにのWindowsPrincipalを確認したい場合は、次の操作を行うことができます(ユーザーがログインすることができsecurityGroup =サーバー側の設定):

(...) 
    switch (securityGroup) { 
      case SecurityGroup.AllClientsCanAccess: { 
       clientCanLogin = true; 
      } break; 
      case SecurityGroup.UseWindowsCredentials: { 
       if (OperationContext.Current.ServiceSecurityContext != null && OperationContext.Current.ServiceSecurityContext.WindowsIdentity != null) { 
         if (OperationContext.Current.ServiceSecurityContext.WindowsIdentity.IsAuthenticated) { 

          if (subSecurityInfo1 == true) { // only clients in specific roles can log in 
           bool userRoleFound = false; 

           WindowsPrincipal userPrincipal = new WindowsPrincipal(OperationContext.Current.ServiceSecurityContext.WindowsIdentity); 
           if (userPrincipal == null) 
            break; 

           foreach (string userRoleToPass in subSecurityList) { // subSecurityList = settings, which roles can pass 

            loginError.ErrorInfo += string.Format("{0}\n", userRoleToPass); 

            if (userPrincipal.IsInRole(userRoleToPass)) { 
             clientCanLogin = userRoleFound = true; 
             break; 
            } 
           } 

           if (userRoleFound) { 
            loginError.ErrorInfo = string.Empty; 
            break; 
           } 
           else { 
            loginError.ErrorNo = LoginErrorCodeNoEnum.UserIsNotInRole; 
           } 
          } 
          (...) 

はそれが役に立てば幸い...

関連する問題