2020import io .debezium .platform .data .dto .ConnectionValidationResult ;
2121import io .debezium .platform .domain .views .Connection ;
2222import io .debezium .platform .environment .connection .ConnectionValidator ;
23+ import io .debezium .util .Strings ;
2324
2425/**
2526 * Implementation of {@link ConnectionValidator} for Infinispan connections.
@@ -103,13 +104,19 @@ public ConnectionValidationResult validate(Connection connectionConfig) {
103104 : null ;
104105
105106 // Infinispan treats both-empty credentials as no-auth, but one-empty causes TransportException.
106- boolean hasUser = user != null && !user .isEmpty ();
107- boolean hasPassword = password != null && !password .isEmpty ();
108- if (hasUser != hasPassword ) {
107+ if (Strings .isNullOrEmpty (user ) != Strings .isNullOrEmpty (password )) {
109108 return ConnectionValidationResult .failed ("User and password must both be provided for authentication" );
110109 }
111110
112- return performConnectionValidation (serverHost , serverPort , cacheName , user , password );
111+ String serverUri ;
112+ if (!Strings .isNullOrEmpty (user ) && !Strings .isNullOrEmpty (password )) {
113+ serverUri = HOTROD_URI_WITH_AUTH .formatted (user , password , serverHost , serverPort );
114+ }
115+ else {
116+ serverUri = HOTROD_URI_NO_AUTH .formatted (serverHost , serverPort );
117+ }
118+
119+ return performConnectionValidation (serverHost , serverPort , cacheName , serverUri );
113120 }
114121 catch (IllegalArgumentException e ) {
115122 return ConnectionValidationResult .failed (e .getMessage ());
@@ -127,25 +134,13 @@ public ConnectionValidationResult validate(Connection connectionConfig) {
127134 * @param serverHost the Infinispan server hostname
128135 * @param serverPort the Infinispan server port
129136 * @param cacheName the Infinispan cache name to verify
130- * @param user optional username for authentication
131- * @param password optional password for authentication
137+ * @param serverUri the HotRod URI including authentication if applicable
132138 * @return ConnectionValidationResult indicating success or failure
133139 */
134- private ConnectionValidationResult performConnectionValidation (String serverHost , int serverPort , String cacheName , String user , String password ) {
140+ private ConnectionValidationResult performConnectionValidation (String serverHost , int serverPort , String cacheName , String serverUri ) {
135141
136142 LOGGER .debug ("Creating Infinispan RemoteCacheManager for validation" );
137143
138- String serverUri ;
139- boolean hasUser = user != null && !user .isEmpty ();
140- boolean hasPassword = password != null && !password .isEmpty ();
141-
142- if (hasUser && hasPassword ) {
143- serverUri = HOTROD_URI_WITH_AUTH .formatted (user , password , serverHost , serverPort );
144- }
145- else {
146- serverUri = HOTROD_URI_NO_AUTH .formatted (serverHost , serverPort );
147- }
148-
149144 ConfigurationBuilder clientConfig = new ConfigurationBuilder ();
150145 clientConfig .uri (serverUri );
151146 clientConfig .connectionTimeout (defaultConnectionTimeoutSeconds * 1000 );
0 commit comments