@tomei/sso 0.50.7 → 0.51.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/components/login-user/user.d.ts +1 -0
- package/dist/src/components/login-user/user.js +24 -0
- package/dist/src/components/login-user/user.js.map +1 -1
- package/dist/src/components/user-group/user-group.d.ts +1 -0
- package/dist/src/components/user-group/user-group.js +30 -0
- package/dist/src/components/user-group/user-group.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/login-user/user.ts +38 -0
- package/src/components/user-group/user-group.ts +54 -0
package/package.json
CHANGED
@@ -2009,6 +2009,44 @@ export class User extends UserBase {
|
|
2009
2009
|
return `${userId}:${systemLogin.sessionId}`;
|
2010
2010
|
}
|
2011
2011
|
|
2012
|
+
public async bypass2FA(systemCode: string, dbTransaction: any) {
|
2013
|
+
try {
|
2014
|
+
const user = await User._Repository.findOne({
|
2015
|
+
where: {
|
2016
|
+
UserId: this.UserId,
|
2017
|
+
},
|
2018
|
+
transaction: dbTransaction,
|
2019
|
+
});
|
2020
|
+
|
2021
|
+
//Check if 2FA is not enabled
|
2022
|
+
if (user.MFAEnabled === 1) {
|
2023
|
+
//If Enabled return error
|
2024
|
+
throw new ClassError(
|
2025
|
+
'LoginUser',
|
2026
|
+
'LoginUserErrMsg0X',
|
2027
|
+
'Cannot bypass 2FA as it is enabled',
|
2028
|
+
);
|
2029
|
+
}
|
2030
|
+
|
2031
|
+
//Retrieve user session
|
2032
|
+
const userSession = await this._SessionService.retrieveUserSession(
|
2033
|
+
`${this.UserId}`,
|
2034
|
+
);
|
2035
|
+
|
2036
|
+
//Retrieve system code
|
2037
|
+
if (!systemCode) {
|
2038
|
+
systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
2039
|
+
}
|
2040
|
+
|
2041
|
+
const systemLogin = userSession.systemLogins.find(
|
2042
|
+
(e) => e.code === systemCode,
|
2043
|
+
);
|
2044
|
+
return `${this.UserId}:${systemLogin.sessionId}`;
|
2045
|
+
} catch (error) {
|
2046
|
+
throw error;
|
2047
|
+
}
|
2048
|
+
}
|
2049
|
+
|
2012
2050
|
public async addUserGroup(
|
2013
2051
|
GroupCode: string,
|
2014
2052
|
loginUser: User,
|
@@ -8,6 +8,7 @@ import { ActionEnum, Activity } from '@tomei/activity-history';
|
|
8
8
|
import GroupSystemAccessModel from '../../models/group-system-access.entity';
|
9
9
|
import GroupModel from '../../models/group.entity';
|
10
10
|
import SystemModel from '../../models/system.entity';
|
11
|
+
import UserModel from '../../models/user.entity';
|
11
12
|
import { Transaction } from 'sequelize';
|
12
13
|
|
13
14
|
export class UserGroup extends ObjectBase {
|
@@ -301,6 +302,59 @@ export class UserGroup extends ObjectBase {
|
|
301
302
|
}
|
302
303
|
}
|
303
304
|
|
305
|
+
public static async getUser(
|
306
|
+
dbTransaction: any,
|
307
|
+
loginUser: LoginUser,
|
308
|
+
GroupCode: string,
|
309
|
+
) {
|
310
|
+
try {
|
311
|
+
// Part 1: Privilege Checking
|
312
|
+
// Call loginUser.checkPrivileges() by passing:
|
313
|
+
// SystemCode: "<get_from_app_config>"
|
314
|
+
// PrivilegeCode: "USER_GROUP_VIEW"
|
315
|
+
const systemCode =
|
316
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
317
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
318
|
+
systemCode,
|
319
|
+
'USER_GROUP_VIEW',
|
320
|
+
);
|
321
|
+
|
322
|
+
// If user does not have privilege to view user group, throw a ClassError
|
323
|
+
if (!isPrivileged) {
|
324
|
+
throw new ClassError(
|
325
|
+
'UserGroup',
|
326
|
+
'UserGroupErrMsg0X',
|
327
|
+
'User does not have privilege to view user group.',
|
328
|
+
);
|
329
|
+
}
|
330
|
+
|
331
|
+
// Part 2: Retrieve Record
|
332
|
+
// Call UserGroup._Repo findAll method by passing:
|
333
|
+
// where:
|
334
|
+
// GroupCode: Params.GroupCode
|
335
|
+
// dbTransaction
|
336
|
+
const userGroup = await UserGroup._Repository.findAll({
|
337
|
+
where: {
|
338
|
+
GroupCode,
|
339
|
+
},
|
340
|
+
include: [
|
341
|
+
{
|
342
|
+
model: UserModel,
|
343
|
+
as: 'User',
|
344
|
+
attributes: ['UserId', 'FullName', 'Email'],
|
345
|
+
},
|
346
|
+
],
|
347
|
+
transaction: dbTransaction,
|
348
|
+
});
|
349
|
+
// If record exists, instantiate UserGroup by calling the private constructor and passing the attributes. Then, returns the instance
|
350
|
+
return userGroup;
|
351
|
+
// If record not exists, return null.
|
352
|
+
return null;
|
353
|
+
} catch (error) {
|
354
|
+
throw error;
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
304
358
|
static async findAllInheritedSystemAccesses(
|
305
359
|
UserId: number,
|
306
360
|
loginUser: User,
|