2024-06-12 10:27:59 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
|
|
|
|
getProfileConfig,
|
|
|
|
|
setProfileConfig
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-14 11:17:38 +05:30
|
|
|
const assert = require('node:assert'),
|
2024-06-12 10:27:59 +02:00
|
|
|
BoxError = require('./boxerror.js'),
|
|
|
|
|
constants = require('./constants.js'),
|
|
|
|
|
debug = require('debug')('box:user-directory'),
|
2024-06-12 10:46:23 +02:00
|
|
|
eventlog = require('./eventlog.js'),
|
2025-06-11 22:53:29 +02:00
|
|
|
oidcClients = require('./oidcclients.js'),
|
2025-06-11 22:00:09 +02:00
|
|
|
oidcServer = require('./oidcserver.js'),
|
2024-06-12 10:27:59 +02:00
|
|
|
settings = require('./settings.js'),
|
|
|
|
|
tokens = require('./tokens.js'),
|
|
|
|
|
users = require('./users.js');
|
|
|
|
|
|
|
|
|
|
async function getProfileConfig() {
|
|
|
|
|
const value = await settings.getJson(settings.PROFILE_CONFIG_KEY);
|
|
|
|
|
return value || { lockUserProfiles: false, mandatory2FA: false };
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 12:54:40 +02:00
|
|
|
async function setProfileConfig(profileConfig, options, auditSource) {
|
2024-06-12 10:27:59 +02:00
|
|
|
assert.strictEqual(typeof profileConfig, 'object');
|
2024-05-25 12:54:40 +02:00
|
|
|
assert.strictEqual(typeof options, 'object');
|
2024-06-12 10:46:23 +02:00
|
|
|
assert(auditSource && typeof auditSource === 'object');
|
2024-06-12 10:27:59 +02:00
|
|
|
|
|
|
|
|
if (constants.DEMO) throw new BoxError(BoxError.BAD_STATE, 'Not allowed in demo mode');
|
|
|
|
|
|
|
|
|
|
const oldConfig = await getProfileConfig();
|
|
|
|
|
await settings.setJson(settings.PROFILE_CONFIG_KEY, profileConfig);
|
|
|
|
|
|
2024-06-12 10:46:23 +02:00
|
|
|
await eventlog.add(eventlog.ACTION_USER_DIRECTORY_PROFILE_CONFIG_UPDATE, auditSource, { oldConfig, config: profileConfig });
|
|
|
|
|
|
2024-06-12 10:27:59 +02:00
|
|
|
if (profileConfig.mandatory2FA && !oldConfig.mandatory2FA) {
|
|
|
|
|
debug('setProfileConfig: logging out non-2FA users to enforce 2FA');
|
|
|
|
|
|
|
|
|
|
const allUsers = await users.list();
|
2024-05-25 12:54:40 +02:00
|
|
|
|
2024-06-12 10:27:59 +02:00
|
|
|
for (const user of allUsers) {
|
|
|
|
|
if (user.twoFactorAuthenticationEnabled) continue;
|
2024-05-25 12:54:40 +02:00
|
|
|
if (options.persistUserIdSessions === user.id) continue; // do not logout the API caller
|
2024-06-12 10:27:59 +02:00
|
|
|
|
2025-06-11 22:53:29 +02:00
|
|
|
await tokens.delByUserIdAndType(user.id, oidcClients.ID_WEBADMIN);
|
2025-07-01 22:07:31 +02:00
|
|
|
await oidcServer.revokeByUsername(user.username);
|
2024-06-12 10:27:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|