You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Infrastructure;
|
|
using OpenAuth.Repository;
|
|
using SqlSugar;
|
|
|
|
namespace OpenAuth.App
|
|
{
|
|
/// <summary>
|
|
/// 加载用户所有可访问的资源/机构/模块
|
|
/// <para>李玉宝新增于2016-07-19 10:53:30</para>
|
|
/// </summary>
|
|
public class AuthContextFactory
|
|
{
|
|
private SystemAuthStrategy _systemAuth;
|
|
private NormalAuthStrategy _normalAuthStrategy;
|
|
private readonly ISugarUnitOfWork<SugarDbContext> _unitWork;
|
|
|
|
public AuthContextFactory(SystemAuthStrategy sysStrategy
|
|
, NormalAuthStrategy normalAuthStrategy
|
|
, ISugarUnitOfWork<SugarDbContext> unitWork)
|
|
{
|
|
_systemAuth = sysStrategy;
|
|
_normalAuthStrategy = normalAuthStrategy;
|
|
_unitWork = unitWork;
|
|
}
|
|
|
|
public AuthStrategyContext GetAuthStrategyContext(string username)
|
|
{
|
|
if (string.IsNullOrEmpty(username)) return null;
|
|
|
|
IAuthStrategy service = null;
|
|
if (username == Define.SYSTEM_USERNAME)
|
|
{
|
|
service = _systemAuth;
|
|
}
|
|
else
|
|
{
|
|
service = _normalAuthStrategy;
|
|
//unitWork 是否自己释放
|
|
using (var uow = _unitWork.CreateContext())
|
|
{
|
|
service.User = uow.User.GetFirst(u => u.Account == username);
|
|
}
|
|
}
|
|
|
|
return new AuthStrategyContext(service);
|
|
}
|
|
}
|
|
} |