RoleProviderPrincipal.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 / Security / RoleProviderPrincipal.cs / 2 / RoleProviderPrincipal.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.ServiceModel.Security 
{
    using System; 
    using System.Runtime.CompilerServices; 
    using System.ServiceModel;
    using System.Security.Principal; 
    using System.ServiceModel.Security;
    using System.Web.Security;

    sealed class RoleProviderPrincipal : IPrincipal 
    {
        static bool defaultRoleProviderSet = false; 
        static object defaultRoleProvider; 

        object roleProvider; 
        ServiceSecurityContext securityContext;

        public RoleProviderPrincipal(object roleProvider, ServiceSecurityContext securityContext)
        { 
            this.roleProvider = roleProvider;
            this.securityContext = securityContext; 
        } 

        public IIdentity Identity 
        {
            get { return this.securityContext.PrimaryIdentity; }
        }
 
        [MethodImpl(MethodImplOptions.NoInlining)]
        public bool IsInRole(string role) 
        { 
            object roleProvider = this.roleProvider ?? GetRoleProvider();
            RoleProvider rp = roleProvider as RoleProvider; 
            if ( rp != null)
            {
                return rp.IsUserInRole(this.securityContext.PrimaryIdentity.Name, role);
            } 
            return false;
        } 
 
        // This method used to be static and had this comment, made instance as part of AH fix [[....]] 8/2008
        // Perf benefit: Roles.Enabled call is expensive due to CAS. 
        [MethodImpl(MethodImplOptions.NoInlining)]
        object GetRoleProvider()
        {
            if (!defaultRoleProviderSet) 
            {
                defaultRoleProvider = Roles.Enabled ? Roles.Provider : null; 
                defaultRoleProviderSet = true; 
            }
            return defaultRoleProvider; 
        }
    }
}

// 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