monkey-front-core 0.0.355 → 0.0.357
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/esm2020/lib/core/services/auth/monkeyecx-auth-guard-role.service.mjs +70 -11
- package/fesm2015/monkey-front-core.mjs +71 -12
- package/fesm2015/monkey-front-core.mjs.map +1 -1
- package/fesm2020/monkey-front-core.mjs +67 -10
- package/fesm2020/monkey-front-core.mjs.map +1 -1
- package/lib/core/services/auth/monkeyecx-auth-guard-role.service.d.ts +16 -0
- package/monkey-front-core-0.0.357.tgz +0 -0
- package/package.json +1 -1
- package/monkey-front-core-0.0.355.tgz +0 -0
|
@@ -4118,29 +4118,86 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
|
|
|
4118
4118
|
}], ctorParameters: function () { return [{ type: MonkeyEcxAuthenticationService }]; } });
|
|
4119
4119
|
|
|
4120
4120
|
class MonkeyEcxAuthGuardByRole {
|
|
4121
|
-
constructor() {
|
|
4121
|
+
constructor(tokenStorage, router) {
|
|
4122
|
+
this.tokenStorage = tokenStorage;
|
|
4123
|
+
this.router = router;
|
|
4124
|
+
this.securityCredentials = null;
|
|
4125
|
+
this.tokenCredentials = null;
|
|
4122
4126
|
// not to do
|
|
4123
4127
|
}
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
+
navigateToErrorPage() {
|
|
4129
|
+
const { tokenCredentials } = this;
|
|
4130
|
+
const companyType = tokenCredentials?.companyType;
|
|
4131
|
+
let path = '/app/pages/forbidden';
|
|
4132
|
+
if (companyType) {
|
|
4133
|
+
path = `/app/${companyType}/pages/forbidden`;
|
|
4134
|
+
}
|
|
4135
|
+
this.router?.navigate([path.toLowerCase()]);
|
|
4136
|
+
}
|
|
4137
|
+
getRole() {
|
|
4138
|
+
const { tokenCredentials } = this;
|
|
4139
|
+
if (!tokenCredentials)
|
|
4140
|
+
return '';
|
|
4141
|
+
if (tokenCredentials?.programAdmin === 'true') {
|
|
4142
|
+
return 'PROGRAM_ADMIN';
|
|
4143
|
+
}
|
|
4144
|
+
if (tokenCredentials?.programAdmin === true) {
|
|
4145
|
+
return 'PROGRAM_ADMIN';
|
|
4146
|
+
}
|
|
4147
|
+
return tokenCredentials?.role || '';
|
|
4148
|
+
}
|
|
4149
|
+
allowedSecurityAccess(roles, byExclusion) {
|
|
4150
|
+
if (!roles?.length)
|
|
4151
|
+
return true;
|
|
4152
|
+
const found = roles?.indexOf(this.getRole());
|
|
4153
|
+
let ret = false;
|
|
4154
|
+
if (byExclusion) {
|
|
4155
|
+
ret = true;
|
|
4156
|
+
if (found > -1) {
|
|
4157
|
+
ret = false;
|
|
4128
4158
|
}
|
|
4129
|
-
|
|
4130
|
-
|
|
4159
|
+
}
|
|
4160
|
+
else {
|
|
4161
|
+
ret = false;
|
|
4162
|
+
if (found > -1) {
|
|
4163
|
+
ret = true;
|
|
4131
4164
|
}
|
|
4132
4165
|
}
|
|
4133
|
-
|
|
4166
|
+
if (!roles || roles.length === 0 || this.getRole() === 'PROGRAM_ADMIN') {
|
|
4167
|
+
ret = true;
|
|
4168
|
+
}
|
|
4169
|
+
return ret;
|
|
4170
|
+
}
|
|
4171
|
+
async canActivate(route, state) {
|
|
4172
|
+
this.securityCredentials = route.data?.securityCredentials;
|
|
4173
|
+
console.log('this.securityCredentials');
|
|
4174
|
+
console.log(this.securityCredentials);
|
|
4175
|
+
if (this.securityCredentials) {
|
|
4176
|
+
const { roles, byExclusion } = this.securityCredentials;
|
|
4177
|
+
if (!this.tokenCredentials) {
|
|
4178
|
+
this.tokenCredentials = await this.tokenStorage.getToken();
|
|
4179
|
+
}
|
|
4180
|
+
console.log('this.tokenCredentials');
|
|
4181
|
+
console.log(this.tokenCredentials);
|
|
4182
|
+
console.log('checando');
|
|
4183
|
+
if (!this.allowedSecurityAccess(roles, byExclusion)) {
|
|
4184
|
+
console.log('checou erro');
|
|
4185
|
+
this.navigateToErrorPage();
|
|
4186
|
+
return false;
|
|
4187
|
+
}
|
|
4188
|
+
console.log('checou ok');
|
|
4189
|
+
}
|
|
4190
|
+
return true;
|
|
4134
4191
|
}
|
|
4135
4192
|
}
|
|
4136
|
-
MonkeyEcxAuthGuardByRole.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
4193
|
+
MonkeyEcxAuthGuardByRole.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, deps: [{ token: MonkeyEcxTokenStorageService }, { token: i2$2.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
4137
4194
|
MonkeyEcxAuthGuardByRole.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, providedIn: 'root' });
|
|
4138
4195
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthGuardByRole, decorators: [{
|
|
4139
4196
|
type: Injectable,
|
|
4140
4197
|
args: [{
|
|
4141
4198
|
providedIn: 'root'
|
|
4142
4199
|
}]
|
|
4143
|
-
}], ctorParameters: function () { return []; } });
|
|
4200
|
+
}], ctorParameters: function () { return [{ type: MonkeyEcxTokenStorageService }, { type: i2$2.Router }]; } });
|
|
4144
4201
|
|
|
4145
4202
|
class MonkeyEcxAuthGuard {
|
|
4146
4203
|
constructor(monkeyecxAuthenticationService) {
|