97 lines
2.7 KiB
C#
97 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace Tanshu.Accounts.BI
|
|
{
|
|
public delegate bool AuthenticateUser(out string userName);
|
|
public class RoleBI : IDisposable
|
|
{
|
|
string roleID;
|
|
Guid userID;
|
|
//bool elevated;
|
|
//AccountsPrincipal originalUser;
|
|
//AuthenticateUser authenticateUser;
|
|
public RoleBI(string roleID, Guid userID)
|
|
{
|
|
this.roleID = roleID;
|
|
this.userID = userID;
|
|
//elevated = false;
|
|
//originalUser = null;
|
|
//authenticateUser = null;
|
|
disposed = false;
|
|
}
|
|
|
|
public bool IsAllowed
|
|
{
|
|
get
|
|
{
|
|
if (userID == new Guid())
|
|
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
|
|
}
|
|
}
|