Jul 12, 2011 at 3:45 PM
Edited Jul 12, 2011 at 3:46 PM
I have a custom channel which handles session authentication. It simply looks for a session header, uses the application's security manager which in turn uses the cache manager to look-up a valid cache entry for the session id. Returns the cache item
(IPrincipal) if found, and sets the Thread.CurrentPrincipal accordingly.
Everything works perfectly it seems. The principal gets set. The request hits the correct service operation. I can authorize the request further on based upon the Thread's principal. The response gets json serialized into a stream.
However, no response ever makes it back to the user.
If I comment out the line "Thread.CurrentPrincipal = authenticatedUserPrincipal;", than everything works correctly and I get my 200 OK response with the serialized data. As soon as I set the CurrentPrincipal, the response just hangs even though
the everything seems to work as it should.
Does anyone have any ideas?
internal class ApiSessionAuthenticationChannel : DelegatingChannel
/// Sends the async request.
/// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns><see cref="Task<HttpResponseMessage>"/> instance to send.</returns>
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
var securityManager = _Container.Resolve<ISecurityManager>();
// TODO: (DG) Figure out how client will be calling the network services!
if (request.Headers.TryGetValues("NetworkSession", out sessions))
var authenticatedUserPrincipal = securityManager.GetPrincipal(new GenericToken(sessions.First()));
if (authenticatedUserPrincipal != null)
Thread.CurrentPrincipal = authenticatedUserPrincipal;
return base.SendAsync(request, cancellationToken);