SecurityTokenProvider.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // SecurityTokenProvider.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005 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.IdentityModel.Tokens;
  30. namespace System.IdentityModel.Selectors
  31. {
  32. public abstract class SecurityTokenProvider
  33. {
  34. protected SecurityTokenProvider ()
  35. {
  36. }
  37. public virtual bool SupportsTokenCancellation {
  38. get { return false; }
  39. }
  40. public virtual bool SupportsTokenRenewal {
  41. get { return false; }
  42. }
  43. public SecurityToken GetToken (TimeSpan timeout)
  44. {
  45. return GetTokenCore (timeout);
  46. }
  47. public IAsyncResult BeginGetToken (
  48. TimeSpan timeout, AsyncCallback callback, object state)
  49. {
  50. return BeginGetTokenCore (timeout, callback, state);
  51. }
  52. public SecurityToken EndGetToken (IAsyncResult result)
  53. {
  54. return EndGetTokenCore (result);
  55. }
  56. public void CancelToken (TimeSpan timeout, SecurityToken token)
  57. {
  58. CancelTokenCore (timeout, token);
  59. }
  60. public IAsyncResult BeginCancelToken (
  61. TimeSpan timeout, SecurityToken token,
  62. AsyncCallback callback, object state)
  63. {
  64. return BeginCancelTokenCore (timeout, token, callback, state);
  65. }
  66. public void EndCancelToken (IAsyncResult result)
  67. {
  68. EndCancelTokenCore (result);
  69. }
  70. public SecurityToken RenewToken (TimeSpan timeout, SecurityToken token)
  71. {
  72. return RenewTokenCore (timeout, token);
  73. }
  74. public IAsyncResult BeginRenewToken (
  75. TimeSpan timeout, SecurityToken token,
  76. AsyncCallback callback, object state)
  77. {
  78. return BeginRenewTokenCore (timeout, token, callback, state);
  79. }
  80. public SecurityToken EndRenewToken (IAsyncResult result)
  81. {
  82. return EndRenewTokenCore (result);
  83. }
  84. protected abstract SecurityToken GetTokenCore (TimeSpan timeout);
  85. protected virtual void CancelTokenCore (TimeSpan timeout, SecurityToken token)
  86. {
  87. throw new NotSupportedException (String.Format ("Token cancellation on this security token provider '{0}' is not supported.", this));
  88. }
  89. protected virtual SecurityToken RenewTokenCore (TimeSpan timeout, SecurityToken token)
  90. {
  91. throw new NotSupportedException (String.Format ("Token renewal on this security token provider '{0}' is not supported.", this));
  92. }
  93. [MonoTODO]
  94. protected virtual IAsyncResult BeginGetTokenCore (
  95. TimeSpan timeout,
  96. AsyncCallback callback, object state)
  97. {
  98. throw new NotImplementedException ();
  99. }
  100. protected virtual IAsyncResult BeginCancelTokenCore (
  101. TimeSpan timeout,
  102. SecurityToken token,
  103. AsyncCallback callback, object state)
  104. {
  105. throw new NotSupportedException (String.Format ("Token cancellation on this security token provider '{0}' is not supported.", this));
  106. }
  107. protected virtual IAsyncResult BeginRenewTokenCore (
  108. TimeSpan timeout,
  109. SecurityToken token,
  110. AsyncCallback callback, object state)
  111. {
  112. throw new NotSupportedException (String.Format ("Token renewal on this security token provider '{0}' is not supported.", this));
  113. }
  114. [MonoTODO]
  115. protected virtual SecurityToken EndGetTokenCore (IAsyncResult result)
  116. {
  117. throw new NotImplementedException ();
  118. }
  119. protected virtual void EndCancelTokenCore (IAsyncResult result)
  120. {
  121. throw new NotSupportedException (String.Format ("Token cancellation on this security token provider '{0}' is not supported.", this));
  122. }
  123. protected virtual SecurityToken EndRenewTokenCore (IAsyncResult result)
  124. {
  125. throw new NotSupportedException (String.Format ("Token renewal on this security token provider '{0}' is not supported.", this));
  126. }
  127. }
  128. }