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

92 lines
2.6 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Tanshu.Accounts.Repository
2010-03-02 17:56:21 +00:00
{
public delegate bool AuthenticateUser(out string userName);
public class RoleBI : IDisposable
{
string roleName;
int userID;
bool isAllowed;
2011-01-06 07:17:00 +00:00
//bool elevated;
//AccountsPrincipal originalUser;
//AuthenticateUser authenticateUser;
public RoleBI(string roleName, int userID)
2010-03-02 17:56:21 +00:00
{
this.roleName = roleName;
2010-03-02 17:56:21 +00:00
this.userID = userID;
if (userID == 0)
isAllowed = false;
else
isAllowed = MembershipBI.IsUserInRole(userID, this.roleName);
2011-01-06 07:17:00 +00:00
disposed = false;
2010-03-02 17:56:21 +00:00
}
2010-03-02 17:56:21 +00:00
public bool IsAllowed
{ get { return isAllowed; } }
2010-03-02 17:56:21 +00:00
2011-01-06 07:17:00 +00:00
//public bool IsElevated
//{
// get
// {
// return elevated;
// }
//}
2010-03-02 17:56:21 +00:00
2011-01-06 07:17:00 +00:00
//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);
2010-03-02 17:56:21 +00:00
// Session.User = MembershipBI.GetUserFromName(userName));
2010-03-02 17:56:21 +00:00
2011-01-06 07:17:00 +00:00
// // bind the generic principal to the thread
// Thread.CurrentPrincipal = principal;
// userName = ((AccountsIdentity)principal.Identity).UserInfo.Name;
// userID = ((AccountsIdentity)principal.Identity).UserInfo.UserID;
// elevated = true;
//}
2010-03-02 17:56:21 +00:00
2011-01-06 07:17:00 +00:00
#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);
}
2010-03-02 17:56:21 +00:00
public void Dispose()
{
2011-01-06 07:17:00 +00:00
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this.disposed)
2010-03-02 17:56:21 +00:00
{
2011-01-06 07:17:00 +00:00
//if (elevated)
// Thread.CurrentPrincipal = originalUser;
// Note disposing has been done.
disposed = true;
2010-03-02 17:56:21 +00:00
}
}
2011-01-06 07:17:00 +00:00
#endregion
2010-03-02 17:56:21 +00:00
}
}