From e45fbd64f1c51019c8e6bf02a1a1637d2ddf1116 Mon Sep 17 00:00:00 2001 From: "yong.teng" Date: Fri, 5 Jan 2024 17:23:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=B9=E6=B3=95=20hasAllPe?= =?UTF-8?q?rmissions=20=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E5=85=B7?= =?UTF-8?q?=E6=9C=89=E6=89=80=E6=9C=89=E7=9A=84=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- src/shiro.ts | 26 ++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 066cbdd..bcc781e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # 更新日志 + +## [v1.2.2](https://github.com/buession/buession-shiro/releases/tag/1.2.2)(2024-01-05) + +### ⭐ 新特性 + +- 新增方法 hasAllPermissions 判断是否具有所有的权限 + + ## [v1.2.1](https://github.com/buession/buession-shiro/releases/tag/1.2.1)(2023-08-25) ### 🐞 BUG 修复 diff --git a/package.json b/package.json index 435eeca..2fb710f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@buession/shiro", "alias": "shiro", - "version": "v1.2.1", + "version": "v1.2.2", "description": "A security framework for JavaScript or TypeScript.", "homepage": "https://shirojs.buession.com/", "author": { diff --git a/src/shiro.ts b/src/shiro.ts index c559390..8cd5c58 100644 --- a/src/shiro.ts +++ b/src/shiro.ts @@ -3,7 +3,7 @@ import { PrincipalPlainObject, Principal, DefaultPrincipal } from './core/princi import { has, hasAny, hasAll } from './utils/common' export interface IShiro { - + /** * 验证是否为已认证通过的用户,不包含已记住的用户,这是与 isUser 标签方法的区别所在 * @@ -102,6 +102,16 @@ export interface IShiro { */ hasAnyPermission(permissions: string[]): boolean; + /** + * 验证用户是否具有以下所有权限 + * + * @param permissions + * 权限列表 + * + * @return 用户是否具有以下所有权限 + */ + hasAllPermissions(permissions: string[]): boolean; + /** * 验证用户是否具有以下所有权限 * @@ -256,8 +266,20 @@ export class Shiro implements IShiro { * * @return 用户是否具有以下所有权限 */ - hasPermissionsAll(permissions: string[]): boolean { + hasAllPermissions(permissions: string[]): boolean { return this.isAuthenticated() && (has(this.principal.getPermissions(), ALL_PERMISSION) || hasAll(this.principal.getPermissions(), permissions)); } + /** + * 验证用户是否具有以下所有权限 + * + * @param permissions + * 权限列表 + * + * @return 用户是否具有以下所有权限 + */ + hasPermissionsAll(permissions: string[]): boolean { + return this.hasAllPermissions(permissions); + } + } \ No newline at end of file