8
8
use Drupal \os2forms_nemid \Element \NemidCompanyCvrFetchData ;
9
9
use Drupal \os2forms_nemid \Element \NemidCompanyPNumber ;
10
10
use Drupal \os2forms_nemid \Element \NemidCprFetchData ;
11
+ use Drupal \os2web_audit \Service \Logger ;
11
12
use Drupal \os2web_datalookup \LookupResult \CompanyLookupResult ;
12
13
use Drupal \os2web_datalookup \LookupResult \CprLookupResult ;
13
14
use Drupal \os2web_datalookup \Plugin \DataLookupManager ;
15
+ use Drupal \os2web_nemlogin \Plugin \AuthProviderInterface ;
14
16
use Drupal \os2web_nemlogin \Service \AuthProviderService ;
15
17
use Drupal \webform \WebformSubmissionInterface ;
16
18
@@ -70,6 +72,13 @@ class FormsHelper {
70
72
*/
71
73
private RouteMatchInterface $ routeMatch ;
72
74
75
+ /**
76
+ * An audit logger.
77
+ *
78
+ * @var \Drupal\os2web_audit\Service\Logger
79
+ */
80
+ private Logger $ auditLogger ;
81
+
73
82
/**
74
83
* Constructor.
75
84
*
@@ -79,11 +88,19 @@ class FormsHelper {
79
88
* Datalookup plugin manager.
80
89
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
81
90
* Route match service.
91
+ * @param \Drupal\os2web_audit\Service\Logger $auditLogger
92
+ * Audit logger.
82
93
*/
83
- public function __construct (AuthProviderService $ authProviderService , DataLookupManager $ dataLookPluginManager , RouteMatchInterface $ routeMatch ) {
94
+ public function __construct (
95
+ AuthProviderService $ authProviderService ,
96
+ DataLookupManager $ dataLookPluginManager ,
97
+ RouteMatchInterface $ routeMatch ,
98
+ Logger $ auditLogger ,
99
+ ) {
84
100
$ this ->authProviderService = $ authProviderService ;
85
101
$ this ->dataLookManager = $ dataLookPluginManager ;
86
102
$ this ->routeMatch = $ routeMatch ;
103
+ $ this ->auditLogger = $ auditLogger ;
87
104
}
88
105
89
106
/**
@@ -126,6 +143,14 @@ public function retrieveCprLookupResult(FormStateInterface $form_state) {
126
143
}
127
144
}
128
145
146
+ // We need the auth provider for logging purposes.
147
+ $ authProviderPlugin = $ this ->getAuthProvider ($ form_state );
148
+
149
+ $ userCpr = $ authProviderPlugin ->fetchValue ('cpr ' );
150
+ $ lookedUpCpr = $ cprLookupResult ->getCpr ();
151
+
152
+ $ this ->auditLogger ->info ('DataLookup ' , 'User with cpr ' . $ userCpr . ' looked up cpr ' . $ lookedUpCpr );
153
+
129
154
return $ cprLookupResult ;
130
155
}
131
156
@@ -196,7 +221,7 @@ public function lookupPersonData(FormStateInterface $form_state) {
196
221
/**
197
222
* Retrieves the CompanyLookupResult which is stored in form_state.
198
223
*
199
- * If there is no CBVRLookupResult , it is requested and saved for future uses.
224
+ * If there is no CVRLookupResult , it is requested and saved for future uses.
200
225
*
201
226
* @param \Drupal\Core\Form\FormStateInterface $form_state
202
227
* Form state.
@@ -408,4 +433,31 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform
408
433
}
409
434
}
410
435
436
+ /**
437
+ * Get active auth provider plugin.
438
+ *
439
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
440
+ * Form state.
441
+ *
442
+ * @return \Drupal\os2web_nemlogin\Plugin\AuthProviderInterface
443
+ * The active auth provider plugin.
444
+ *
445
+ * @throws \Drupal\Component\Plugin\Exception\PluginException
446
+ */
447
+ private function getAuthProvider (FormStateInterface $ form_state ): AuthProviderInterface {
448
+ /** @var \Drupal\webform\WebformSubmissionInterface Interface $webformSubmission */
449
+ $ webformSubmission = $ form_state ->getFormObject ()->getEntity ();
450
+ /** @var \Drupal\webform\WebformInterface $webform */
451
+ $ webform = $ webformSubmission ->getWebform ();
452
+ $ webformNemidSettings = $ webform ->getThirdPartySetting ('os2forms ' , 'os2forms_nemid ' );
453
+
454
+ // Getting auth plugin ID override.
455
+ $ authPluginId = NULL ;
456
+ if (!empty ($ webformNemidSettings ['session_type ' ])) {
457
+ $ authPluginId = $ webformNemidSettings ['session_type ' ];
458
+ }
459
+
460
+ return ($ authPluginId ) ? $ this ->authProviderService ->getPluginInstance ($ authPluginId ) : $ this ->authProviderService ->getActivePlugin ();
461
+ }
462
+
411
463
}
0 commit comments