@@ -2,15 +2,8 @@ use std::collections::HashMap;
22use std:: sync:: Arc ;
33
44use async_trait:: async_trait;
5- use futures:: sink:: Sink ;
6- use pgwire:: api:: auth:: {
7- finish_authentication, save_startup_parameters_to_metadata, AuthSource ,
8- DefaultServerParameterProvider , LoginInfo , Password , StartupHandler ,
9- } ;
10- use pgwire:: api:: ClientInfo ;
5+ use pgwire:: api:: auth:: { AuthSource , LoginInfo , Password } ;
116use pgwire:: error:: { PgWireError , PgWireResult } ;
12- use pgwire:: messages:: { PgWireBackendMessage , PgWireFrontendMessage } ;
13- use std:: fmt:: Debug ;
147use tokio:: sync:: RwLock ;
158
169/// User information stored in the authentication system
@@ -591,18 +584,13 @@ impl DfAuthSource {
591584#[ async_trait]
592585impl AuthSource for DfAuthSource {
593586 async fn get_password ( & self , login : & LoginInfo ) -> PgWireResult < Password > {
594- // For development convenience, allow postgres superuser without password
595587 if let Some ( username) = login. user ( ) {
596- if username == "postgres" {
597- // Note: In production, implement proper password authentication
598- return Ok ( Password :: new ( None , vec ! [ ] ) ) ;
599- }
600-
601588 // Check if user exists in our RBAC system
602589 if let Some ( user) = self . auth_manager . get_user ( username) . await {
603590 if user. can_login {
604- // Return password hash for authentication
605- // In a real implementation, this would be properly hashed
591+ // Return the stored password hash for authentication
592+ // The pgwire authentication handlers (cleartext/md5/scram) will
593+ // handle the actual password verification process
606594 Ok ( Password :: new ( None , user. password_hash . into_bytes ( ) ) )
607595 } else {
608596 Err ( PgWireError :: UserError ( Box :: new (
@@ -634,68 +622,42 @@ impl AuthSource for DfAuthSource {
634622 }
635623}
636624
637- /// Custom startup handler that performs authentication
638- ///
639- /// DEPRECATED: Use DfAuthSource with cleartext/md5/scram authentication instead
640- pub struct AuthStartupHandler {
641- auth_manager : Arc < AuthManager > ,
642- }
643-
644- impl AuthStartupHandler {
645- pub fn new ( auth_manager : Arc < AuthManager > ) -> Self {
646- AuthStartupHandler { auth_manager }
647- }
648- }
649-
650- #[ async_trait]
651- impl StartupHandler for AuthStartupHandler {
652- async fn on_startup < C > (
653- & self ,
654- client : & mut C ,
655- message : PgWireFrontendMessage ,
656- ) -> PgWireResult < ( ) >
657- where
658- C : ClientInfo + Sink < PgWireBackendMessage > + Unpin + Send ,
659- C :: Error : Debug ,
660- PgWireError : From < <C as Sink < PgWireBackendMessage > >:: Error > ,
661- {
662- if let PgWireFrontendMessage :: Startup ( ref startup) = message {
663- save_startup_parameters_to_metadata ( client, startup) ;
664-
665- // Extract username from startup message
666- let username = startup
667- . parameters
668- . get ( "user" )
669- . unwrap_or ( & "anonymous" . to_string ( ) )
670- . clone ( ) ;
671-
672- // For now, we'll do basic authentication
673- // In a full implementation, this would involve password authentication
674- let is_authenticated = if username == "postgres" {
675- // Always allow postgres user for compatibility
676- true
677- } else {
678- // Check if user exists in our system
679- self . auth_manager . get_user ( & username) . await . is_some ( )
680- } ;
681-
682- if !is_authenticated {
683- return Err ( PgWireError :: UserError ( Box :: new (
684- pgwire:: error:: ErrorInfo :: new (
685- "FATAL" . to_string ( ) ,
686- "28P01" . to_string ( ) , // invalid_password
687- format ! ( "password authentication failed for user \" {username}\" " ) ,
688- ) ,
689- ) ) ) ;
690- }
691-
692- // Complete authentication process
693- finish_authentication ( client, & DefaultServerParameterProvider :: default ( ) ) . await ?;
694- }
695-
696- Ok ( ( ) )
697- }
698- }
625+ // REMOVED: Custom startup handler approach
626+ //
627+ // Instead of implementing a custom StartupHandler, use the proper pgwire authentication:
628+ //
629+ // For cleartext authentication:
630+ // ```rust
631+ // use pgwire::api::auth::cleartext::CleartextStartupHandler;
632+ //
633+ // let auth_source = Arc::new(DfAuthSource::new(auth_manager));
634+ // let authenticator = CleartextStartupHandler::new(
635+ // auth_source,
636+ // Arc::new(DefaultServerParameterProvider::default())
637+ // );
638+ // ```
639+ //
640+ // For MD5 authentication:
641+ // ```rust
642+ // use pgwire::api::auth::md5::MD5StartupHandler;
643+ //
644+ // let auth_source = Arc::new(DfAuthSource::new(auth_manager));
645+ // let authenticator = MD5StartupHandler::new(
646+ // auth_source,
647+ // Arc::new(DefaultServerParameterProvider::default())
648+ // );
649+ // ```
650+ //
651+ // For SCRAM authentication (requires "server-api-scram" feature):
652+ // ```rust
653+ // use pgwire::api::auth::scram::SASLScramAuthStartupHandler;
654+ //
655+ // let auth_source = Arc::new(DfAuthSource::new(auth_manager));
656+ // let authenticator = SASLScramAuthStartupHandler::new(
657+ // auth_source,
658+ // Arc::new(DefaultServerParameterProvider::default())
659+ // );
660+ // ```
699661
700662/// Simple AuthSource implementation that accepts any user with empty password
701663pub struct SimpleAuthSource {
0 commit comments