|
56 | 56 | import static com.mongodb.internal.connection.OidcAuthenticator.OidcValidator.validateCreateOidcCredential; |
57 | 57 | import static java.lang.String.format; |
58 | 58 | import static java.util.Arrays.asList; |
| 59 | +import static java.util.Collections.emptyList; |
59 | 60 | import static java.util.Collections.singletonList; |
60 | 61 | import static java.util.Collections.unmodifiableList; |
61 | 62 |
|
@@ -505,7 +506,7 @@ public ConnectionString(final String connectionString, @Nullable final DnsClient |
505 | 506 | throw new IllegalArgumentException("srvMaxHosts can not be specified with replica set name"); |
506 | 507 | } |
507 | 508 |
|
508 | | - validateProxyParameters(); |
| 509 | + validateProxyParameters(combinedOptionsMaps); |
509 | 510 |
|
510 | 511 | credential = createCredentials(combinedOptionsMaps, userName, password); |
511 | 512 | warnOnUnsupportedOptions(combinedOptionsMaps); |
@@ -1226,7 +1227,7 @@ private void validatePort(final String port) { |
1226 | 1227 | } |
1227 | 1228 | } |
1228 | 1229 |
|
1229 | | - private void validateProxyParameters() { |
| 1230 | + private void validateProxyParameters(final Map<String, List<String>> optionsMap) { |
1230 | 1231 | if (proxyHost == null) { |
1231 | 1232 | if (proxyPort != null) { |
1232 | 1233 | throw new IllegalArgumentException("proxyPort can only be specified with proxyHost"); |
@@ -1259,6 +1260,23 @@ private void validateProxyParameters() { |
1259 | 1260 | throw new IllegalArgumentException( |
1260 | 1261 | "Both proxyUsername and proxyPassword must be set together. They cannot be set individually"); |
1261 | 1262 | } |
| 1263 | + |
| 1264 | + if (containsDuplicatedOptions("proxyhost", optionsMap)) { |
| 1265 | + throw new IllegalArgumentException("Duplicated values for proxyHost: " + optionsMap.get("proxyhost")); |
| 1266 | + } |
| 1267 | + if (containsDuplicatedOptions("proxyport", optionsMap)) { |
| 1268 | + throw new IllegalArgumentException("Duplicated values for proxyPort: " + optionsMap.get("proxyport")); |
| 1269 | + } |
| 1270 | + if (containsDuplicatedOptions("proxypassword", optionsMap)) { |
| 1271 | + throw new IllegalArgumentException("Duplicated values for proxyPassword: " + optionsMap.get("proxypassword")); |
| 1272 | + } |
| 1273 | + if (containsDuplicatedOptions("proxyusername", optionsMap)) { |
| 1274 | + throw new IllegalArgumentException("Duplicated values for proxyUsername: " + optionsMap.get("proxyusername")); |
| 1275 | + } |
| 1276 | + } |
| 1277 | + |
| 1278 | + private static boolean containsDuplicatedOptions(final String optionName, final Map<String, List<String>> optionsMap) { |
| 1279 | + return optionsMap.getOrDefault(optionName, emptyList()).size() > 1; |
1262 | 1280 | } |
1263 | 1281 |
|
1264 | 1282 | private int countOccurrences(final String haystack, final String needle) { |
|
0 commit comments