@punks/backend-entity-manager 0.0.180 → 0.0.181
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +32 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/platforms/nest/extensions/authentication/guards/auth.d.ts +2 -0
- package/dist/esm/index.js +32 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/platforms/nest/extensions/authentication/guards/auth.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -6,9 +6,11 @@ export declare class AuthGuard implements CanActivate {
|
|
|
6
6
|
constructor(reflector: Reflector);
|
|
7
7
|
canActivate(context: ExecutionContext): boolean;
|
|
8
8
|
private isRoleMatching;
|
|
9
|
+
private isPermissionMatching;
|
|
9
10
|
private getIsForAllAuthenticated;
|
|
10
11
|
private getIsPublic;
|
|
11
12
|
private getAllowedRoles;
|
|
13
|
+
private getAllowedPermissions;
|
|
12
14
|
private getCurrentAuth;
|
|
13
15
|
private getMetadata;
|
|
14
16
|
private getContextInfo;
|
package/dist/esm/index.js
CHANGED
|
@@ -2621,15 +2621,34 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2621
2621
|
const allowedRoles = this.getAllowedRoles(context);
|
|
2622
2622
|
if (allowedRoles) {
|
|
2623
2623
|
const isAllowed = this.isRoleMatching(allowedRoles, auth?.roles ?? []);
|
|
2624
|
-
this.logger.debug(`Authorized:${isAllowed} -> authorization guard`, {
|
|
2624
|
+
this.logger.debug(`Authorized:${isAllowed} -> authorization role guard`, {
|
|
2625
2625
|
...this.getContextInfo({
|
|
2626
2626
|
context,
|
|
2627
2627
|
roles: auth?.roles,
|
|
2628
2628
|
user: auth?.user,
|
|
2629
|
+
permissions: auth?.permissions,
|
|
2629
2630
|
}),
|
|
2630
2631
|
allowedRoles,
|
|
2631
2632
|
});
|
|
2632
|
-
|
|
2633
|
+
if (!isAllowed) {
|
|
2634
|
+
return false;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
const allowedPermissions = this.getAllowedPermissions(context);
|
|
2638
|
+
if (allowedPermissions) {
|
|
2639
|
+
const isAllowed = this.isPermissionMatching(allowedPermissions, auth?.roles ?? []);
|
|
2640
|
+
this.logger.debug(`Authorized:${isAllowed} -> authorization permission guard`, {
|
|
2641
|
+
...this.getContextInfo({
|
|
2642
|
+
context,
|
|
2643
|
+
roles: auth?.roles,
|
|
2644
|
+
user: auth?.user,
|
|
2645
|
+
permissions: auth?.permissions,
|
|
2646
|
+
}),
|
|
2647
|
+
allowedPermissions,
|
|
2648
|
+
});
|
|
2649
|
+
if (!isAllowed) {
|
|
2650
|
+
return false;
|
|
2651
|
+
}
|
|
2633
2652
|
}
|
|
2634
2653
|
const isForAllAuthenticated = this.getIsForAllAuthenticated(context);
|
|
2635
2654
|
if (isForAllAuthenticated) {
|
|
@@ -2639,6 +2658,7 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2639
2658
|
context,
|
|
2640
2659
|
roles: auth?.roles,
|
|
2641
2660
|
user: auth?.user,
|
|
2661
|
+
permissions: auth?.permissions,
|
|
2642
2662
|
}),
|
|
2643
2663
|
});
|
|
2644
2664
|
return isAuthenticated;
|
|
@@ -2649,6 +2669,7 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2649
2669
|
context,
|
|
2650
2670
|
roles: auth?.roles,
|
|
2651
2671
|
user: auth?.user,
|
|
2672
|
+
permissions: auth?.permissions,
|
|
2652
2673
|
}),
|
|
2653
2674
|
});
|
|
2654
2675
|
return isAuthenticated;
|
|
@@ -2656,6 +2677,9 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2656
2677
|
isRoleMatching(allowedRoles, userRoles) {
|
|
2657
2678
|
return userRoles.some((role) => allowedRoles.includes(role.uid));
|
|
2658
2679
|
}
|
|
2680
|
+
isPermissionMatching(allowedPermissions, userPermissions) {
|
|
2681
|
+
return userPermissions.some((permission) => allowedPermissions.includes(permission.uid));
|
|
2682
|
+
}
|
|
2659
2683
|
getIsForAllAuthenticated(context) {
|
|
2660
2684
|
return this.getMetadata(AuthenticationGuardsSymbols.Authenticated, context);
|
|
2661
2685
|
}
|
|
@@ -2665,12 +2689,16 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2665
2689
|
getAllowedRoles(context) {
|
|
2666
2690
|
return this.getMetadata(AuthenticationGuardsSymbols.Roles, context);
|
|
2667
2691
|
}
|
|
2692
|
+
getAllowedPermissions(context) {
|
|
2693
|
+
return this.getMetadata(AuthenticationGuardsSymbols.Permissions, context);
|
|
2694
|
+
}
|
|
2668
2695
|
getCurrentAuth(context) {
|
|
2669
2696
|
const request = context.switchToHttp()?.getRequest();
|
|
2670
2697
|
return request?.auth?.user
|
|
2671
2698
|
? {
|
|
2672
2699
|
user: request.auth.user,
|
|
2673
2700
|
roles: request.auth.roles,
|
|
2701
|
+
permissions: request.auth.permissions,
|
|
2674
2702
|
}
|
|
2675
2703
|
: undefined;
|
|
2676
2704
|
}
|
|
@@ -2680,7 +2708,7 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2680
2708
|
context.getClass(),
|
|
2681
2709
|
]);
|
|
2682
2710
|
}
|
|
2683
|
-
getContextInfo({ context, user, roles, }) {
|
|
2711
|
+
getContextInfo({ context, user, roles, permissions, }) {
|
|
2684
2712
|
return {
|
|
2685
2713
|
request: {
|
|
2686
2714
|
path: context.switchToHttp()?.getRequest()?.path,
|
|
@@ -2693,6 +2721,7 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2693
2721
|
userName: user.userName,
|
|
2694
2722
|
email: user.email,
|
|
2695
2723
|
roles: roles?.map((role) => role.uid),
|
|
2724
|
+
permissions: permissions?.map((permission) => permission.uid),
|
|
2696
2725
|
},
|
|
2697
2726
|
}
|
|
2698
2727
|
: {}),
|