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

88 lines
2.5 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
namespace Tanshu.Accounts.Repository
2010-03-02 17:56:21 +00:00
{
public delegate bool AuthenticateUser(out string userName);
public class RoleBI : IDisposable
{
readonly string _roleName;
int _userID;
readonly 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;
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
}
}