2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.ServiceModel / System.ServiceModel.Dispatcher / SecurityHandler.cs
blob71f9da1e32a04437f1661b5ec7c31453ca600536
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.ServiceModel.Channels;
5 using System.ServiceModel;
6 using System.ServiceModel.Security.Tokens;
8 namespace System.ServiceModel.Dispatcher
10 internal class SecurityHandler : BaseRequestProcessorHandler
12 protected override bool ProcessRequest (MessageProcessingContext mrc)
14 DispatchRuntime dispatch_runtime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
16 // FIXME: I doubt this should be done at this "handler"
17 // layer, especially considering about non-ServiceHost
18 // use of SecurityBindingElement + listener.
20 // For example there is no way to handle it in duplex
21 // dispatch callbacks.
22 if (dispatch_runtime.ChannelDispatcher == null)
23 return false;
25 Message negoResponce = null;
26 // process WS-Trust based negotiation
27 MessageSecurityBindingSupport support =
28 dispatch_runtime.ChannelDispatcher.Listener.GetProperty<MessageSecurityBindingSupport> ();
29 if (support != null && mrc.IncomingMessage.Headers.FindHeader ("Security", Constants.WssNamespace) < 0) {
30 CommunicationSecurityTokenAuthenticator nego =
31 support.TokenAuthenticator as CommunicationSecurityTokenAuthenticator;
32 if (nego != null)
33 negoResponce = nego.Communication.ProcessNegotiation (mrc.IncomingMessage);
36 if (negoResponce == null)
37 return false;
39 ReplyNegoResponse (mrc, negoResponce);
40 return true;
44 void ReplyNegoResponse (MessageProcessingContext mrc, Message negoResponse)
46 negoResponse.Headers.CopyHeadersFrom (mrc.OperationContext.OutgoingMessageHeaders);
47 negoResponse.Properties.CopyProperties (mrc.OperationContext.OutgoingMessageProperties);
48 mrc.RequestContext.Reply (negoResponse, mrc.Operation.Parent.ChannelDispatcher.timeouts.SendTimeout);
49 return;