2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.ServiceModel / System.ServiceModel.Security.Tokens / IssuedSecurityTokenProvider.cs
blob9e4e4663b1aa79d4c4ac437431fbdce89b9102a5
1 //
2 // IssuedSecurityTokenProvider.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
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.
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;
38 namespace System.ServiceModel.Security.Tokens
40 public class IssuedSecurityTokenProvider : SecurityTokenProvider, ICommunicationObject
42 public IssuedSecurityTokenProvider ()
46 IssuedTokenCommunicationObject comm =
47 new IssuedTokenCommunicationObject ();
49 SecurityKeyEntropyMode entropy_mode =
50 SecurityKeyEntropyMode.CombinedEntropy;
51 TimeSpan max_cache_time = TimeSpan.MaxValue;
52 MessageSecurityVersion version = MessageSecurityVersion.Default;
53 int threshold = 60;
54 IdentityVerifier verifier = IdentityVerifier.CreateDefault ();
55 bool cache_issued_tokens = true;
56 Collection<XmlElement> request_params =
57 new Collection<XmlElement> ();
59 CommunicationState state = CommunicationState.Created;
61 internal IssuedTokenCommunicationObject Communication {
62 get { return comm; }
65 public bool CacheIssuedTokens {
66 get { return cache_issued_tokens; }
67 set { cache_issued_tokens = value; }
70 public virtual TimeSpan DefaultCloseTimeout {
71 get { return comm.DefaultCloseTimeout; }
74 public virtual TimeSpan DefaultOpenTimeout {
75 get { return comm.DefaultOpenTimeout; }
78 public IdentityVerifier IdentityVerifier {
79 get { return verifier; }
80 set { verifier = value; }
83 public int IssuedTokenRenewalThresholdPercentage {
84 get { return threshold; }
85 set { threshold = value; }
88 public EndpointAddress IssuerAddress {
89 get { return comm.IssuerAddress; }
90 set { comm.IssuerAddress = value; }
93 public Binding IssuerBinding {
94 get { return comm.IssuerBinding; }
95 set { comm.IssuerBinding = value; }
98 public KeyedByTypeCollection<IEndpointBehavior> IssuerChannelBehaviors {
99 get { return comm.IssuerChannelBehaviors; }
102 public SecurityKeyEntropyMode KeyEntropyMode {
103 get { return entropy_mode; }
104 set { entropy_mode = value; }
107 public TimeSpan MaxIssuedTokenCachingTime {
108 get { return max_cache_time; }
109 set { max_cache_time = value; }
112 public MessageSecurityVersion MessageSecurityVersion {
113 get { return version; }
114 set { version = value; }
117 public SecurityAlgorithmSuite SecurityAlgorithmSuite {
118 get { return comm.SecurityAlgorithmSuite; }
119 set { comm.SecurityAlgorithmSuite = value; }
122 public SecurityTokenSerializer SecurityTokenSerializer {
123 get { return comm.SecurityTokenSerializer; }
124 set { comm.SecurityTokenSerializer = value; }
127 public EndpointAddress TargetAddress {
128 get { return comm.TargetAddress; }
129 set { comm.TargetAddress = value; }
132 public Collection<XmlElement> TokenRequestParameters {
133 get { return request_params; }
136 // SecurityTokenProvider
138 [MonoTODO ("support it then")]
139 public override bool SupportsTokenCancellation {
140 get { return true; }
143 [MonoTODO]
144 protected override SecurityToken GetTokenCore (TimeSpan timeout)
146 if (State != CommunicationState.Opened)
147 throw new InvalidOperationException ("Open the provider before issuing actual request to get token.");
148 return comm.GetToken (timeout);
151 [MonoTODO]
152 protected override IAsyncResult BeginGetTokenCore (
153 TimeSpan timeout,
154 AsyncCallback callback, object state)
156 throw new NotImplementedException ();
159 [MonoTODO]
160 protected override SecurityToken EndGetTokenCore (IAsyncResult result)
162 throw new NotImplementedException ();
165 // ICommunicationObject
167 public CommunicationState State {
168 get { return comm.State; }
171 [MonoTODO]
172 public void Abort ()
174 comm.Abort ();
177 public void Open ()
179 comm.Open ();
182 [MonoTODO]
183 public void Open (TimeSpan timeout)
185 comm.Open (timeout);
188 public IAsyncResult BeginOpen (AsyncCallback callback, object state)
190 return comm.BeginOpen (callback, state);
193 [MonoTODO]
194 public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
196 return comm.BeginOpen (timeout, callback, state);
199 [MonoTODO]
200 public void EndOpen (IAsyncResult result)
202 comm.EndOpen (result);
205 public void Close ()
207 comm.Close ();
210 [MonoTODO]
211 public void Close (TimeSpan timeout)
213 comm.Close (timeout);
216 public IAsyncResult BeginClose (AsyncCallback callback, object state)
218 return comm.BeginClose (callback, state);
221 [MonoTODO]
222 public IAsyncResult BeginClose (TimeSpan timeout, AsyncCallback callback, object state)
224 return comm.BeginClose (timeout, callback, state);
227 [MonoTODO]
228 public void EndClose (IAsyncResult result)
230 comm.EndClose (result);
233 public void Dispose ()
235 Close ();
238 public event EventHandler Opened {
239 add { comm.Opened += value; }
240 remove { comm.Opened -= value; }
242 public event EventHandler Opening {
243 add { comm.Opening += value; }
244 remove { comm.Opening -= value; }
246 public event EventHandler Closed {
247 add { comm.Closed += value; }
248 remove { comm.Closed -= value; }
250 public event EventHandler Closing {
251 add { comm.Closing += value; }
252 remove { comm.Closing -= value; }
254 public event EventHandler Faulted {
255 add { comm.Faulted += value; }
256 remove { comm.Faulted -= value; }