IssuedSecurityTokenProvider.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // IssuedSecurityTokenProvider.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.Collections.Generic;
  29. using System.Collections.ObjectModel;
  30. using System.Xml;
  31. using System.IdentityModel.Selectors;
  32. using System.IdentityModel.Tokens;
  33. using System.ServiceModel;
  34. using System.ServiceModel.Channels;
  35. using System.ServiceModel.Description;
  36. using System.ServiceModel.Security;
  37. namespace System.ServiceModel.Security.Tokens
  38. {
  39. public class IssuedSecurityTokenProvider : SecurityTokenProvider, ICommunicationObject
  40. {
  41. public IssuedSecurityTokenProvider ()
  42. {
  43. }
  44. IssuedTokenCommunicationObject comm =
  45. new IssuedTokenCommunicationObject ();
  46. SecurityKeyEntropyMode entropy_mode =
  47. SecurityKeyEntropyMode.CombinedEntropy;
  48. TimeSpan max_cache_time = TimeSpan.MaxValue;
  49. MessageSecurityVersion version = MessageSecurityVersion.Default;
  50. int threshold = 60;
  51. IdentityVerifier verifier = IdentityVerifier.CreateDefault ();
  52. bool cache_issued_tokens = true;
  53. Collection<XmlElement> request_params =
  54. new Collection<XmlElement> ();
  55. CommunicationState state = CommunicationState.Created;
  56. internal IssuedTokenCommunicationObject Communication {
  57. get { return comm; }
  58. }
  59. public bool CacheIssuedTokens {
  60. get { return cache_issued_tokens; }
  61. set { cache_issued_tokens = value; }
  62. }
  63. public virtual TimeSpan DefaultCloseTimeout {
  64. get { return comm.DefaultCloseTimeout; }
  65. }
  66. public virtual TimeSpan DefaultOpenTimeout {
  67. get { return comm.DefaultOpenTimeout; }
  68. }
  69. public IdentityVerifier IdentityVerifier {
  70. get { return verifier; }
  71. set { verifier = value; }
  72. }
  73. public int IssuedTokenRenewalThresholdPercentage {
  74. get { return threshold; }
  75. set { threshold = value; }
  76. }
  77. public EndpointAddress IssuerAddress {
  78. get { return comm.IssuerAddress; }
  79. set { comm.IssuerAddress = value; }
  80. }
  81. public Binding IssuerBinding {
  82. get { return comm.IssuerBinding; }
  83. set { comm.IssuerBinding = value; }
  84. }
  85. public KeyedByTypeCollection<IEndpointBehavior> IssuerChannelBehaviors {
  86. get { return comm.IssuerChannelBehaviors; }
  87. }
  88. public SecurityKeyEntropyMode KeyEntropyMode {
  89. get { return entropy_mode; }
  90. set { entropy_mode = value; }
  91. }
  92. public TimeSpan MaxIssuedTokenCachingTime {
  93. get { return max_cache_time; }
  94. set { max_cache_time = value; }
  95. }
  96. public MessageSecurityVersion MessageSecurityVersion {
  97. get { return version; }
  98. set { version = value; }
  99. }
  100. public SecurityAlgorithmSuite SecurityAlgorithmSuite {
  101. get { return comm.SecurityAlgorithmSuite; }
  102. set { comm.SecurityAlgorithmSuite = value; }
  103. }
  104. public SecurityTokenSerializer SecurityTokenSerializer {
  105. get { return comm.SecurityTokenSerializer; }
  106. set { comm.SecurityTokenSerializer = value; }
  107. }
  108. public EndpointAddress TargetAddress {
  109. get { return comm.TargetAddress; }
  110. set { comm.TargetAddress = value; }
  111. }
  112. public Collection<XmlElement> TokenRequestParameters {
  113. get { return request_params; }
  114. }
  115. // SecurityTokenProvider
  116. [MonoTODO ("support it then")]
  117. public override bool SupportsTokenCancellation {
  118. get { return true; }
  119. }
  120. [MonoTODO]
  121. protected override SecurityToken GetTokenCore (TimeSpan timeout)
  122. {
  123. if (State != CommunicationState.Opened)
  124. throw new InvalidOperationException ("Open the provider before issuing actual request to get token.");
  125. return comm.GetToken (timeout);
  126. }
  127. [MonoTODO]
  128. protected override IAsyncResult BeginGetTokenCore (
  129. TimeSpan timeout,
  130. AsyncCallback callback, object state)
  131. {
  132. throw new NotImplementedException ();
  133. }
  134. [MonoTODO]
  135. protected override SecurityToken EndGetTokenCore (IAsyncResult result)
  136. {
  137. throw new NotImplementedException ();
  138. }
  139. // ICommunicationObject
  140. public CommunicationState State {
  141. get { return comm.State; }
  142. }
  143. [MonoTODO]
  144. public void Abort ()
  145. {
  146. comm.Abort ();
  147. }
  148. public void Open ()
  149. {
  150. comm.Open ();
  151. }
  152. [MonoTODO]
  153. public void Open (TimeSpan timeout)
  154. {
  155. comm.Open (timeout);
  156. }
  157. public IAsyncResult BeginOpen (AsyncCallback callback, object state)
  158. {
  159. return comm.BeginOpen (callback, state);
  160. }
  161. [MonoTODO]
  162. public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
  163. {
  164. return comm.BeginOpen (timeout, callback, state);
  165. }
  166. [MonoTODO]
  167. public void EndOpen (IAsyncResult result)
  168. {
  169. comm.EndOpen (result);
  170. }
  171. public void Close ()
  172. {
  173. comm.Close ();
  174. }
  175. [MonoTODO]
  176. public void Close (TimeSpan timeout)
  177. {
  178. comm.Close (timeout);
  179. }
  180. public IAsyncResult BeginClose (AsyncCallback callback, object state)
  181. {
  182. return comm.BeginClose (callback, state);
  183. }
  184. [MonoTODO]
  185. public IAsyncResult BeginClose (TimeSpan timeout, AsyncCallback callback, object state)
  186. {
  187. return comm.BeginClose (timeout, callback, state);
  188. }
  189. [MonoTODO]
  190. public void EndClose (IAsyncResult result)
  191. {
  192. comm.EndClose (result);
  193. }
  194. public void Dispose ()
  195. {
  196. Close ();
  197. }
  198. public event EventHandler Opened {
  199. add { comm.Opened += value; }
  200. remove { comm.Opened -= value; }
  201. }
  202. public event EventHandler Opening {
  203. add { comm.Opening += value; }
  204. remove { comm.Opening -= value; }
  205. }
  206. public event EventHandler Closed {
  207. add { comm.Closed += value; }
  208. remove { comm.Closed -= value; }
  209. }
  210. public event EventHandler Closing {
  211. add { comm.Closing += value; }
  212. remove { comm.Closing -= value; }
  213. }
  214. public event EventHandler Faulted {
  215. add { comm.Faulted += value; }
  216. remove { comm.Faulted -= value; }
  217. }
  218. }
  219. }