66
77use Horde \Core \Auth \Jwt \GeneratedJwt ;
88use Horde_Registry ;
9+ use Psr \Log \LoggerInterface ;
910use Exception ;
1011use Horde ;
1112
@@ -58,11 +59,13 @@ class AuthenticationService
5859{
5960 /**
6061 * @param Horde_Registry $registry Horde registry
62+ * @param LoggerInterface $logger PSR-3 logger
6163 * @param JwtService|null $jwtService JWT service (optional, for dual-mode)
6264 */
6365 public function __construct (
6466 private readonly Horde_Registry $ registry ,
65- private readonly ?JwtService $ jwtService = null
67+ private readonly LoggerInterface $ logger ,
68+ private readonly ?JwtService $ jwtService = null ,
6669 ) {}
6770
6871 /**
@@ -108,13 +111,23 @@ public function authenticate(string $username, string $password, array $options
108111 $ authCredentials = array_merge ($ authCredentials , $ options ['auth_params ' ]);
109112 }
110113
111- Horde::log ("AUTHENTICATE: Attempting auth for username= $ username " , 'DEBUG ' );
114+ $ this ->logger ->debug ('Authentication attempt ' , [
115+ 'username ' => $ username ,
116+ 'generate_jwt ' => $ generateJwt ,
117+ 'has_jwt_service ' => $ this ->jwtService !== null ,
118+ ]);
112119 $ authResult = $ auth ->authenticate ($ username , $ authCredentials );
113- Horde::log ("AUTHENTICATE: Auth result= " . ($ authResult ? 'true ' : 'false ' ) . " for username= $ username " , 'DEBUG ' );
120+ $ this ->logger ->debug ('Authentication result ' , [
121+ 'username ' => $ username ,
122+ 'success ' => $ authResult ,
123+ ]);
114124
115125 // Check if authentication actually succeeded
116126 if (!$ authResult ) {
117- Horde::log ("AUTHENTICATE: Authentication failed for username= $ username " , 'ERR ' );
127+ $ this ->logger ->error ('Authentication failed ' , [
128+ 'username ' => $ username ,
129+ 'reason ' => 'auth_backend_returned_false ' ,
130+ ]);
118131 return [
119132 'success ' => false ,
120133 'error ' => 'Authentication failed ' ,
@@ -125,11 +138,11 @@ public function authenticate(string $username, string $password, array $options
125138 $ credentials = $ auth ->getCredential ('credentials ' ) ?: ['password ' => $ password ];
126139 $ userId = $ username ;
127140
128- Horde::log ("AUTHENTICATE: username= $ username, generateJwt= $ generateJwt, hasJwtService= " . ($ this ->jwtService !== null ? 'yes ' : 'no ' ), 'DEBUG ' );
129-
130141 // If JWT enabled, generate tokens
131142 if ($ generateJwt && $ this ->jwtService !== null ) {
132- Horde::log ("AUTHENTICATE: Generating JWT tokens " , 'DEBUG ' );
143+ $ this ->logger ->debug ('Generating JWT tokens ' , [
144+ 'username ' => $ username ,
145+ ]);
133146
134147 // Generate JWT tokens
135148 $ jwtClaims = $ this ->buildJwtClaims ($ username , $ options );
@@ -152,7 +165,12 @@ public function authenticate(string $username, string $password, array $options
152165 ['refresh_jti ' => $ jti ] // Link access token to session
153166 ));
154167
155- Horde::log ("AUTHENTICATE: JWT tokens generated, session_id= " . session_id () . ", jti= $ jti " , 'DEBUG ' );
168+ $ this ->logger ->debug ('JWT tokens generated ' , [
169+ 'username ' => $ username ,
170+ 'session_id ' => session_id (),
171+ 'jti ' => $ jti ,
172+ 'access_token_expires_at ' => $ accessToken ->expiresAt ,
173+ ]);
156174
157175 return [
158176 'success ' => true ,
0 commit comments