Can a custom UserNamePasswordValidator add things to the WCF session?

梦想的初衷 提交于 2019-12-02 01:42:48

Yes, it can. You'll need:

  • a custom ServiceCredentials implementation that returns a custom SecurityTokenManager.
  • a custom SecurityTokenManager implementation that returns a custom CustomUserNameSecurityTokenAuthenticator.
  • your custom CustomUserNameSecurityTokenAuthenticator needs to override ValidateUserNamePasswordCore, and should add a custom implementation of IAuthorizationPolicy.
  • your implementation of IAuthorizationPolicy should implement Evaluate, at which point it can start putting things in the WCF context.
  • replace the evaluationContext["PrimaryIdentity"] value with a PasswordIdentity or a custom IIdentity.
  • replace the evaluationContext["Principal"] value with a PasswordPrincipal or a custom IPrincipal.
  • update the evaluationContext["Identities"] collection to replace the GenericIdentity instance with your custom instance.

By doing this, you can have a custom IPrincipal implementation with some extra information in it.

For more details, see this.

UserNamePasswordValidator is absolutely out of all WCF contexts. It is only used to validate user name and password. Can you futher explain your problem?

Edit: I guess COM object is instantiated for each session, isn't it? Otherwise wrapping COM into singleton should solve your problem. If you need to have per session COM object shared between validator and service instance you will need some cache or registry - something which is outside both validator and service and can be called from both of them.

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