WCF - Transport Authentication - Get Credentials of Authenticated User

大城市里の小女人 提交于 2020-01-25 06:21:26

问题


I have a NetTcpBinding with SecurityMode.TransportWithMessageCredential.

Transport.ClientCredentialType is set to MessageCredentialType.Windows, but I'm considering MessageCredentialType.UserName.

Then there's a class DataStoreServerProxy for fetching database data which implements IDataStoreContract.

It contains methods such as this one:

Private Function Common_IDataStoreContract_ModifyData(ByVal ParamArray dmlStatements As ModificationStatement()) As ModificationResult Implements IDataStoreContract.ModifyData
        Return wrappedDataStore.ModifyData(dmlStatements)
    End Function

In order to get to that DB point, user must have already supplied the credentials. The question is, how to obtain them in those methods? Depending on the user name, I have to decide whether to allow access to some tables or not.


回答1:


Username can be retrieved using OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name



来源:https://stackoverflow.com/questions/3244735/wcf-transport-authentication-get-credentials-of-authenticated-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!