Skip to content

Commit

Permalink
clean(ZMS): use logger in Oidc.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAFink authored Jan 24, 2025
1 parent 7d7a8d4 commit 03d5e99
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions zmsstatistic/src/Zmsstatistic/Oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,40 @@ public function readResponse(
$state = $request->getParam("state");
$authKey = \BO\Zmsclient\Auth::getKey();

// Log state validation attempt
error_log(json_encode([
\App::$log->info('OIDC state validation', [
'event' => 'oauth_state_validation',
'timestamp' => date('c'),
'provider' => \BO\Zmsclient\Auth::getOidcProvider(),
'application' => 'zmsstatistic',
'state_match' => ($state == $authKey)
]));
]);

if ($state == $authKey) {
try {
$workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
$username = $workstation->getUseraccount()->id . '@' . \BO\Zmsclient\Auth::getOidcProvider();

// Log workstation access with username
error_log(json_encode([
\App::$log->info('OIDC workstation access', [
'event' => 'oauth_workstation_access',
'timestamp' => date('c'),
'provider' => \BO\Zmsclient\Auth::getOidcProvider(),
'application' => 'zmsstatistic',
'username' => $username,
'workstation_id' => $workstation->id ?? 'unknown'
]));
]);

$departmentCount = $workstation->getUseraccount()->getDepartmentList()->count();

// Log department check with username
error_log(json_encode([
\App::$log->info('OIDC department check', [
'event' => 'oauth_department_check',
'timestamp' => date('c'),
'provider' => \BO\Zmsclient\Auth::getOidcProvider(),
'application' => 'zmsstatistic',
'username' => $username,
'department_count' => $departmentCount,
'has_departments' => ($departmentCount > 0)
]));
]);

if (0 == $departmentCount) {
return \BO\Slim\Render::redirect(
Expand All @@ -75,39 +73,36 @@ public function readResponse(
[]
);
} catch (\Exception $e) {
// Log workstation access error
error_log(json_encode([
\App::$log->error('OIDC workstation error', [
'event' => 'oauth_workstation_error',
'timestamp' => date('c'),
'provider' => \BO\Zmsclient\Auth::getOidcProvider(),
'application' => 'zmsstatistic',
'error' => $e->getMessage(),
'code' => $e->getCode()
]));
]);
throw $e;
}
}

// Log invalid state
error_log(json_encode([
\App::$log->error('OIDC invalid state', [
'event' => 'oauth_invalid_state',
'timestamp' => date('c'),
'provider' => \BO\Zmsclient\Auth::getOidcProvider(),
'application' => 'zmsstatistic'
]));
]);

throw new \BO\Slim\Exception\OAuthInvalid();

} catch (\Exception $e) {
// Log any uncaught exceptions
error_log(json_encode([
\App::$log->error('OIDC error', [
'event' => 'oauth_error',
'timestamp' => date('c'),
'provider' => \BO\Zmsclient\Auth::getOidcProvider(),
'application' => 'zmsstatistic',
'error' => $e->getMessage(),
'code' => $e->getCode()
]));
]);
throw $e;
}
}
Expand Down

0 comments on commit 03d5e99

Please sign in to comment.