monkey-front-core 0.0.347 → 0.0.349
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 +53 -51
- package/esm2020/lib/core/services/auth/monkeyecx-authentication.service.mjs +6 -1
- package/fesm2015/monkey-front-core.mjs +56 -50
- package/fesm2015/monkey-front-core.mjs.map +1 -1
- package/fesm2020/monkey-front-core.mjs +55 -50
- package/fesm2020/monkey-front-core.mjs.map +1 -1
- package/lib/core/services/auth/monkeyecx-authentication.service.d.ts +2 -0
- package/monkey-front-core-0.0.349.tgz +0 -0
- package/package.json +1 -1
- package/monkey-front-core-0.0.347.tgz +0 -0
|
@@ -4037,6 +4037,10 @@ class MonkeyEcxAuthenticationService {
|
|
|
4037
4037
|
console.error('refreshToken needs to be declared!');
|
|
4038
4038
|
return null;
|
|
4039
4039
|
};
|
|
4040
|
+
this.getToken = async () => {
|
|
4041
|
+
console.error('getToken needs to be declared!');
|
|
4042
|
+
return null;
|
|
4043
|
+
};
|
|
4040
4044
|
// not to do
|
|
4041
4045
|
}
|
|
4042
4046
|
init(args) {
|
|
@@ -4054,6 +4058,7 @@ class MonkeyEcxAuthenticationService {
|
|
|
4054
4058
|
this.getRequestWithHeadersOb = args?.getRequestWithHeadersOb.bind(this);
|
|
4055
4059
|
this.refreshShouldHappen = args?.refreshShouldHappen || this.refreshShouldHappen.bind(this);
|
|
4056
4060
|
this.refreshToken = args?.refreshToken || this.refreshToken.bind(this);
|
|
4061
|
+
this.getToken = args?.getToken || this.getToken.bind(this);
|
|
4057
4062
|
}
|
|
4058
4063
|
}
|
|
4059
4064
|
MonkeyEcxAuthenticationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: MonkeyEcxAuthenticationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
@@ -4118,79 +4123,79 @@ let MonkeyEcxAuthGuardByRole = class MonkeyEcxAuthGuardByRole {
|
|
|
4118
4123
|
}
|
|
4119
4124
|
static forRoles(roles, companyType, byExclusion) {
|
|
4120
4125
|
class RoleCheck {
|
|
4121
|
-
constructor() {
|
|
4126
|
+
constructor(monkeyecxAuthenticationService, router) {
|
|
4127
|
+
this.monkeyecxAuthenticationService = monkeyecxAuthenticationService;
|
|
4128
|
+
this.router = router;
|
|
4122
4129
|
this.tokenCredentials = null;
|
|
4123
4130
|
// not to do
|
|
4124
4131
|
}
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4132
|
+
navigateToErrorPage() {
|
|
4133
|
+
let path = '/app/pages/forbidden';
|
|
4134
|
+
if (companyType) {
|
|
4135
|
+
path = `/app/${companyType}/pages/forbidden`;
|
|
4136
|
+
}
|
|
4137
|
+
this.router?.navigate([path.toLowerCase()]);
|
|
4131
4138
|
}
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
return tokenCredentials?.role || '';
|
|
4139
|
+
getRole() {
|
|
4140
|
+
const { tokenCredentials } = this;
|
|
4141
|
+
if (!tokenCredentials)
|
|
4142
|
+
return '';
|
|
4143
|
+
if (tokenCredentials?.programAdmin === 'true') {
|
|
4144
|
+
return 'PROGRAM_ADMIN';
|
|
4145
|
+
}
|
|
4146
|
+
if (tokenCredentials?.programAdmin === true) {
|
|
4147
|
+
return 'PROGRAM_ADMIN';
|
|
4148
|
+
}
|
|
4149
|
+
return tokenCredentials?.role || '';
|
|
4145
4150
|
}
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4151
|
+
allowedSecurityAccess(roles) {
|
|
4152
|
+
if (!roles?.length)
|
|
4153
|
+
return true;
|
|
4154
|
+
const found = roles?.indexOf(this.getRole());
|
|
4155
|
+
let ret = false;
|
|
4156
|
+
if (byExclusion) {
|
|
4157
|
+
ret = true;
|
|
4158
|
+
if (found > -1) {
|
|
4159
|
+
ret = false;
|
|
4160
|
+
}
|
|
4156
4161
|
}
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4162
|
+
else {
|
|
4163
|
+
ret = false;
|
|
4164
|
+
if (found > -1) {
|
|
4165
|
+
ret = true;
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
if (!roles || roles.length === 0 || this.getRole() === 'PROGRAM_ADMIN') {
|
|
4169
|
+
ret = true;
|
|
4161
4170
|
}
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
ret = true;
|
|
4165
|
-
}
|
|
4166
|
-
return ret;
|
|
4167
|
-
} */
|
|
4171
|
+
return ret;
|
|
4172
|
+
}
|
|
4168
4173
|
async canActivate() {
|
|
4169
4174
|
console.log('roles');
|
|
4170
4175
|
console.log(roles);
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4176
|
+
if (!this.tokenCredentials) {
|
|
4177
|
+
this.tokenCredentials = await this.monkeyecxAuthenticationService.getToken();
|
|
4178
|
+
}
|
|
4174
4179
|
console.log('this.tokenCredentials');
|
|
4175
4180
|
console.log(this.tokenCredentials);
|
|
4176
4181
|
console.log('checando');
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
+
if (!this.allowedSecurityAccess(roles)) {
|
|
4183
|
+
console.log('checou erro');
|
|
4184
|
+
this.navigateToErrorPage();
|
|
4185
|
+
return false;
|
|
4186
|
+
}
|
|
4182
4187
|
console.log('checou ok');
|
|
4183
4188
|
return true;
|
|
4184
4189
|
}
|
|
4185
4190
|
}
|
|
4186
|
-
RoleCheck.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
4191
|
+
RoleCheck.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, deps: [{ token: MonkeyEcxAuthenticationService }, { token: i2$2.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
4187
4192
|
RoleCheck.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, providedIn: 'root' });
|
|
4188
4193
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: RoleCheck, decorators: [{
|
|
4189
4194
|
type: Injectable,
|
|
4190
4195
|
args: [{
|
|
4191
4196
|
providedIn: 'root'
|
|
4192
4197
|
}]
|
|
4193
|
-
}], ctorParameters: function () { return []; } });
|
|
4198
|
+
}], ctorParameters: function () { return [{ type: MonkeyEcxAuthenticationService }, { type: i2$2.Router }]; } });
|
|
4194
4199
|
return RoleCheck;
|
|
4195
4200
|
}
|
|
4196
4201
|
};
|