Skip to content

Commit

Permalink
新增方法 hasAllPermissions 判断是否具有所有的权限
Browse files Browse the repository at this point in the history
  • Loading branch information
yong.teng committed Jan 5, 2024
1 parent bb49974 commit e45fbd6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 修复
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
26 changes: 24 additions & 2 deletions src/shiro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrincipalPlainObject, Principal, DefaultPrincipal } from './core/princi
import { has, hasAny, hasAll } from './utils/common'

export interface IShiro {

/**
* 验证是否为已认证通过的用户,不包含已记住的用户,这是与 isUser 标签方法的区别所在
*
Expand Down Expand Up @@ -102,6 +102,16 @@ export interface IShiro {
*/
hasAnyPermission(permissions: string[]): boolean;

/**
* 验证用户是否具有以下所有权限
*
* @param permissions
* 权限列表
*
* @return 用户是否具有以下所有权限
*/
hasAllPermissions(permissions: string[]): boolean;

/**
* 验证用户是否具有以下所有权限
*
Expand Down Expand Up @@ -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);
}

}

0 comments on commit e45fbd6

Please sign in to comment.