ClientCredentials.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // ClientCredentials.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.Generic;
  30. using System.ServiceModel.Channels;
  31. using System.ServiceModel.Description;
  32. using System.ServiceModel.Dispatcher;
  33. using System.ServiceModel.Security;
  34. #if !NET_2_1
  35. using System.IdentityModel.Selectors;
  36. using System.IdentityModel.Tokens;
  37. using System.ServiceModel.Security.Tokens;
  38. #endif
  39. namespace System.ServiceModel.Description
  40. {
  41. public class ClientCredentials
  42. #if NET_2_1
  43. : IEndpointBehavior
  44. #else
  45. : SecurityCredentialsManager, IEndpointBehavior
  46. #endif
  47. {
  48. public ClientCredentials ()
  49. {
  50. }
  51. [MonoTODO]
  52. protected ClientCredentials (ClientCredentials source)
  53. {
  54. throw new NotImplementedException ();
  55. }
  56. UserNamePasswordClientCredential userpass =
  57. new UserNamePasswordClientCredential ();
  58. #if !NET_2_1
  59. IssuedTokenClientCredential issued_token =
  60. new IssuedTokenClientCredential ();
  61. HttpDigestClientCredential digest =
  62. new HttpDigestClientCredential ();
  63. X509CertificateInitiatorClientCredential initiator =
  64. new X509CertificateInitiatorClientCredential ();
  65. X509CertificateRecipientClientCredential recipient =
  66. new X509CertificateRecipientClientCredential ();
  67. WindowsClientCredential windows =
  68. new WindowsClientCredential ();
  69. PeerCredential peer = new PeerCredential ();
  70. bool support_interactive = true;
  71. public X509CertificateInitiatorClientCredential ClientCertificate {
  72. get { return initiator; }
  73. }
  74. public HttpDigestClientCredential HttpDigest {
  75. get { return digest; }
  76. }
  77. public IssuedTokenClientCredential IssuedToken {
  78. get { return issued_token; }
  79. }
  80. public PeerCredential Peer {
  81. get { return peer; }
  82. }
  83. public X509CertificateRecipientClientCredential ServiceCertificate {
  84. get { return recipient; }
  85. }
  86. public bool SupportInteractive {
  87. get { return support_interactive; }
  88. set { support_interactive = value; }
  89. }
  90. public WindowsClientCredential Windows {
  91. get { return windows; }
  92. }
  93. #endif
  94. public UserNamePasswordClientCredential UserName {
  95. get { return userpass; }
  96. }
  97. public ClientCredentials Clone ()
  98. {
  99. ClientCredentials ret = CloneCore ();
  100. if (ret.GetType () != GetType ())
  101. throw new NotImplementedException ("CloneCore() must be implemented to return an instance of the same type in this custom ClientCredentials type.");
  102. return ret;
  103. }
  104. protected virtual ClientCredentials CloneCore ()
  105. {
  106. return new ClientCredentials (this);
  107. }
  108. #if !NET_2_1
  109. public override SecurityTokenManager CreateSecurityTokenManager ()
  110. {
  111. return new ClientCredentialsSecurityTokenManager (this);
  112. }
  113. [MonoTODO]
  114. protected virtual SecurityToken GetInfoCardSecurityToken (
  115. bool requiresInfoCard, CardSpacePolicyElement [] chain,
  116. SecurityTokenSerializer tokenSerializer)
  117. {
  118. throw new NotImplementedException ();
  119. }
  120. void IEndpointBehavior.AddBindingParameters (ServiceEndpoint endpoint,
  121. BindingParameterCollection parameters)
  122. {
  123. parameters.Add (this);
  124. }
  125. void IEndpointBehavior.ApplyDispatchBehavior (ServiceEndpoint endpoint,
  126. EndpointDispatcher dispatcher)
  127. {
  128. // documented as to have no effect.
  129. }
  130. [MonoTODO]
  131. public virtual void ApplyClientBehavior (
  132. ServiceEndpoint endpoint, ClientRuntime behavior)
  133. {
  134. if (endpoint == null)
  135. throw new ArgumentNullException ("endpoint");
  136. if (behavior == null)
  137. throw new ArgumentNullException ("behavior");
  138. // FIXME: apply to endpoint when there is not security binding element.
  139. }
  140. void IEndpointBehavior.Validate (ServiceEndpoint endpoint)
  141. {
  142. // documented as reserved for future use.
  143. }
  144. #endif
  145. }
  146. }