ServiceWebSocketContext.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // <copyright>
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // </copyright>
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.Specialized;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Net.WebSockets;
  12. using System.Runtime;
  13. using System.Security.Principal;
  14. using System.Text;
  15. class ServiceWebSocketContext : WebSocketContext
  16. {
  17. WebSocketContext context;
  18. IPrincipal user;
  19. public ServiceWebSocketContext(WebSocketContext context, IPrincipal user)
  20. {
  21. Fx.Assert(context != null, "context should not be null.");
  22. this.context = context;
  23. this.user = user;
  24. }
  25. public override CookieCollection CookieCollection
  26. {
  27. get { return this.context.CookieCollection; }
  28. }
  29. public override NameValueCollection Headers
  30. {
  31. get { return this.context.Headers; }
  32. }
  33. public override bool IsAuthenticated
  34. {
  35. get { return this.user != null ? this.user.Identity != null && this.user.Identity.IsAuthenticated : this.context.IsAuthenticated; }
  36. }
  37. public override bool IsLocal
  38. {
  39. get { return this.context.IsLocal; }
  40. }
  41. public override bool IsSecureConnection
  42. {
  43. get { return this.context.IsSecureConnection; }
  44. }
  45. public override Uri RequestUri
  46. {
  47. get { return this.context.RequestUri; }
  48. }
  49. public override string SecWebSocketKey
  50. {
  51. get { return this.context.SecWebSocketKey; }
  52. }
  53. public override string Origin
  54. {
  55. get { return this.context.Origin; }
  56. }
  57. public override IEnumerable<string> SecWebSocketProtocols
  58. {
  59. get { return this.context.SecWebSocketProtocols; }
  60. }
  61. public override string SecWebSocketVersion
  62. {
  63. get { return this.context.SecWebSocketVersion; }
  64. }
  65. public override IPrincipal User
  66. {
  67. get { return this.user != null ? this.user : this.context.User; }
  68. }
  69. public override WebSocket WebSocket
  70. {
  71. get { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.GetString(SR.WebSocketContextWebSocketCannotBeAccessedError))); }
  72. }
  73. }
  74. }