UNPKG

@lanaqi/rsr

Version:
198 lines (197 loc) 6.04 kB
import { type AccessAuthentication, type AccessAuthorization, type AccessDatasheet, type AuthenticationDatasheet, type AuthorizationDatasheet } from './aaa'; import type { AccessPath } from './common'; import type { AccessRecorder } from './recorder'; /** * 访问存储器 */ export interface AccessStorer { /** * 加载认证 * @param recorder 记录器 */ loadAuthentication(recorder: AccessRecorder): AccessAuthentication | undefined; /** * 校验认证 * @param recorder 记录器 * @param authentication 认证 */ verifyAuthentication(recorder: AccessRecorder, authentication: AccessAuthentication): boolean; /** * 删除认证 * @param recorder 记录器 */ deleteAuthentication(recorder: AccessRecorder): void; /** * 保存认证 * @param recorder 记录器 * @param datasheet 数据表 */ saveAuthentication<Datasheet>(recorder: AccessRecorder, datasheet: AccessDatasheet<AuthenticationDatasheet<Datasheet>>): void; /** * 加载授权 * @param recorder 记录器 * @param authentication 认证 | undefined */ loadAuthorization(recorder: AccessRecorder, authentication: AccessAuthentication | undefined): AccessAuthorization | undefined; /** * 删除授权 * @param recorder 记录器 */ deleteAuthorization(recorder: AccessRecorder): void; /** * 保存授权 * @param recorder 记录器 * @param datasheet 数据表 */ saveAuthorization<Datasheet>(recorder: AccessRecorder, datasheet: AccessDatasheet<AuthorizationDatasheet<Datasheet>>): void; /** * 加载签名 * @param recorder 记录器 * @param path 路径 * @param authentication 认证 * @param authorization 授权 */ loadSignature(recorder: AccessRecorder, path: AccessPath, authentication: AccessAuthentication, authorization: AccessAuthorization): boolean; /** * 移除签名 * @param recorder 记录器 * @param path 路径 */ removeSignature(recorder: AccessRecorder, path: AccessPath): void; /** * 删除签名 * @param recorder 记录器 */ deleteSignature(recorder: AccessRecorder): void; /** * 保存签名 * @param recorder 记录器 * @param path 路径 */ saveSignature(recorder: AccessRecorder, path: AccessPath): void; } /** * 访问验证器 */ export type AccessValidator = (recorder: AccessRecorder, authentication: AccessAuthentication) => boolean; /** * 简单存储器 */ export declare class SimpleStorer implements AccessStorer { /** * 存储健:认证 */ static readonly KEY_AUTHENTICATION = "__authentication__"; /** * 存储健:授权 */ static readonly KEY_AUTHORIZATION = "__authorization__"; /** * 存储健:签名 */ static readonly KEY_SIGNATURE = "__signature__"; /** * 认证与授权存储 * @private */ private readonly aaaStorage; /** * 签名存储 * @private */ private readonly signStorage; /** * 认证健 * @private */ private readonly authenticationKey; /** * 授权健 * @private */ private readonly authorizationKey; /** * 签名健 * @private */ private readonly signatureKey; /** * 认证验证器 * @private */ private readonly authenticationValidator?; /** * 构造函数 * @param aaaStorage 认证与授权存储 * @param signStorage 签名存储 * @param authenticationKey 认证健 * @param authorizationKey 授权健 * @param signatureKey 签名健 * @param authenticationValidator 认证验证器 */ constructor(aaaStorage: Storage, signStorage: Storage, authenticationKey?: string, authorizationKey?: string, signatureKey?: string, authenticationValidator?: AccessValidator); /** * 加载认证 * @param recorder 记录器 */ loadAuthentication(recorder: AccessRecorder): AccessAuthentication | undefined; /** * 校验认证 * @param recorder 记录器 * @param authentication 认证 */ verifyAuthentication(recorder: AccessRecorder, authentication: AccessAuthentication): boolean; /** * 删除认证 * @param recorder 记录器 */ deleteAuthentication(recorder: AccessRecorder): void; /** * 保存认证 * @param recorder 记录器 * @param datasheet 数据表 */ saveAuthentication<Datasheet>(recorder: AccessRecorder, datasheet: AccessDatasheet<AuthenticationDatasheet<Datasheet>>): void; /** * 加载授权 * @param recorder 记录器 * @param authentication 认证 | undefined */ loadAuthorization(recorder: AccessRecorder, authentication: AccessAuthentication | undefined): AccessAuthorization | undefined; /** * 删除授权 * @param recorder 记录器 */ deleteAuthorization(recorder: AccessRecorder): void; /** * 保存授权 * @param recorder 记录器 * @param datasheet 数据表 */ saveAuthorization<Datasheet>(recorder: AccessRecorder, datasheet: AccessDatasheet<AuthorizationDatasheet<Datasheet>>): void; /** * 加载签名 * @param recorder 记录器 * @param path 路径 * @param authentication 认证 * @param authorization 授权 */ loadSignature(recorder: AccessRecorder, path: AccessPath, authentication: AccessAuthentication, authorization: AccessAuthorization): boolean; /** * 移除签名 * @param recorder 记录器 * @param path 路径 */ removeSignature(recorder: AccessRecorder, path: AccessPath): void; /** * 删除签名 * @param recorder 记录器 */ deleteSignature(recorder: AccessRecorder): void; /** * 保存签名 * @param recorder 记录器 * @param path 路径 */ saveSignature(recorder: AccessRecorder, path: AccessPath): void; }