0

Webサービスで操作を呼び出す各クライアントがデータベースに対応するユーザー名とパスワードを持っていることを確認したいので、WCFサービスはカスタムメッセージベースのセキュリティにカスタム資格情報検証ツールを使用します。

Imports System.IdentityModel.Selectors
Imports System.IdentityModel.Tokens

Public Class CredentialsValidator
    Inherits UserNamePasswordValidator

    Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
        Dim authenticationApi As New AuthenticationGateway()
        If Not authenticationApi.IsValid(userName, password) Then
            Throw New SecurityTokenException("Validation Failed.")
        End If
    End Sub
End Class

つまり、ユーザーが認証に合格したら、OperationContract実装でuserNameを使用して、コンテキストベースの呼び出しを行います。

<ServiceContract(Name:="IMyService")> _
Public Interface IMyService
    <OperationContract()> _
    Function GetAccountNumber() As String
End Interface

Public Class IntegrationService
    Implements IIntegrationService

    Public Function GetAccountNumber() As String Implements IMyService.GetAccountNumber
        Dim userName As String '' Here I want the userName set from credentials
        Dim accountApi As New AccountGateway()
        Return accountApi.GetAccountNumber(userName)
    End Function
End Class

呼び出し先の正直さを信頼して実際のuserNameを指定することはできないため、パスワードも渡さずに渡すことはできません。Webサービスへのすべての呼び出しでClientCredentialsを受け入れる必要がないようにしたかったのです。

ありがとう。

4

1 に答える 1

1
Public Class IntegrationService
    Implements IIntegrationService

    Private ReadOnly Property UserName As String
        Get
            Return ServiceSecurityContext.Current.PrimaryIdentity.Name
        End Get
    End Property

    Public Function GetAccountNumber() As String Implements IMyService.GetAccountNumber
        Dim accountApi As New AccountGateway()
        Return accountApi.GetAccountNumber(UserName)
    End Function
End Class
于 2009-09-01T23:30:42.890 に答える