2020-10-22 14:59:36 +08:00
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// Assembly : OpenAuth.App
|
|
|
|
|
// Author : 李玉宝
|
|
|
|
|
// Created : 07-05-2018
|
|
|
|
|
//
|
|
|
|
|
// Last Modified By : 李玉宝
|
|
|
|
|
// Last Modified On : 07-05-2018
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// <copyright file="AuthContextFactory.cs" company="OpenAuth.App">
|
2021-07-22 19:33:55 +08:00
|
|
|
|
// Copyright (c) http://www.openauth.net.cn. All rights reserved.
|
2020-10-22 14:59:36 +08:00
|
|
|
|
// </copyright>
|
|
|
|
|
// <summary>
|
|
|
|
|
// 用户权限策略工厂
|
|
|
|
|
//</summary>
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
2021-01-14 23:35:54 +08:00
|
|
|
|
using Infrastructure;
|
2020-12-29 23:52:06 +08:00
|
|
|
|
using OpenAuth.Repository;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using OpenAuth.Repository.Domain;
|
|
|
|
|
using OpenAuth.Repository.Interface;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.App
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载用户所有可访问的资源/机构/模块
|
|
|
|
|
/// <para>李玉宝新增于2016-07-19 10:53:30</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AuthContextFactory
|
|
|
|
|
{
|
|
|
|
|
private SystemAuthStrategy _systemAuth;
|
|
|
|
|
private NormalAuthStrategy _normalAuthStrategy;
|
2020-12-29 23:52:06 +08:00
|
|
|
|
private readonly IUnitWork<OpenAuthDBContext> _unitWork;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
|
|
|
|
public AuthContextFactory(SystemAuthStrategy sysStrategy
|
|
|
|
|
, NormalAuthStrategy normalAuthStrategy
|
2020-12-29 23:52:06 +08:00
|
|
|
|
, IUnitWork<OpenAuthDBContext> unitWork)
|
2020-10-22 14:59:36 +08:00
|
|
|
|
{
|
|
|
|
|
_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;
|
2025-02-19 12:44:42 +08:00
|
|
|
|
service.User = _unitWork.FirstOrDefault<SysUser>(u => u.Account == username);
|
2020-10-22 14:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new AuthStrategyContext(service);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|