2009-08-04 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / SecurityHandler.cs
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;
7
8 namespace System.ServiceModel.Dispatcher
9 {
10         internal class SecurityHandler : BaseRequestProcessorHandler
11         {
12                 protected override bool ProcessRequest (MessageProcessingContext mrc)
13                 {
14                         DispatchRuntime dispatch_runtime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
15                         Message negoResponce = null;
16                         // process WS-Trust based negotiation
17                         MessageSecurityBindingSupport support =
18                                 dispatch_runtime.ChannelDispatcher.Listener.GetProperty<MessageSecurityBindingSupport> ();
19                         if (support != null && mrc.IncomingMessage.Headers.FindHeader ("Security", Constants.WssNamespace) < 0) {
20                                 CommunicationSecurityTokenAuthenticator nego =
21                                         support.TokenAuthenticator as CommunicationSecurityTokenAuthenticator;
22                                 if (nego != null)
23                                         negoResponce = nego.Communication.ProcessNegotiation (mrc.IncomingMessage);
24                         }
25
26                         if (negoResponce == null)
27                                 return false;
28                         
29                         ReplyNegoResponse (mrc, negoResponce);
30                         return true;
31
32                 }
33
34                 void ReplyNegoResponse (MessageProcessingContext mrc, Message negoResponse)
35                 {
36                         negoResponse.Headers.CopyHeadersFrom (mrc.OperationContext.OutgoingMessageHeaders);
37                         negoResponse.Properties.CopyProperties (mrc.OperationContext.OutgoingMessageProperties);                        
38                         mrc.RequestContext.Reply (negoResponse, mrc.Operation.Parent.ChannelDispatcher.timeouts.SendTimeout);
39                         return;
40                 }
41         }
42 }