mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 02:29:24 +08:00
转移.net core 3.1,为.NET 5做准备
This commit is contained in:
59
OpenAuth.App/AuthContextFactory.cs
Normal file
59
OpenAuth.App/AuthContextFactory.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : 李玉宝
|
||||
// Created : 07-05-2018
|
||||
//
|
||||
// Last Modified By : 李玉宝
|
||||
// Last Modified On : 07-05-2018
|
||||
// ***********************************************************************
|
||||
// <copyright file="AuthContextFactory.cs" company="OpenAuth.App">
|
||||
// Copyright (c) http://www.openauth.me. All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// 用户权限策略工厂
|
||||
//</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
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;
|
||||
private readonly IUnitWork _unitWork;
|
||||
|
||||
public AuthContextFactory(SystemAuthStrategy sysStrategy
|
||||
, NormalAuthStrategy normalAuthStrategy
|
||||
, IUnitWork 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;
|
||||
service.User = _unitWork.FindSingle<User>(u => u.Account == username);
|
||||
}
|
||||
|
||||
return new AuthStrategyContext(service);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user