36
36
import io .r2dbc .postgresql .message .backend .NoticeResponse ;
37
37
import io .r2dbc .postgresql .util .Assert ;
38
38
import io .r2dbc .postgresql .util .LogLevel ;
39
+ import org .reactivestreams .Publisher ;
40
+ import reactor .core .publisher .Mono ;
39
41
import reactor .netty .resources .LoopResources ;
40
42
import reactor .util .annotation .Nullable ;
41
43
@@ -103,7 +105,7 @@ public final class PostgresqlConnectionConfiguration {
103
105
104
106
private final Map <String , String > options ;
105
107
106
- private final CharSequence password ;
108
+ private final Publisher < CharSequence > password ;
107
109
108
110
private final boolean preferAttachedBuffers ;
109
111
@@ -123,18 +125,18 @@ public final class PostgresqlConnectionConfiguration {
123
125
124
126
private final TimeZone timeZone ;
125
127
126
- private final String username ;
128
+ private final Publisher < String > username ;
127
129
128
130
private PostgresqlConnectionConfiguration (String applicationName , boolean autodetectExtensions , @ Nullable boolean compatibilityMode , @ Nullable Duration connectTimeout , @ Nullable String database ,
129
131
LogLevel errorResponseLogLevel ,
130
132
List <Extension > extensions , ToIntFunction <String > fetchSize , boolean forceBinary , @ Nullable Duration lockWaitTimeout ,
131
133
@ Nullable LoopResources loopResources ,
132
134
@ 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 ,
134
136
int preparedStatementCacheQueries , @ Nullable String schema ,
135
137
@ Nullable SingleHostConfiguration singleHostConfiguration , SSLConfig sslConfig , @ Nullable Duration statementTimeout ,
136
138
boolean tcpKeepAlive , boolean tcpNoDelay , TimeZone timeZone ,
137
- String username ) {
139
+ Publisher < String > username ) {
138
140
this .applicationName = Assert .requireNonNull (applicationName , "applicationName must not be null" );
139
141
this .autodetectExtensions = autodetectExtensions ;
140
142
this .compatibilityMode = compatibilityMode ;
@@ -200,7 +202,7 @@ public String toString() {
200
202
", multiHostConfiguration='" + this .multiHostConfiguration + '\'' +
201
203
", noticeLogLevel='" + this .noticeLogLevel + '\'' +
202
204
", options='" + this .options + '\'' +
203
- ", password='" + obfuscate (this .password != null ? this . password . length () : 0 ) + '\'' +
205
+ ", password='" + obfuscate (this .password != null ? 4 : 0 ) + '\'' +
204
206
", preferAttachedBuffers=" + this .preferAttachedBuffers +
205
207
", singleHostConfiguration=" + this .singleHostConfiguration +
206
208
", statementTimeout=" + this .statementTimeout +
@@ -261,8 +263,7 @@ Map<String, String> getOptions() {
261
263
return Collections .unmodifiableMap (this .options );
262
264
}
263
265
264
- @ Nullable
265
- CharSequence getPassword () {
266
+ Publisher <CharSequence > getPassword () {
266
267
return this .password ;
267
268
}
268
269
@@ -290,7 +291,7 @@ SingleHostConfiguration getRequiredSingleHostConfiguration() {
290
291
return config ;
291
292
}
292
293
293
- String getUsername () {
294
+ Publisher < String > getUsername () {
294
295
return this .username ;
295
296
}
296
297
@@ -380,7 +381,7 @@ public static final class Builder {
380
381
private Map <String , String > options ;
381
382
382
383
@ Nullable
383
- private CharSequence password ;
384
+ private Publisher < CharSequence > password ;
384
385
385
386
private boolean preferAttachedBuffers = false ;
386
387
@@ -423,7 +424,7 @@ public static final class Builder {
423
424
private LoopResources loopResources = null ;
424
425
425
426
@ Nullable
426
- private String username ;
427
+ private Publisher < String > username ;
427
428
428
429
private Builder () {
429
430
}
@@ -743,7 +744,31 @@ public Builder options(Map<String, String> options) {
743
744
* @return this {@link Builder}
744
745
*/
745
746
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 );
747
772
return this ;
748
773
}
749
774
@@ -780,7 +805,6 @@ public Builder preferAttachedBuffers(boolean preferAttachedBuffers) {
780
805
*
781
806
* @param preparedStatementCacheQueries the preparedStatementCacheQueries
782
807
* @return this {@link Builder}
783
- * @throws IllegalArgumentException if {@code username} is {@code null}
784
808
* @since 0.8.1
785
809
*/
786
810
public Builder preparedStatementCacheQueries (int preparedStatementCacheQueries ) {
@@ -1023,10 +1047,34 @@ public Builder timeZone(TimeZone timeZone) {
1023
1047
* @throws IllegalArgumentException if {@code username} is {@code null}
1024
1048
*/
1025
1049
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 ) {
1026
1062
this .username = Assert .requireNonNull (username , "username must not be null" );
1027
1063
return this ;
1028
1064
}
1029
1065
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
+
1030
1078
@ Override
1031
1079
public String toString () {
1032
1080
return "Builder{" +
@@ -1044,7 +1092,7 @@ public String toString() {
1044
1092
", multiHostConfiguration='" + this .multiHostConfiguration + '\'' +
1045
1093
", noticeLogLevel='" + this .noticeLogLevel + '\'' +
1046
1094
", parameters='" + this .options + '\'' +
1047
- ", password='" + obfuscate (this .password != null ? this . password . length () : 0 ) + '\'' +
1095
+ ", password='" + obfuscate (this .password != null ? 4 : 0 ) + '\'' +
1048
1096
", preparedStatementCacheQueries='" + this .preparedStatementCacheQueries + '\'' +
1049
1097
", schema='" + this .schema + '\'' +
1050
1098
", singleHostConfiguration='" + this .singleHostConfiguration + '\'' +
0 commit comments