SslSecurityTokenParameters.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // SslSecurityTokenParameters.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 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.IdentityModel.Selectors;
  29. using System.IdentityModel.Tokens;
  30. using System.ServiceModel.Security;
  31. using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
  32. namespace System.ServiceModel.Security.Tokens
  33. {
  34. public class SslSecurityTokenParameters : SecurityTokenParameters
  35. {
  36. public SslSecurityTokenParameters ()
  37. : this (false, false)
  38. {
  39. }
  40. public SslSecurityTokenParameters (bool requireClientCertificate)
  41. : this (requireClientCertificate, false)
  42. {
  43. }
  44. public SslSecurityTokenParameters (bool requireClientCertificate,
  45. bool requireCancellation)
  46. {
  47. this.cert = requireClientCertificate;
  48. this.cancel = requireCancellation;
  49. }
  50. protected SslSecurityTokenParameters (SslSecurityTokenParameters source)
  51. : base (source)
  52. {
  53. cert = source.cert;
  54. cancel = source.cancel;
  55. }
  56. bool cert, cancel;
  57. public bool RequireClientCertificate {
  58. get { return cert; }
  59. set { cert = value; }
  60. }
  61. public bool RequireCancellation {
  62. get { return cancel; }
  63. set { cancel = value; }
  64. }
  65. [MonoTODO]
  66. public override string ToString ()
  67. {
  68. return base.ToString ();
  69. }
  70. protected override bool HasAsymmetricKey {
  71. get { return false; }
  72. }
  73. protected override bool SupportsClientAuthentication {
  74. get { return false; }
  75. }
  76. protected override bool SupportsClientWindowsIdentity {
  77. get { return false; }
  78. }
  79. protected override bool SupportsServerAuthentication {
  80. get { return true; }
  81. }
  82. protected override SecurityTokenParameters CloneCore ()
  83. {
  84. return new SslSecurityTokenParameters (this);
  85. }
  86. protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
  87. SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
  88. {
  89. if (token == null)
  90. throw new ArgumentNullException ("token");
  91. SecurityContextSecurityToken sct = token as SecurityContextSecurityToken;
  92. if (sct == null)
  93. throw new ArgumentException (String.Format ("Not supported SecurityToken: '{0}'", token));
  94. return referenceStyle == SecurityTokenReferenceStyle.Internal ?
  95. (SecurityKeyIdentifierClause)
  96. new LocalIdKeyIdentifierClause (sct.Id) :
  97. new SecurityContextKeyIdentifierClause (sct.ContextId, sct.KeyGeneration);
  98. /*
  99. GenericXmlSecurityToken x = token as GenericXmlSecurityToken;
  100. if (x == null)
  101. throw new ArgumentException (String.Format ("Not supported SecurityToken: '{0}'", token));
  102. return referenceStyle == SecurityTokenReferenceStyle.Internal ? x.InternalTokenReference : x.ExternalTokenReference;
  103. */
  104. }
  105. protected override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
  106. {
  107. requirement.TokenType =
  108. RequireClientCertificate ?
  109. ServiceModelSecurityTokenTypes.MutualSslnego :
  110. ServiceModelSecurityTokenTypes.AnonymousSslnego;
  111. requirement.RequireCryptographicToken = true;
  112. requirement.Properties [ReqType.SupportSecurityContextCancellationProperty] = RequireCancellation;
  113. requirement.Properties [ReqType.IssuedSecurityTokenParametersProperty] = this.Clone ();
  114. requirement.KeyType = SecurityKeyType.SymmetricKey;
  115. }
  116. }
  117. }