Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.1] Extend 2FA Enforcement option to select usergroups #30522

Merged
merged 4 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions administrator/components/com_users/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@
<option value="3">COM_USERS_CONFIG_FIELD_ENFORCE_2FA_FIELD_BOTH</option>
</field>

<field
name="enforce_2fa_usergroups"
type="usergrouplist"
label="COM_USERS_CONFIG_FIELD_ENFORCE_2FA_GROUPS_LABEL"
multiple="true"
filter="int_array"
size="10"
showon="enforce_2fa_options!:0"
/>

</fieldset>

<fieldset
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ COM_USERS_CONFIG_FIELD_ENFORCE_2FA_FIELD_ADMIN="Admin (Backend)"
COM_USERS_CONFIG_FIELD_ENFORCE_2FA_FIELD_BOTH="Both"
COM_USERS_CONFIG_FIELD_ENFORCE_2FA_FIELD_LABEL="Enforce Two Factor Authentication"
COM_USERS_CONFIG_FIELD_ENFORCE_2FA_FIELD_SITE="Site (Frontend)"
COM_USERS_CONFIG_FIELD_ENFORCE_2FA_GROUPS_LABEL="Enforce Two Factor Authentication for Usergroups"
COM_USERS_CONFIG_FIELD_FRONTEND_LANG_LABEL="Frontend Language"
COM_USERS_CONFIG_FIELD_FRONTEND_RESET_COUNT_LABEL="Maximum Reset Count"
COM_USERS_CONFIG_FIELD_FRONTEND_RESET_TIME_LABEL="Reset Time"
Expand Down
21 changes: 18 additions & 3 deletions libraries/src/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -1175,9 +1175,9 @@ public function isCli()
*/
protected function isTwoFactorAuthenticationRequired(): bool
{
$userId = $this->getIdentity()->id;
$user = $this->getIdentity();

if (!$userId)
if (!$user->id)
{
return false;
}
Expand All @@ -1188,7 +1188,22 @@ protected function isTwoFactorAuthenticationRequired(): bool
return false;
}

$enforce2faOptions = ComponentHelper::getComponent('com_users')->getParams()->get('enforce_2fa_options', 0);
$comUsersParams = ComponentHelper::getComponent('com_users')->getParams();

// Check if 2fa is enforced for the logged in user.
$forced2faGroups = (array) $comUsersParams->get('enforce_2fa_usergroups', []);

if (!empty($forced2faGroups))
{
$userGroups = (array) $user->get('groups', []);

if (!array_intersect($forced2faGroups, $userGroups))
{
return false;
}
}

$enforce2faOptions = $comUsersParams->get('enforce_2fa_options', 0);

if ($enforce2faOptions == 0 || !$enforce2faOptions)
{
Expand Down