88use Drupal \os2forms_nemid \Element \NemidCompanyCvrFetchData ;
99use Drupal \os2forms_nemid \Element \NemidCompanyPNumber ;
1010use Drupal \os2forms_nemid \Element \NemidCprFetchData ;
11+ use Drupal \os2web_audit \Service \Logger ;
1112use Drupal \os2web_datalookup \LookupResult \CompanyLookupResult ;
1213use Drupal \os2web_datalookup \LookupResult \CprLookupResult ;
1314use Drupal \os2web_datalookup \Plugin \DataLookupManager ;
15+ use Drupal \os2web_nemlogin \Plugin \AuthProviderInterface ;
1416use Drupal \os2web_nemlogin \Service \AuthProviderService ;
1517use Drupal \webform \WebformSubmissionInterface ;
1618
@@ -70,6 +72,13 @@ class FormsHelper {
7072 */
7173 private RouteMatchInterface $ routeMatch ;
7274
75+ /**
76+ * An audit logger.
77+ *
78+ * @var \Drupal\os2web_audit\Service\Logger
79+ */
80+ private Logger $ auditLogger ;
81+
7382 /**
7483 * Constructor.
7584 *
@@ -79,11 +88,19 @@ class FormsHelper {
7988 * Datalookup plugin manager.
8089 * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
8190 * Route match service.
91+ * @param \Drupal\os2web_audit\Service\Logger $auditLogger
92+ * Audit logger.
8293 */
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+ ) {
84100 $ this ->authProviderService = $ authProviderService ;
85101 $ this ->dataLookManager = $ dataLookPluginManager ;
86102 $ this ->routeMatch = $ routeMatch ;
103+ $ this ->auditLogger = $ auditLogger ;
87104 }
88105
89106 /**
@@ -126,6 +143,14 @@ public function retrieveCprLookupResult(FormStateInterface $form_state) {
126143 }
127144 }
128145
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+
129154 return $ cprLookupResult ;
130155 }
131156
@@ -196,7 +221,7 @@ public function lookupPersonData(FormStateInterface $form_state) {
196221 /**
197222 * Retrieves the CompanyLookupResult which is stored in form_state.
198223 *
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.
200225 *
201226 * @param \Drupal\Core\Form\FormStateInterface $form_state
202227 * Form state.
@@ -408,4 +433,31 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform
408433 }
409434 }
410435
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+
411463}
0 commit comments