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

97 lines
2.7 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 roleID;
int userID;
2011-01-06 07:17:00 +00:00
//bool elevated;
//AccountsPrincipal originalUser;
//AuthenticateUser authenticateUser;
public RoleBI(string roleID, int userID)
2010-03-02 17:56:21 +00:00
{
this.roleID = roleID;
this.userID = userID;
2011-01-06 07:17:00 +00:00
//elevated = false;
//originalUser = null;
//authenticateUser = null;
disposed = false;
2010-03-02 17:56:21 +00:00
}
2011-01-06 07:17:00 +00:00
2010-03-02 17:56:21 +00:00
public bool IsAllowed
{
get
{
if (userID == 0)
2011-01-06 07:17:00 +00:00
return false;
2010-03-02 17:56:21 +00:00
return new MembershipBI().IsUserInRole(userID, roleID);
}
}
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
2011-01-06 07:17:00 +00:00
// Session.User = new 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
}
}