WSFederationHttpSecurity.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / WSFederationHttpSecurity.cs / 1 / WSFederationHttpSecurity.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel
{ 
    using System.Diagnostics;
    using System.Net.Security; 
    using System.ServiceModel.Channels; 
    using System.ServiceModel.Security;
 
    public sealed class WSFederationHttpSecurity
    {
        internal const WSFederationHttpSecurityMode DefaultMode = WSFederationHttpSecurityMode.Message;
 
        WSFederationHttpSecurityMode mode;
        FederatedMessageSecurityOverHttp messageSecurity; 
 
        internal WSFederationHttpSecurity() : this(DefaultMode, new FederatedMessageSecurityOverHttp())
        { 
        }

        WSFederationHttpSecurity(WSFederationHttpSecurityMode mode, FederatedMessageSecurityOverHttp messageSecurity)
        { 
            DiagnosticUtility.DebugAssert(WSFederationHttpSecurityModeHelper.IsDefined(mode), string.Format("Invalid WSFederationHttpSecurityMode value: {0}", mode.ToString()));
 
            this.mode = mode; 
            this.messageSecurity = messageSecurity == null ? new FederatedMessageSecurityOverHttp() : messageSecurity;
        } 

        public WSFederationHttpSecurityMode Mode
        {
            get { return this.mode; } 
            set
            { 
                if (!WSFederationHttpSecurityModeHelper.IsDefined(value)) 
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); 
                }
                this.mode = value;
            }
        } 

        public FederatedMessageSecurityOverHttp Message 
        { 
            get { return this.messageSecurity; }
        } 

        internal SecurityBindingElement CreateMessageSecurity(bool isReliableSessionEnabled, MessageSecurityVersion version)
        {
            if (this.mode == WSFederationHttpSecurityMode.Message || this.mode == WSFederationHttpSecurityMode.TransportWithMessageCredential) 
            {
                return this.messageSecurity.CreateSecurityBindingElement(this.Mode == WSFederationHttpSecurityMode.TransportWithMessageCredential, isReliableSessionEnabled, version); 
            } 
            else
            { 
                return null;
            }
        }
 
        internal static bool TryCreate(SecurityBindingElement sbe,
                                       WSFederationHttpSecurityMode mode, 
                                       HttpTransportSecurity transportSecurity, 
                                       bool isReliableSessionEnabled,
                                       MessageSecurityVersion version, 
                                       out WSFederationHttpSecurity security)
        {
            security = null;
            FederatedMessageSecurityOverHttp messageSecurity = null; 
            if (sbe == null)
            { 
                mode = WSFederationHttpSecurityMode.None; 
            }
            else 
            {
                mode &= WSFederationHttpSecurityMode.Message | WSFederationHttpSecurityMode.TransportWithMessageCredential;
                DiagnosticUtility.DebugAssert(WSFederationHttpSecurityModeHelper.IsDefined(mode), string.Format("Invalid WSFederationHttpSecurityMode value: {0}", mode.ToString()));
 
                if (!FederatedMessageSecurityOverHttp.TryCreate(sbe, mode == WSFederationHttpSecurityMode.TransportWithMessageCredential, isReliableSessionEnabled, version, out messageSecurity))
                    return false; 
            } 
            security = new WSFederationHttpSecurity(mode, messageSecurity);
            return true; 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK