SecurityTokenParameters.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // SecurityTokenParameters.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.Channels;
  31. using System.ServiceModel.Security;
  32. using System.Text;
  33. namespace System.ServiceModel.Security.Tokens
  34. {
  35. public abstract class SecurityTokenParameters
  36. {
  37. protected SecurityTokenParameters ()
  38. {
  39. }
  40. protected SecurityTokenParameters (SecurityTokenParameters source)
  41. {
  42. }
  43. SecurityTokenInclusionMode inclusion_mode;
  44. SecurityTokenReferenceStyle reference_style;
  45. bool require_derived_keys = true;
  46. BindingContext issuer_binding_context;
  47. public SecurityTokenInclusionMode InclusionMode {
  48. get { return inclusion_mode; }
  49. set { inclusion_mode = value; }
  50. }
  51. public SecurityTokenReferenceStyle ReferenceStyle {
  52. get { return reference_style; }
  53. set { reference_style = value; }
  54. }
  55. public bool RequireDerivedKeys {
  56. get { return require_derived_keys; }
  57. set { require_derived_keys = value; }
  58. }
  59. public SecurityTokenParameters Clone ()
  60. {
  61. return CloneCore ();
  62. }
  63. public override string ToString ()
  64. {
  65. var sb = new StringBuilder ();
  66. sb.Append (GetType ().FullName).Append (":\n");
  67. foreach (var pi in GetType ().GetProperties ()) {
  68. var simple = Type.GetTypeCode (pi.PropertyType) != TypeCode.Object;
  69. var val = pi.GetValue (this, null);
  70. sb.Append (pi.Name).Append (':');
  71. if (val != null)
  72. sb.AppendFormat ("{0}{1}{2}", simple ? " " : "\n", simple ? "" : " ", String.Join ("\n ", val.ToString ().Split ('\n')));
  73. sb.Append ('\n');
  74. }
  75. sb.Length--; // chop trailing EOL.
  76. return sb.ToString ();
  77. }
  78. protected abstract bool HasAsymmetricKey { get; }
  79. protected abstract bool SupportsClientAuthentication { get; }
  80. protected abstract bool SupportsClientWindowsIdentity { get; }
  81. protected abstract bool SupportsServerAuthentication { get; }
  82. internal bool InternalHasAsymmetricKey {
  83. get { return HasAsymmetricKey; }
  84. }
  85. internal bool InternalSupportsClientAuthentication {
  86. get { return SupportsClientAuthentication; }
  87. }
  88. internal bool InternalSupportsClientWindowsIdentity {
  89. get { return SupportsClientWindowsIdentity; }
  90. }
  91. internal bool InternalSupportsServerAuthentication {
  92. get { return SupportsServerAuthentication; }
  93. }
  94. protected abstract SecurityTokenParameters CloneCore ();
  95. protected abstract SecurityKeyIdentifierClause CreateKeyIdentifierClause (
  96. SecurityToken token, SecurityTokenReferenceStyle referenceStyle);
  97. // internalized call to CreateKeyIdentifierClause()
  98. internal SecurityKeyIdentifierClause CallCreateKeyIdentifierClause (
  99. SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
  100. {
  101. return CreateKeyIdentifierClause (token, referenceStyle);
  102. }
  103. protected abstract void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement);
  104. internal BindingContext IssuerBindingContext {
  105. set { issuer_binding_context = value; }
  106. }
  107. internal void CallInitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
  108. {
  109. if (issuer_binding_context != null)
  110. requirement.Properties [ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty] = issuer_binding_context;
  111. InitializeSecurityTokenRequirement (requirement);
  112. }
  113. [MonoTODO]
  114. protected virtual bool MatchesKeyIdentifierClause (
  115. SecurityToken token,
  116. SecurityKeyIdentifierClause keyIdentifierClause,
  117. SecurityTokenReferenceStyle referenceStyle)
  118. {
  119. throw new NotImplementedException ();
  120. }
  121. }
  122. }