38
38
import java .net .URLDecoder ;
39
39
import java .nio .charset .StandardCharsets ;
40
40
import java .util .ArrayList ;
41
- import java .util .Arrays ;
42
41
import java .util .Collections ;
43
42
import java .util .HashMap ;
44
43
import java .util .HashSet ;
240
239
* mechanism (the default).
241
240
* </li>
242
241
* <li>{@code authMechanismProperties=PROPERTY_NAME:PROPERTY_VALUE,PROPERTY_NAME2:PROPERTY_VALUE2}: This option allows authentication
243
- * mechanism properties to be set on the connection string. Property values must be percent-encoded individually, when
244
- * special characters are used, including {@code ,} (comma), {@code =}, {@code +}, {@code &}, and {@code %}. The
245
- * entire substring following the {@code =} should not itself be encoded.
242
+ * mechanism properties to be set on the connection string.
246
243
* </li>
247
244
* <li>{@code gssapiServiceName=string}: This option only applies to the GSSAPI mechanism and is used to alter the service name.
248
245
* Deprecated, please use {@code authMechanismProperties=SERVICE_NAME:string} instead.
@@ -908,7 +905,6 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
908
905
}
909
906
}
910
907
911
-
912
908
MongoCredential credential = null ;
913
909
if (mechanism != null ) {
914
910
credential = createMongoCredentialWithMechanism (mechanism , userName , password , authSource , gssapiServiceName );
@@ -926,9 +922,6 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
926
922
}
927
923
String key = mechanismPropertyKeyValue [0 ].trim ().toLowerCase ();
928
924
String value = mechanismPropertyKeyValue [1 ].trim ();
929
- if (decodeValueOfKeyValuePair (credential .getMechanism ())) {
930
- value = urldecode (value );
931
- }
932
925
if (MECHANISM_KEYS_DISALLOWED_IN_CONNECTION_STRING .contains (key )) {
933
926
throw new IllegalArgumentException (format ("The connection string contains disallowed mechanism properties. "
934
927
+ "'%s' must be set on the credential programmatically." , key ));
@@ -944,27 +937,6 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
944
937
return credential ;
945
938
}
946
939
947
- private static boolean decodeWholeOptionValue (final boolean isOidc , final String key ) {
948
- // The "whole option value" is the entire string following = in an option,
949
- // including separators when the value is a list or list of key-values.
950
- // This is the original parsing behaviour, but implies that users can
951
- // encode separators (much like they might with URL parameters). This
952
- // behaviour implies that users cannot encode "key-value" values that
953
- // contain a comma, because this will (after this "whole value decoding)
954
- // be parsed as a key-value separator, rather than part of a value.
955
- return !(isOidc && key .equals ("authmechanismproperties" ));
956
- }
957
-
958
- private static boolean decodeValueOfKeyValuePair (@ Nullable final String mechanismName ) {
959
- // Only authMechanismProperties should be individually decoded, and only
960
- // when the mechanism is OIDC. These will not have been decoded.
961
- return AuthenticationMechanism .MONGODB_OIDC .getMechanismName ().equals (mechanismName );
962
- }
963
-
964
- private static boolean isOidc (final List <String > options ) {
965
- return options .contains ("authMechanism=" + AuthenticationMechanism .MONGODB_OIDC .getMechanismName ());
966
- }
967
-
968
940
private MongoCredential createMongoCredentialWithMechanism (final AuthenticationMechanism mechanism , final String userName ,
969
941
@ Nullable final char [] password ,
970
942
@ Nullable final String authSource ,
@@ -1049,9 +1021,7 @@ private Map<String, List<String>> parseOptions(final String optionsPart) {
1049
1021
return optionsMap ;
1050
1022
}
1051
1023
1052
- List <String > options = Arrays .asList (optionsPart .split ("&|;" ));
1053
- boolean isOidc = isOidc (options );
1054
- for (final String part : options ) {
1024
+ for (final String part : optionsPart .split ("&|;" )) {
1055
1025
if (part .isEmpty ()) {
1056
1026
continue ;
1057
1027
}
@@ -1063,10 +1033,7 @@ private Map<String, List<String>> parseOptions(final String optionsPart) {
1063
1033
if (valueList == null ) {
1064
1034
valueList = new ArrayList <>(1 );
1065
1035
}
1066
- if (decodeWholeOptionValue (isOidc , key )) {
1067
- value = urldecode (value );
1068
- }
1069
- valueList .add (value );
1036
+ valueList .add (urldecode (value ));
1070
1037
optionsMap .put (key , valueList );
1071
1038
} else {
1072
1039
throw new IllegalArgumentException (format ("The connection string contains an invalid option '%s'. "
0 commit comments