2009-09-01 3 views
0

내 웹 서비스에서 작업을 호출하는 각 클라이언트가 데이터베이스에서 해당 사용자 이름과 암호를 갖고 있으므로 WCF 서비스에서 사용자 지정 메시지 기반 보안에 사용자 지정 자격 증명 유효성 검사기를 사용합니다.WCF 작업에서 ClientCredentials 가져 오기

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 

은 또한 암호를 전달없이 통과 할 수 있도록 실제 사용자 이름을 지정하기 위해 호출 수신자의 정직에 의존하지 못할. ClientCredentials를 수락해야하는 웹 서비스에 대한 모든 호출을 피하기를 원했습니다.

감사합니다.

답변

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 
관련 문제