Click here to Skip to main content
15,886,362 members
Articles / Web Development / ASP.NET

ASP.NET TimeTracker Starter Kits Porting from Windows to Linux (Race to Linux)

Rate me:
Please Sign up or sign in to vote.
2.84/5 (9 votes)
5 Oct 20055 min read 70.5K   388   21  
ASP.NET TimeTracker Starter Kits Porting from Windows to Linux using Mainsoft's Grasshopper
using System;
using System.Security.Principal;

namespace ASPNET.StarterKit.TimeTracker.BusinessLogicLayer
{

	//*********************************************************************
	//
	// CustomPrincipal Class
	//
	// The CustomPrincipal class implements the IPrincipal interface so it 
	// can be used in place of the GenericPrincipal object.  Requirements for 
	// implementing the IPrincipal interface include implementing the
	// IIdentity interface and an implementation for IsInRole.  The custom
	// principal is attached to the current request in Global.asax in the
	// Authenticate_Request event handler.  The user's role is stored in the
	// custom principal object in the Global_AcquireRequestState event handler.
	// 
	//*********************************************************************

	public class CustomPrincipal : IPrincipal
	{
		private int		_userID;
		private string	_userRole = String.Empty;
		private string	_name;

		// Required to implement the IPrincipal interface.
		protected IIdentity _Identity;
		
		public CustomPrincipal()
		{
		}

		public CustomPrincipal(
			IIdentity identity, 
			int userID, 
			string userRole,
			string name)
		{
			_Identity = identity;
			_userID = userID;
			_userRole = userRole;
		}

		// IIdentity property used to retrieve the Identity object attached to
		// this principal.
		public IIdentity Identity
		{
			get	{ return _Identity; }
			set	{ _Identity = value; }
		}
		
		// The user's ID, created when the user was inserted into the database
		public int UserID
		{
			get { return _userID; }
			set { _userID = value; }
		}

		// The user's role, as defined in TTUser.
		public string UserRole
		{
			get { return _userRole; }
			set { _userRole = value; }
		}

		// The user's name (either First and Last name, or their network username)
		public string Name
		{
			get { return _name; }
			set { _name = value; }
		}

		//*********************************************************************
		//
		// Checks to see if the current user is a member of AT LEAST ONE of
		// the roles in the role string.  Returns true if found, otherwise false.
		// role is a comma-delimited list of role IDs.
		//
		//*********************************************************************

		public bool IsInRole(string role)
		{
			string [] roleArray = role.Split(new char[] {','});

			foreach (string r in roleArray)
			{
				if (_userRole == r)
					return true;
			}
			return false;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
Australia Australia
"Impossible" + "'" + " " = "I'm Possible"

Started programming when i was a kid with 286 computers and Spectrum using BASIC from 1986. There was series of languages like pascal, c, c++, ada, algol, prolog, assembly, java, C#, VB.NET and so on. Then shifted my intrest in Architecture during past 5 years with Rational Suite and UML. Wrote some articles, i was member of month on some sites, top poster(i only answer) of week (actually weeks), won some books as prizes, rated 2nd in ASP.NET and ADO.NET in Australia.

There is simplicity in complexity

Comments and Discussions