Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service - Custom Principal

Tags:

wcf

principal

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?

like image 778
David Ward Avatar asked Dec 17 '22 21:12

David Ward


1 Answers

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

like image 185
David Ward Avatar answered Jan 13 '23 03:01

David Ward