Skip to content

Commit b4679bd

Browse files
committed
Fix AuthPanel serialization issue with PDO objects
The identity object and authentication providers contained references to PDO connections which cannot be serialized. This caused DebugKit to fail when viewing the Auth panel. Changes: - Store identity->getOriginalData() instead of the raw Identity object - Store provider class names as strings instead of provider objects - Update template to work with the new data structure
1 parent 4df33c4 commit b4679bd

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/Panel/AuthPanel.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,15 @@ public function shutdown(EventInterface $event): void {
103103
$data['config'] = $authUserComponent->getConfig();
104104
$data['access'] = $access;
105105

106-
$data['identity'] = $request->getAttribute('identity');
106+
$identity = $request->getAttribute('identity');
107+
// Store as array to avoid serialization issues with PDO/ORM connections
108+
$data['identity'] = $identity ? $identity->getOriginalData() : null;
109+
$data['identityClass'] = $identity ? get_class($identity) : null;
107110

108111
/** @var \Authentication\AuthenticationService|null $auth */
109112
$auth = $request->getAttribute('authentication');
110-
$data['authenticationProvider'] = $auth ? $auth->getAuthenticationProvider() : null;
111-
$data['identificationProvider'] = $auth ? $auth->getIdentificationProvider() : null;
113+
$data['authenticationProvider'] = $auth?->getAuthenticationProvider() ? get_class($auth->getAuthenticationProvider()) : null;
114+
$data['identificationProvider'] = $auth?->getIdentificationProvider() ? get_class($auth->getIdentificationProvider()) : null;
112115

113116
$this->_data = $data;
114117
}

templates/element/auth_panel.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
* @var bool[] $access
1010
* @var string $path;
1111
* @var array<string, mixed> $config
12-
* @var \Authorization\Identity|\Authentication\Identity|null $identity
13-
* @var \Authentication\Authenticator\AuthenticatorInterface|null $authenticationProvider
14-
* @var \Authentication\Identifier\IdentifierInterface|null $identificationProvider
12+
* @var array|null $identity
13+
* @var string|null $identityClass
14+
* @var string|null $authenticationProvider
15+
* @var string|null $identificationProvider
1516
*/
1617

1718
use Cake\Error\Debugger;
@@ -67,12 +68,12 @@
6768

6869
<?php if ($authenticationProvider) {
6970
echo '<p>';
70-
echo 'Authentication provider used: ' . get_class($authenticationProvider);
71+
echo 'Authentication provider used: ' . h($authenticationProvider);
7172
echo '</p>';
7273
} ?>
7374
<?php if ($identificationProvider) {
7475
echo '<p>';
75-
echo 'Identification provider used: ' . get_class($identificationProvider);
76+
echo 'Identification provider used: ' . h($identificationProvider);
7677
echo '</p>';
7778
} ?>
7879

@@ -128,12 +129,13 @@
128129
<?php if ($identity) { ?>
129130
<h2>Identity</h2>
130131
<?php
131-
echo '<h4>' . get_class($identity) . '</h4>';
132+
if (!empty($identityClass)) {
133+
echo '<h4>' . h($identityClass) . '</h4>';
134+
}
132135
?>
133136

134137
<?php
135-
$user = $identity->getOriginalData();
136-
echo Debugger::exportVar($user);
138+
echo Debugger::exportVar($identity);
137139
?>
138140
<?php } ?>
139141

0 commit comments

Comments
 (0)