WCF Service - Custom Principal

大憨熊 提交于 2019-12-06 06:38:11

问题


In the constructor of my WCF service class I am setting the current principal to be that of the principal passed in the header of the message:

Thread.CurrentPrincipal = OperationContext.Current.IncomingMessageHeaders.GetHeader<BBPrincipal>("bbPrincipal", "ns");

This seems to work fine, however when I come to reference the principal in a method, the Thread.CurrentPrincipal has reverted to a WindowsPrincipal.

Presumably the method is firing on a different thread. How can I ensure that the method is using the principal set in the constructor of the service?


回答1:


I've just found the answer to my original question. In order to stop WCF overriding the principal with a blank one, set the following in the behavior configuration:

<serviceAuthorization principalPermissionMode="None" />

Simple as that and no need to made sweeping changes to the existing code base.

See: http://connect.microsoft.com/VisualStudio/feedback/details/369445/wcf-service-configured-for-transport-security-shouldnt-change-thread-currentprincipal




回答2:


WCF always sets principal in AuthorizationPolicy so it probably overwrites your changes. You should implement custom authorization policy and set principal there.



来源:https://stackoverflow.com/questions/3750016/wcf-service-custom-principal

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