CustomUserNameSecurityTokenAuthenticator.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Selectors / CustomUserNameSecurityTokenAuthenticator.cs / 1305376 / CustomUserNameSecurityTokenAuthenticator.cs

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

namespace System.IdentityModel.Selectors 
{
    using System.Collections.Generic; 
    using System.Collections.ObjectModel; 
    using System.IdentityModel.Claims;
    using System.IdentityModel.Policy; 
    using System.IdentityModel.Tokens;
    using System.Security.Principal;

    public class CustomUserNameSecurityTokenAuthenticator : UserNameSecurityTokenAuthenticator 
    {
        UserNamePasswordValidator validator; 
 
        public CustomUserNameSecurityTokenAuthenticator(UserNamePasswordValidator validator)
        { 
            if (validator == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("validator");
            this.validator = validator;
        } 

        protected override ReadOnlyCollection ValidateUserNamePasswordCore(string userName, string password) 
        { 
            this.validator.Validate(userName, password);
            return SecurityUtils.CreateAuthorizationPolicies(new UserNameClaimSet(userName, validator.GetType().Name)); 
        }

        class UserNameClaimSet : DefaultClaimSet, IIdentityInfo
        { 
            IIdentity identity;
 
            public UserNameClaimSet(string userName, string authType) 
            {
                if (userName == null) 
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("userName");

                this.identity = SecurityUtils.CreateIdentity(userName, authType);
 
                List claims = new List(2);
                claims.Add(new Claim(ClaimTypes.Name, userName, Rights.Identity)); 
                claims.Add(Claim.CreateNameClaim(userName)); 
                Initialize(ClaimSet.System, claims);
            } 

            public IIdentity Identity
            {
                get { return this.identity; } 
            }
        } 
    } 
}

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

namespace System.IdentityModel.Selectors 
{
    using System.Collections.Generic; 
    using System.Collections.ObjectModel; 
    using System.IdentityModel.Claims;
    using System.IdentityModel.Policy; 
    using System.IdentityModel.Tokens;
    using System.Security.Principal;

    public class CustomUserNameSecurityTokenAuthenticator : UserNameSecurityTokenAuthenticator 
    {
        UserNamePasswordValidator validator; 
 
        public CustomUserNameSecurityTokenAuthenticator(UserNamePasswordValidator validator)
        { 
            if (validator == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("validator");
            this.validator = validator;
        } 

        protected override ReadOnlyCollection ValidateUserNamePasswordCore(string userName, string password) 
        { 
            this.validator.Validate(userName, password);
            return SecurityUtils.CreateAuthorizationPolicies(new UserNameClaimSet(userName, validator.GetType().Name)); 
        }

        class UserNameClaimSet : DefaultClaimSet, IIdentityInfo
        { 
            IIdentity identity;
 
            public UserNameClaimSet(string userName, string authType) 
            {
                if (userName == null) 
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("userName");

                this.identity = SecurityUtils.CreateIdentity(userName, authType);
 
                List claims = new List(2);
                claims.Add(new Claim(ClaimTypes.Name, userName, Rights.Identity)); 
                claims.Add(Claim.CreateNameClaim(userName)); 
                Initialize(ClaimSet.System, claims);
            } 

            public IIdentity Identity
            {
                get { return this.identity; } 
            }
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

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