using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IdentityModel.Policy; using System.Linq; using System.Security.Authentication; using System.Security.Principal; using System.ServiceModel; using System.ServiceModel.Channels; using System.Text; using System.Threading; using GlobalCommonLib; namespace ServiceCommonLib { public class CentralUserIdentity : IIdentity { private readonly CentralRequestSession _session; public CentralUserIdentity(CentralRequestSession session) { this._session = session; } public string Name { get { return _session.UserName; } } public string AuthenticationType { get { return "Central"; } } public bool IsAuthenticated { get { return true; } } public CentralRequestSession Session { get { return _session; } } } public class CentralPrincipal : IPrincipal { readonly IIdentity _identity; string[] _roles = null; public CentralPrincipal(IIdentity identity) { this._identity = identity; } public static CentralPrincipal Current { get { return Thread.CurrentPrincipal as CentralPrincipal; } } public IIdentity Identity { get { return _identity; } } public string[] Roles { get { //Findout Role and set here return _roles; } } public bool IsInRole(string role) { //Findout Role and set here return true; } } public class CentralAuthenticationManager : ServiceAuthenticationManager { public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate(ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri, ref Message message) { var session = CredentialHelper.GetSessionData(message); CheckCredentials(session); var identity = new CentralUserIdentity(session); IPrincipal user = new CentralPrincipal(identity); message.Properties["Principal"] = user; return authPolicy; } public void CheckCredentials(CentralRequestSession credentials) { System.Console.WriteLine("Checking Credentils for {0}..........", credentials.UserName); // check the user and password against a database; // if not match // throw new AuthenticationException("Incorrect credentials!"); System.Console.WriteLine( "{0} is Valid!!", credentials.UserName); } } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
The Next Version of Android - Some of What's Coming