SecurityHandler.cs 1.5 KB

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