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

#871: Applied patch fixing os2forms_nemid authentication check #286

Closed
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Nedenfor ses dato for release og beskrivelse af opgaver som er implementeret.

## [Under udvikling]

* Tilføjede patch på OS2Forms Nemid autentificeringstjek.

## [2.7.7] 2024-02-15

* Opdaterede installationsguide.
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
"drupal/maestro": {
"Fix check for task notifications": "patches/drupal/maestro/maestro_notification.patch",
"Maestro task notification permission patch": "patches/drupal/maestro/maestro_task_select_notification_role_permission.patch"
},
"os2forms/os2forms": {
"Authentication check fix": "patches/drupal/os2forms/os2forms_nemid_authentication_check_update.patch"
}
},
"patches-ignore": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
diff --git a/modules/os2forms_nemid/os2forms_nemid.module b/modules/os2forms_nemid/os2forms_nemid.module
index cd86dc4..a24b0a5 100644
--- a/modules/os2forms_nemid/os2forms_nemid.module
+++ b/modules/os2forms_nemid/os2forms_nemid.module
@@ -134,21 +134,37 @@ function os2forms_nemid_webform_submission_form_alter(array &$form, FormStateInt
// User is authenticated, check if the form type is corresponding to
// authentication type.
if ($authProviderPlugin->isAuthenticated()) {
- if ($authProviderPlugin->isAuthenticatedPerson() && $webform_type !== NemidElementBase::WEBFORM_TYPE_PERSONAL
- || $authProviderPlugin->isAuthenticatedCompany() && $webform_type !== NemidElementBase::WEBFORM_TYPE_COMPANY) {
- \Drupal::messenger()
- ->addWarning(t('Your login type does match the login type required by the webform. Please <a href="@logout">log out</a> and sign in with a different account', [
- '@logout' => $authProviderService->getLogoutUrl()
- ->toString(),
- ]));
- foreach (Element::children($form['actions']) as $key) {
- $form['actions'][$key]['#disabled'] = TRUE;
- }
+ // Users often login on behalf of company as themselves
+ // i.e. values may contain both a cpr and cvr value,
+ // and they will be considered authenticated as company AND person.
+ if ($webform_type === NemidElementBase::WEBFORM_TYPE_COMPANY && !$authProviderPlugin->isAuthenticatedCompany()) {
+ _os2forms_nemid_add_authentication_warning_and_disable_form($form, $authProviderService->getLogoutUrl()->toString());
+ }
+ elseif ($webform_type === NemidElementBase::WEBFORM_TYPE_PERSONAL && !$authProviderPlugin->isAuthenticatedPerson()) {
+ _os2forms_nemid_add_authentication_warning_and_disable_form($form, $authProviderService->getLogoutUrl()->toString());
}
}
}
}

+/**
+ * Adds authentication warning and disables actions on form.
+ *
+ * @param array $form
+ * Form array.
+ * @param string $logoutUrl
+ * Logout url.
+ */
+function _os2forms_nemid_add_authentication_warning_and_disable_form(array $form, string $logoutUrl) {
+ \Drupal::messenger()
+ ->addWarning(t('Your login type does match the login type required by the webform. Please <a href="@logout">log out</a> and sign in with a different account', [
+ '@logout' => $logoutUrl,
+ ]));
+ foreach (Element::children($form['actions']) as $key) {
+ $form['actions'][$key]['#disabled'] = TRUE;
+ }
+}
+
/**
* Implements hook_preprocess().
*/
Loading