narsil/Tanshu.Accounts.Repository/BusinessLayer/RoleBI.cs
2011-03-12 17:12:02 +05:30

92 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Tanshu.Accounts.Repository
{
public delegate bool AuthenticateUser(out string userName);
public class RoleBI : IDisposable
{
string roleName;
int userID;
bool isAllowed;
//bool elevated;
//AccountsPrincipal originalUser;
//AuthenticateUser authenticateUser;
public RoleBI(string roleName, int userID)
{
this.roleName = roleName;
this.userID = userID;
if (userID == 0)
isAllowed = false;
else
isAllowed = MembershipBI.IsUserInRole(userID, this.roleName);
disposed = false;
}
public bool IsAllowed
{ get { return isAllowed; } }
//public bool IsElevated
//{
// get
// {
// return elevated;
// }
//}
//public void Evelvate(AuthenticateUser authenticateUser)
//{
// this.authenticateUser = authenticateUser;
// string userName;
// if (this.authenticateUser(out userName))
// {
// originalUser = (AccountsPrincipal)Thread.CurrentPrincipal;
// SetElevation(userName);
// }
//}
//private void SetElevation(string userName)
//{
// if (userName.Contains(":"))
// userName = userName.Substring(userName.IndexOf(":") + 1);
// Session.User = MembershipBI.GetUserFromName(userName));
// // bind the generic principal to the thread
// Thread.CurrentPrincipal = principal;
// userName = ((AccountsIdentity)principal.Identity).UserInfo.Name;
// userID = ((AccountsIdentity)principal.Identity).UserInfo.UserID;
// elevated = true;
//}
#region IDisposable
bool disposed;
~RoleBI()
{
// call Dispose with false. Since we're in the
// destructor call, the managed resources will be
// disposed of anyways.
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this.disposed)
{
//if (elevated)
// Thread.CurrentPrincipal = originalUser;
// Note disposing has been done.
disposed = true;
}
}
#endregion
}
}