1.1K Star 4.9K Fork 1.8K

GVPdotNET China/OpenAuth.Net

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AuthContextFactory.cs 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
李玉宝 提交于 2025-02-19 12:44 +08:00 . 调整User为SysUser、Resource为SysResource
// ***********************************************************************
// 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.net.cn. All rights reserved.
// </copyright>
// <summary>
// 用户权限策略工厂
//</summary>
// ***********************************************************************
using Infrastructure;
using OpenAuth.Repository;
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<OpenAuthDBContext> _unitWork;
public AuthContextFactory(SystemAuthStrategy sysStrategy
, NormalAuthStrategy normalAuthStrategy
, IUnitWork<OpenAuthDBContext> 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.FirstOrDefault<SysUser>(u => u.Account == username);
}
return new AuthStrategyContext(service);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/dotnetchina/OpenAuth.Net.git
git@gitee.com:dotnetchina/OpenAuth.Net.git
dotnetchina
OpenAuth.Net
OpenAuth.Net
main

搜索帮助