2 using System.Collections.Generic;
4 using System.ServiceModel.Channels;
5 using System.ServiceModel.Channels.Security;
6 using System.ServiceModel;
7 using System.ServiceModel.Security.Tokens;
9 namespace System.ServiceModel.Dispatcher
11 internal class SecurityHandler : BaseRequestProcessorHandler
13 protected override bool ProcessRequest (MessageProcessingContext mrc)
15 DispatchRuntime dispatch_runtime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
17 // FIXME: I doubt this should be done at this "handler"
18 // layer, especially considering about non-ServiceHost
19 // use of SecurityBindingElement + listener.
21 // For example there is no way to handle it in duplex
22 // dispatch callbacks.
23 if (dispatch_runtime.ChannelDispatcher == null)
26 Message negoResponce = null;
27 // process WS-Trust based negotiation
28 MessageSecurityBindingSupport support =
29 dispatch_runtime.ChannelDispatcher.Listener.GetProperty<MessageSecurityBindingSupport> ();
30 if (support != null && mrc.IncomingMessage.Headers.FindHeader ("Security", Constants.WssNamespace) < 0) {
31 CommunicationSecurityTokenAuthenticator nego =
32 support.TokenAuthenticator as CommunicationSecurityTokenAuthenticator;
34 negoResponce = nego.Communication.ProcessNegotiation (mrc.IncomingMessage);
37 if (negoResponce == null)
40 ReplyNegoResponse (mrc, negoResponce);
45 void ReplyNegoResponse (MessageProcessingContext mrc, Message negoResponse)
47 negoResponse.Headers.CopyHeadersFrom (mrc.OperationContext.OutgoingMessageHeaders);
48 negoResponse.Properties.CopyProperties (mrc.OperationContext.OutgoingMessageProperties);
49 mrc.RequestContext.Reply (negoResponse, mrc.Operation.Parent.ChannelDispatcher.timeouts.SendTimeout);