narsil/Tanshu.Accounts.SqlDAO/BusinessLayer/RoleBI.cs

97 lines
2.7 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 roleID;
int userID;
//bool elevated;
//AccountsPrincipal originalUser;
//AuthenticateUser authenticateUser;
public RoleBI(string roleID, int userID)
{
this.roleID = roleID;
this.userID = userID;
//elevated = false;
//originalUser = null;
//authenticateUser = null;
disposed = false;
}
public bool IsAllowed
{
get
{
if (userID == 0)
return false;
return new MembershipBI().IsUserInRole(userID, roleID);
}
}
//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 = new 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
}
}