AuthContextFactory.cs
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ***********************************************************************
// <summary>
// 用户权限策略工厂
//</summary>
// ***********************************************************************
using WebRepository;
namespace WebApp
{
/// <summary>
/// 加载用户所有可访问的资源/机构/模块
/// </summary>
public class AuthContextFactory
{
private SystemAuthStrategy _systemAuth;
private NormalAuthStrategy _normalAuthStrategy;
private readonly IRepository<SysUser> _app;
public AuthContextFactory(SystemAuthStrategy sysStrategy
, NormalAuthStrategy normalAuthStrategy
, IRepository<SysUser> app)
{
_systemAuth = sysStrategy;
_normalAuthStrategy = normalAuthStrategy;
_app = app;
}
public AuthStrategyContext GetAuthStrategyContext(string username)
{
IAuthStrategy service = null;
if (username == "System")
{
service = _systemAuth;
return new AuthStrategyContext(service);
}
else
{
service = _normalAuthStrategy;
service.User = _app.FindSingle(u => u.Account == username);
return new AuthStrategyContext(service);
}
}
}
}