| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- //----------------------------------------------------------------------------
- // Copyright (c) Microsoft Corporation. All rights reserved.
- //----------------------------------------------------------------------------
- namespace System.ServiceModel.Security
- {
- using System.ServiceModel.Channels;
- using System.ServiceModel;
- using System.ServiceModel.Diagnostics;
- using System.IdentityModel.Selectors;
- using System.Runtime.Diagnostics;
- class WrapperSecurityCommunicationObject : CommunicationObject
- {
- ISecurityCommunicationObject innerCommunicationObject;
- public WrapperSecurityCommunicationObject(ISecurityCommunicationObject innerCommunicationObject)
- : base()
- {
- if (innerCommunicationObject == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("innerCommunicationObject");
- }
- this.innerCommunicationObject = innerCommunicationObject;
- }
- protected override Type GetCommunicationObjectType()
- {
- return this.innerCommunicationObject.GetType();
- }
- protected override TimeSpan DefaultCloseTimeout
- {
- get { return this.innerCommunicationObject.DefaultCloseTimeout; }
- }
- protected override TimeSpan DefaultOpenTimeout
- {
- get { return this.innerCommunicationObject.DefaultOpenTimeout; }
- }
- protected override void OnAbort()
- {
- this.innerCommunicationObject.OnAbort();
- }
- protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return this.innerCommunicationObject.OnBeginClose(timeout, callback, state);
- }
- protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return this.innerCommunicationObject.OnBeginOpen(timeout, callback, state);
- }
- protected override void OnClose(TimeSpan timeout)
- {
- this.innerCommunicationObject.OnClose(timeout);
- }
- protected override void OnClosed()
- {
- this.innerCommunicationObject.OnClosed();
- base.OnClosed();
- }
- protected override void OnClosing()
- {
- this.innerCommunicationObject.OnClosing();
- base.OnClosing();
- }
- protected override void OnEndClose(IAsyncResult result)
- {
- this.innerCommunicationObject.OnEndClose(result);
- }
- protected override void OnEndOpen(IAsyncResult result)
- {
- this.innerCommunicationObject.OnEndOpen(result);
- }
- protected override void OnFaulted()
- {
- this.innerCommunicationObject.OnFaulted();
- base.OnFaulted();
- }
- protected override void OnOpen(TimeSpan timeout)
- {
- this.innerCommunicationObject.OnOpen(timeout);
- }
- protected override void OnOpened()
- {
- this.innerCommunicationObject.OnOpened();
- base.OnOpened();
- }
- protected override void OnOpening()
- {
- this.innerCommunicationObject.OnOpening();
- base.OnOpening();
- }
- new internal void ThrowIfDisposedOrImmutable()
- {
- base.ThrowIfDisposedOrImmutable();
- }
- }
- abstract class CommunicationObjectSecurityTokenProvider : SecurityTokenProvider, ICommunicationObject, ISecurityCommunicationObject
- {
- EventTraceActivity eventTraceActivity;
- WrapperSecurityCommunicationObject communicationObject;
- protected CommunicationObjectSecurityTokenProvider()
- {
- communicationObject = new WrapperSecurityCommunicationObject(this);
- }
- internal EventTraceActivity EventTraceActivity
- {
- get
- {
- if (eventTraceActivity == null)
- {
- eventTraceActivity = EventTraceActivity.GetFromThreadOrCreate();
- }
- return this.eventTraceActivity;
- }
- }
- protected WrapperSecurityCommunicationObject CommunicationObject
- {
- get { return this.communicationObject; }
- }
- public event EventHandler Closed
- {
- add { this.communicationObject.Closed += value; }
- remove { this.communicationObject.Closed -= value; }
- }
- public event EventHandler Closing
- {
- add { this.communicationObject.Closing += value; }
- remove { this.communicationObject.Closing -= value; }
- }
- public event EventHandler Faulted
- {
- add { this.communicationObject.Faulted += value; }
- remove { this.communicationObject.Faulted -= value; }
- }
- public event EventHandler Opened
- {
- add { this.communicationObject.Opened += value; }
- remove { this.communicationObject.Opened -= value; }
- }
- public event EventHandler Opening
- {
- add { this.communicationObject.Opening += value; }
- remove { this.communicationObject.Opening -= value; }
- }
- public CommunicationState State
- {
- get { return this.communicationObject.State; }
- }
- public virtual TimeSpan DefaultOpenTimeout
- {
- get { return ServiceDefaults.OpenTimeout; }
- }
- public virtual TimeSpan DefaultCloseTimeout
- {
- get { return ServiceDefaults.CloseTimeout; }
- }
- // communication object
- public void Abort()
- {
- this.communicationObject.Abort();
- }
- public void Close()
- {
- this.communicationObject.Close();
- }
- public void Close(TimeSpan timeout)
- {
- this.communicationObject.Close(timeout);
- }
- public IAsyncResult BeginClose(AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginClose(callback, state);
- }
- public IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginClose(timeout, callback, state);
- }
- public void EndClose(IAsyncResult result)
- {
- this.communicationObject.EndClose(result);
- }
- public void Open()
- {
- this.communicationObject.Open();
- }
- public void Open(TimeSpan timeout)
- {
- this.communicationObject.Open(timeout);
- }
- public IAsyncResult BeginOpen(AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginOpen(callback, state);
- }
- public IAsyncResult BeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginOpen(timeout, callback, state);
- }
- public void EndOpen(IAsyncResult result)
- {
- this.communicationObject.EndOpen(result);
- }
- public void Dispose()
- {
- this.Close();
- }
- // ISecurityCommunicationObject methods
- public virtual void OnAbort()
- {
- }
- public IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return new OperationWithTimeoutAsyncResult(new OperationWithTimeoutCallback(this.OnClose), timeout, callback, state);
- }
- public IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return new OperationWithTimeoutAsyncResult(new OperationWithTimeoutCallback(this.OnOpen), timeout, callback, state);
- }
- public virtual void OnClose(TimeSpan timeout)
- {
- }
- public virtual void OnClosed()
- {
- SecurityTraceRecordHelper.TraceTokenProviderClosed(this);
- }
- public virtual void OnClosing()
- {
- }
- public void OnEndClose(IAsyncResult result)
- {
- OperationWithTimeoutAsyncResult.End(result);
- }
- public void OnEndOpen(IAsyncResult result)
- {
- OperationWithTimeoutAsyncResult.End(result);
- }
- public virtual void OnFaulted()
- {
- this.OnAbort();
- }
- public virtual void OnOpen(TimeSpan timeout)
- {
- }
- public virtual void OnOpened()
- {
- SecurityTraceRecordHelper.TraceTokenProviderOpened(this.EventTraceActivity, this);
- }
- public virtual void OnOpening()
- {
- }
- }
- abstract class CommunicationObjectSecurityTokenAuthenticator : SecurityTokenAuthenticator, ICommunicationObject, ISecurityCommunicationObject
- {
- WrapperSecurityCommunicationObject communicationObject;
- protected CommunicationObjectSecurityTokenAuthenticator()
- {
- communicationObject = new WrapperSecurityCommunicationObject(this);
- }
- protected WrapperSecurityCommunicationObject CommunicationObject
- {
- get { return this.communicationObject; }
- }
- public event EventHandler Closed
- {
- add { this.communicationObject.Closed += value; }
- remove { this.communicationObject.Closed -= value; }
- }
- public event EventHandler Closing
- {
- add { this.communicationObject.Closing += value; }
- remove { this.communicationObject.Closing -= value; }
- }
- public event EventHandler Faulted
- {
- add { this.communicationObject.Faulted += value; }
- remove { this.communicationObject.Faulted -= value; }
- }
- public event EventHandler Opened
- {
- add { this.communicationObject.Opened += value; }
- remove { this.communicationObject.Opened -= value; }
- }
- public event EventHandler Opening
- {
- add { this.communicationObject.Opening += value; }
- remove { this.communicationObject.Opening -= value; }
- }
- public CommunicationState State
- {
- get { return this.communicationObject.State; }
- }
- public virtual TimeSpan DefaultOpenTimeout
- {
- get { return ServiceDefaults.OpenTimeout; }
- }
- public virtual TimeSpan DefaultCloseTimeout
- {
- get { return ServiceDefaults.CloseTimeout; }
- }
- // communication object
- public void Abort()
- {
- this.communicationObject.Abort();
- }
- public void Close()
- {
- this.communicationObject.Close();
- }
- public void Close(TimeSpan timeout)
- {
- this.communicationObject.Close(timeout);
- }
- public IAsyncResult BeginClose(AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginClose(callback, state);
- }
- public IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginClose(timeout, callback, state);
- }
- public void EndClose(IAsyncResult result)
- {
- this.communicationObject.EndClose(result);
- }
- public void Open()
- {
- this.communicationObject.Open();
- }
- public void Open(TimeSpan timeout)
- {
- this.communicationObject.Open(timeout);
- }
- public IAsyncResult BeginOpen(AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginOpen(callback, state);
- }
- public IAsyncResult BeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return this.communicationObject.BeginOpen(timeout, callback, state);
- }
- public void EndOpen(IAsyncResult result)
- {
- this.communicationObject.EndOpen(result);
- }
- public void Dispose()
- {
- this.Close();
- }
- // ISecurityCommunicationObject methods
- public virtual void OnAbort()
- {
- }
- public IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return new OperationWithTimeoutAsyncResult(new OperationWithTimeoutCallback(this.OnClose), timeout, callback, state);
- }
- public IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
- {
- return new OperationWithTimeoutAsyncResult(new OperationWithTimeoutCallback(this.OnOpen), timeout, callback, state);
- }
- public virtual void OnClose(TimeSpan timeout)
- {
- }
- public virtual void OnClosed()
- {
- SecurityTraceRecordHelper.TraceTokenAuthenticatorClosed(this);
- }
- public virtual void OnClosing()
- {
- }
- public void OnEndClose(IAsyncResult result)
- {
- OperationWithTimeoutAsyncResult.End(result);
- }
- public void OnEndOpen(IAsyncResult result)
- {
- OperationWithTimeoutAsyncResult.End(result);
- }
- public virtual void OnFaulted()
- {
- this.OnAbort();
- }
- public virtual void OnOpen(TimeSpan timeout)
- {
- }
- public virtual void OnOpened()
- {
- SecurityTraceRecordHelper.TraceTokenAuthenticatorOpened(this);
- }
- public virtual void OnOpening()
- {
- }
- }
- }
|