Sparkdo.Security
1.0.1
.NET 10.0
This package targets .NET 10.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Sparkdo.Security --version 1.0.1
NuGet\Install-Package Sparkdo.Security -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sparkdo.Security" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sparkdo.Security" Version="1.0.1" />
<PackageReference Include="Sparkdo.Security" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sparkdo.Security --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Sparkdo.Security, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sparkdo.Security@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sparkdo.Security&version=1.0.1
#tool nuget:?package=Sparkdo.Security&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Sparkdo.Security
Sparkdo 安全模块,提供身份验证、授权、加密和安全日志等核心安全功能。
功能特性
- 用户身份管理(ICurrentUser)
- 客户端身份管理(ICurrentClient)
- 声明式权限控制
- 字符串加密服务
- 安全日志记录
- 模块化安全配置
安装
<PackageReference Include="Sparkdo.Security" Version="x.x.x" />
核心组件
用户和客户端管理
ICurrentUser: 访问当前认证用户信息ICurrentClient: 访问当前客户端信息
加密服务
IStringEncryptionService: 字符串加密和解密
安全日志
ISecurityLogManager: 安全日志管理ISecurityLogStore: 安全日志存储
模块配置
SparkdoSecurityModule: 自动注册安全服务
所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。
使用方法
基本身份信息访问
通过依赖注入获取当前用户信息:
public class MyService
{
private readonly ICurrentUser _currentUser;
public MyService(ICurrentUser currentUser)
{
_currentUser = currentUser;
}
public void DoSomething()
{
if (_currentUser.IsAuthenticated)
{
Console.WriteLine($"当前用户: {_currentUser.UserName}");
Console.WriteLine($"用户ID: {_currentUser.Id}");
Console.WriteLine($"用户角色: {string.Join(", ", _currentUser.Roles)}");
}
}
}
客户端身份信息访问
获取当前客户端信息:
public class MyService
{
private readonly ICurrentClient _currentClient;
public MyService(ICurrentClient currentClient)
{
_currentClient = currentClient;
}
public void DoSomething()
{
if (_currentClient.IsAuthenticated)
{
Console.WriteLine($"当前客户端ID: {_currentClient.Id}");
}
}
}
字符串加密
使用字符串加密服务:
public class MyService
{
private readonly IStringEncryptionService _encryptionService;
public MyService(IStringEncryptionService encryptionService)
{
_encryptionService = encryptionService;
}
public void EncryptData()
{
string plainText = "需要加密的数据";
string encrypted = _encryptionService.Encrypt(plainText);
string decrypted = _encryptionService.Decrypt(encrypted);
Console.WriteLine($"原文: {plainText}");
Console.WriteLine($"密文: {encrypted}");
Console.WriteLine($"解密: {decrypted}");
}
}
安全日志
记录安全相关操作:
public class MyService
{
private readonly ISecurityLogManager _securityLogManager;
public MyService(ISecurityLogManager securityLogManager)
{
_securityLogManager = securityLogManager;
}
public async Task DoSomethingAsync()
{
await _securityLogManager.SaveAsync(new SecurityLogInfo
{
Identity = "用户操作",
Action = "数据修改",
Message = "用户修改了重要数据",
Parameters = "相关参数"
});
}
}
核心接口
ICurrentUser
当前用户信息接口,提供对当前认证用户信息的访问:
IsAuthenticated: 是否已通过身份验证Id: 用户唯一标识UserName: 用户名Name: 用户姓名Roles: 用户角色列表FindClaim(): 查找特定声明IsInRole(): 检查用户是否在特定角色中
ICurrentClient
当前客户端信息接口,提供对当前客户端信息的访问:
Id: 客户端唯一标识IsAuthenticated: 客户端是否已认证
IStringEncryptionService
字符串加密服务接口:
Encrypt(): 加密字符串Decrypt(): 解密字符串
ISecurityLogManager
安全日志管理器接口:
SaveAsync(): 保存安全日志
配置选项
SparkdoStringEncryptionOptions
字符串加密选项配置:
{
"Sparkdo": {
"StringEncryption": {
"DefaultPassPhrase": "默认加密密钥",
"DefaultSalt": "默认盐值",
"KeySize": 256,
"InitVectorBytes": "初始化向量"
}
}
}
扩展性
可以通过以下方式扩展安全功能:
- 实现自定义的
ICurrentUser来提供特定的用户信息访问逻辑 - 实现自定义的
ICurrentClient来提供特定的客户端信息访问逻辑 - 实现自定义的
IStringEncryptionService来提供特定的加密算法 - 实现自定义的
ISecurityLogStore来改变安全日志的存储方式
代码结构说明
本项目包含以下主要组件:
用户和客户端管理
ICurrentUser和DefaultCurrentUser:用于访问当前认证用户的信息ICurrentClient和DefaultCurrentClient:用于访问当前客户端的信息CurrentUserExtensions:提供对当前用户声明信息的扩展方法
安全声明处理
ICurrentPrincipalAccessor:用于访问当前安全主体ISparkdoClaimsPrincipalFactory:用于创建声明主体SparkdoClaimTypes:定义了系统中使用的声明类型常量ClaimsIdentityExtensions:提供对声明身份的扩展方法
加密服务
IStringEncryptionService和DefaultStringEncryptionService:提供字符串的加密和解密功能SparkdoStringEncryptionOptions:配置加密服务的选项
安全日志
ISecurityLogManager和DefaultSecurityLogManager:用于管理安全日志ISecurityLogStore和SimpleSecurityLogStore:用于存储安全日志SecurityLogInfo:安全日志信息实体SparkdoSecurityLogOptions:安全日志配置选项
模块配置
SparkdoSecurityModule:安全模块的配置类,用于注册所有安全相关服务
所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- JetBrains.Annotations (>= 2025.2.2)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 10.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.0)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyModel (>= 10.0.0)
- Microsoft.Extensions.FileProviders.Physical (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Localization (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Nito.AsyncEx.Context (>= 5.1.2)
- Sparkdo.Core (>= 1.0.1)
- System.Linq.Dynamic.Core (>= 1.7.0)
- System.Runtime.Loader (>= 4.3.0)
- System.Text.Json (>= 10.0.0)
-
net10.0
- JetBrains.Annotations (>= 2025.2.2)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 10.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.0)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyModel (>= 10.0.0)
- Microsoft.Extensions.FileProviders.Physical (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Localization (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Nito.AsyncEx.Context (>= 5.1.2)
- Sparkdo.Core (>= 1.0.1)
- System.Linq.Dynamic.Core (>= 1.7.0)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Sparkdo.Security:
| Package | Downloads |
|---|---|
|
Sparkdo.Settings
Sparkdo 设置管理库,提供设置定义、设置值提供者、设置存储等设置管理功能 |
|
|
Sparkdo.MultiTenancy.Abstractions
Sparkdo 框架的多租户抽象实现。提供多租户功能的核心接口和抽象类定义。 |
|
|
Sparkdo.ExceptionHandling
Sparkdo 异常处理库,提供统一的异常处理机制和错误信息转换功能 |
|
|
Sparkdo.Auditing
Sparkdo 审计库,提供方法调用和实体变更的自动审计日志记录功能 |
|
|
Sparkdo.Features
Sparkdo 功能系统库,提供功能定义、管理、检查和拦截功能 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.2-preview.1 | 171 | 12/4/2025 |
| 1.0.1 | 2,748 | 11/27/2025 |
| 1.0.0 | 2,674 | 11/25/2025 |
| 1.0.0-preview.5 | 101 | 10/24/2025 |