3636import  io .r2dbc .postgresql .message .backend .NoticeResponse ;
3737import  io .r2dbc .postgresql .util .Assert ;
3838import  io .r2dbc .postgresql .util .LogLevel ;
39+ import  org .reactivestreams .Publisher ;
40+ import  reactor .core .publisher .Mono ;
3941import  reactor .netty .resources .LoopResources ;
4042import  reactor .util .annotation .Nullable ;
4143
@@ -103,7 +105,7 @@ public final class PostgresqlConnectionConfiguration {
103105
104106    private  final  Map <String , String > options ;
105107
106-     private  final  CharSequence  password ;
108+     private  final  Publisher < CharSequence >  password ;
107109
108110    private  final  boolean  preferAttachedBuffers ;
109111
@@ -123,18 +125,18 @@ public final class PostgresqlConnectionConfiguration {
123125
124126    private  final  TimeZone  timeZone ;
125127
126-     private  final  String  username ;
128+     private  final  Publisher < String >  username ;
127129
128130    private  PostgresqlConnectionConfiguration (String  applicationName , boolean  autodetectExtensions , @ Nullable  boolean  compatibilityMode , @ Nullable  Duration  connectTimeout , @ Nullable  String  database ,
129131                                              LogLevel  errorResponseLogLevel ,
130132                                              List <Extension > extensions , ToIntFunction <String > fetchSize , boolean  forceBinary , @ Nullable  Duration  lockWaitTimeout ,
131133                                              @ Nullable  LoopResources  loopResources ,
132134                                              @ Nullable  MultiHostConfiguration  multiHostConfiguration ,
133-                                               LogLevel  noticeLogLevel , @ Nullable  Map <String , String > options , @ Nullable   CharSequence  password , boolean  preferAttachedBuffers ,
135+                                               LogLevel  noticeLogLevel , @ Nullable  Map <String , String > options , Publisher < CharSequence >  password , boolean  preferAttachedBuffers ,
134136                                              int  preparedStatementCacheQueries , @ Nullable  String  schema ,
135137                                              @ Nullable  SingleHostConfiguration  singleHostConfiguration , SSLConfig  sslConfig , @ Nullable  Duration  statementTimeout ,
136138                                              boolean  tcpKeepAlive , boolean  tcpNoDelay , TimeZone  timeZone ,
137-                                               String  username ) {
139+                                               Publisher < String >  username ) {
138140        this .applicationName  = Assert .requireNonNull (applicationName , "applicationName must not be null" );
139141        this .autodetectExtensions  = autodetectExtensions ;
140142        this .compatibilityMode  = compatibilityMode ;
@@ -200,7 +202,7 @@ public String toString() {
200202            ", multiHostConfiguration='"  + this .multiHostConfiguration  + '\''  +
201203            ", noticeLogLevel='"  + this .noticeLogLevel  + '\''  +
202204            ", options='"  + this .options  + '\''  +
203-             ", password='"  + obfuscate (this .password  != null  ? this . password . length ()  : 0 ) + '\''  +
205+             ", password='"  + obfuscate (this .password  != null  ? 4  : 0 ) + '\''  +
204206            ", preferAttachedBuffers="  + this .preferAttachedBuffers  +
205207            ", singleHostConfiguration="  + this .singleHostConfiguration  +
206208            ", statementTimeout="  + this .statementTimeout  +
@@ -261,8 +263,7 @@ Map<String, String> getOptions() {
261263        return  Collections .unmodifiableMap (this .options );
262264    }
263265
264-     @ Nullable 
265-     CharSequence  getPassword () {
266+     Publisher <CharSequence > getPassword () {
266267        return  this .password ;
267268    }
268269
@@ -290,7 +291,7 @@ SingleHostConfiguration getRequiredSingleHostConfiguration() {
290291        return  config ;
291292    }
292293
293-     String  getUsername () {
294+     Publisher < String >  getUsername () {
294295        return  this .username ;
295296    }
296297
@@ -380,7 +381,7 @@ public static final class Builder {
380381        private  Map <String , String > options ;
381382
382383        @ Nullable 
383-         private  CharSequence  password ;
384+         private  Publisher < CharSequence >  password ;
384385
385386        private  boolean  preferAttachedBuffers  = false ;
386387
@@ -423,7 +424,7 @@ public static final class Builder {
423424        private  LoopResources  loopResources  = null ;
424425
425426        @ Nullable 
426-         private  String  username ;
427+         private  Publisher < String >  username ;
427428
428429        private  Builder () {
429430        }
@@ -743,7 +744,31 @@ public Builder options(Map<String, String> options) {
743744         * @return this {@link Builder} 
744745         */ 
745746        public  Builder  password (@ Nullable  CharSequence  password ) {
746-             this .password  = password ;
747+             this .password  = Mono .justOrEmpty (password );
748+             return  this ;
749+         }
750+ 
751+         /** 
752+          * Configure the password publisher. The publisher is used on each authentication attempt. 
753+          * 
754+          * @param password the password 
755+          * @return this {@link Builder} 
756+          * @since 1.0.3 
757+          */ 
758+         public  Builder  password (Publisher <CharSequence > password ) {
759+             this .password  = Mono .from (password );
760+             return  this ;
761+         }
762+ 
763+         /** 
764+          * Configure the password supplier. The supplier is used on each authentication attempt. 
765+          * 
766+          * @param password the password 
767+          * @return this {@link Builder} 
768+          * @since 1.0.3 
769+          */ 
770+         public  Builder  password (Supplier <CharSequence > password ) {
771+             this .password  = Mono .fromSupplier (password );
747772            return  this ;
748773        }
749774
@@ -780,7 +805,6 @@ public Builder preferAttachedBuffers(boolean preferAttachedBuffers) {
780805         * 
781806         * @param preparedStatementCacheQueries the preparedStatementCacheQueries 
782807         * @return this {@link Builder} 
783-          * @throws IllegalArgumentException if {@code username} is {@code null} 
784808         * @since 0.8.1 
785809         */ 
786810        public  Builder  preparedStatementCacheQueries (int  preparedStatementCacheQueries ) {
@@ -1023,10 +1047,34 @@ public Builder timeZone(TimeZone timeZone) {
10231047         * @throws IllegalArgumentException if {@code username} is {@code null} 
10241048         */ 
10251049        public  Builder  username (String  username ) {
1050+             this .username  = Mono .just (Assert .requireNonNull (username , "username must not be null" ));
1051+             return  this ;
1052+         }
1053+ 
1054+         /** 
1055+          * Configure the username publisher. The publisher is used on each authentication attempt. 
1056+          * 
1057+          * @param username the username 
1058+          * @return this {@link Builder} 
1059+          * @throws IllegalArgumentException if {@code username} is {@code null} 
1060+          */ 
1061+         public  Builder  username (Publisher <String > username ) {
10261062            this .username  = Assert .requireNonNull (username , "username must not be null" );
10271063            return  this ;
10281064        }
10291065
1066+         /** 
1067+          * Configure the username supplier. The supplier is used on each authentication attempt. 
1068+          * 
1069+          * @param username the username 
1070+          * @return this {@link Builder} 
1071+          * @throws IllegalArgumentException if {@code username} is {@code null} 
1072+          */ 
1073+         public  Builder  username (Supplier <String > username ) {
1074+             this .username  = Mono .fromSupplier (Assert .requireNonNull (username , "username must not be null" ));
1075+             return  this ;
1076+         }
1077+ 
10301078        @ Override 
10311079        public  String  toString () {
10321080            return  "Builder{"  +
@@ -1044,7 +1092,7 @@ public String toString() {
10441092                ", multiHostConfiguration='"  + this .multiHostConfiguration  + '\''  +
10451093                ", noticeLogLevel='"  + this .noticeLogLevel  + '\''  +
10461094                ", parameters='"  + this .options  + '\''  +
1047-                 ", password='"  + obfuscate (this .password  != null  ? this . password . length ()  : 0 ) + '\''  +
1095+                 ", password='"  + obfuscate (this .password  != null  ? 4  : 0 ) + '\''  +
10481096                ", preparedStatementCacheQueries='"  + this .preparedStatementCacheQueries  + '\''  +
10491097                ", schema='"  + this .schema  + '\''  +
10501098                ", singleHostConfiguration='"  + this .singleHostConfiguration  + '\''  +
0 commit comments