Skip to content

Commit 18487ef

Browse files
committed
DATAMONGO-1713 - Polishing.
Fix typos. Migrate to diamond syntax where applicable. Use Arrays.stream(…) instead of Arrays.asList(…).stream(). Mention percent sign as required char for URL encoding and reference RFC 3986 in documentation. Original pull request: spring-projects#477.
1 parent 1aa2ee5 commit 18487ef

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoCredentialPropertyEditor.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/**
3333
* Parse a {@link String} to a Collection of {@link MongoCredential}.
34-
*
34+
*
3535
* @author Christoph Strobl
3636
* @author Oliver Gierke
3737
* @since 1.7
@@ -41,10 +41,10 @@ public class MongoCredentialPropertyEditor extends PropertyEditorSupport {
4141
private static final Pattern GROUP_PATTERN = Pattern.compile("(\\\\?')(.*?)\\1");
4242

4343
private static final String AUTH_MECHANISM_KEY = "uri.authMechanism";
44-
private static final String USERNAME_PASSWORD_DELIMINATOR = ":";
45-
private static final String DATABASE_DELIMINATOR = "@";
46-
private static final String OPTIONS_DELIMINATOR = "?";
47-
private static final String OPTION_VALUE_DELIMINATOR = "&";
44+
private static final String USERNAME_PASSWORD_DELIMITER = ":";
45+
private static final String DATABASE_DELIMITER = "@";
46+
private static final String OPTIONS_DELIMITER = "?";
47+
private static final String OPTION_VALUE_DELIMITER = "&";
4848

4949
/*
5050
* (non-Javadoc)
@@ -57,7 +57,7 @@ public void setAsText(String text) throws IllegalArgumentException {
5757
return;
5858
}
5959

60-
List<MongoCredential> credentials = new ArrayList<MongoCredential>();
60+
List<MongoCredential> credentials = new ArrayList<>();
6161

6262
for (String credentialString : extractCredentialsString(text)) {
6363

@@ -117,7 +117,7 @@ public void setAsText(String text) throws IllegalArgumentException {
117117
private List<String> extractCredentialsString(String source) {
118118

119119
Matcher matcher = GROUP_PATTERN.matcher(source);
120-
List<String> list = new ArrayList<String>();
120+
List<String> list = new ArrayList<>();
121121

122122
while (matcher.find()) {
123123

@@ -134,44 +134,44 @@ private List<String> extractCredentialsString(String source) {
134134

135135
private static String[] extractUserNameAndPassword(String text) {
136136

137-
int index = text.lastIndexOf(DATABASE_DELIMINATOR);
137+
int index = text.lastIndexOf(DATABASE_DELIMITER);
138138

139-
index = index != -1 ? index : text.lastIndexOf(OPTIONS_DELIMINATOR);
139+
index = index != -1 ? index : text.lastIndexOf(OPTIONS_DELIMITER);
140140

141141
if (index == -1) {
142142
return new String[] {};
143143
}
144144

145-
return Arrays.asList(text.substring(0, index).split(USERNAME_PASSWORD_DELIMINATOR)).stream()
145+
return Arrays.stream(text.substring(0, index).split(USERNAME_PASSWORD_DELIMITER))
146146
.map(MongoCredentialPropertyEditor::decodeParameter).toArray(String[]::new);
147147
}
148148

149149
private static String extractDB(String text) {
150150

151-
int dbSeperationIndex = text.lastIndexOf(DATABASE_DELIMINATOR);
151+
int dbSeparationIndex = text.lastIndexOf(DATABASE_DELIMITER);
152152

153-
if (dbSeperationIndex == -1) {
153+
if (dbSeparationIndex == -1) {
154154
return "";
155155
}
156156

157-
String tmp = text.substring(dbSeperationIndex + 1);
158-
int optionsSeperationIndex = tmp.lastIndexOf(OPTIONS_DELIMINATOR);
157+
String tmp = text.substring(dbSeparationIndex + 1);
158+
int optionsSeparationIndex = tmp.lastIndexOf(OPTIONS_DELIMITER);
159159

160-
return optionsSeperationIndex > -1 ? tmp.substring(0, optionsSeperationIndex) : tmp;
160+
return optionsSeparationIndex > -1 ? tmp.substring(0, optionsSeparationIndex) : tmp;
161161
}
162162

163163
private static Properties extractOptions(String text) {
164164

165-
int optionsSeperationIndex = text.lastIndexOf(OPTIONS_DELIMINATOR);
166-
int dbSeperationIndex = text.lastIndexOf(OPTIONS_DELIMINATOR);
165+
int optionsSeparationIndex = text.lastIndexOf(OPTIONS_DELIMITER);
166+
int dbSeparationIndex = text.lastIndexOf(OPTIONS_DELIMITER);
167167

168-
if (optionsSeperationIndex == -1 || dbSeperationIndex > optionsSeperationIndex) {
168+
if (optionsSeparationIndex == -1 || dbSeparationIndex > optionsSeparationIndex) {
169169
return new Properties();
170170
}
171171

172172
Properties properties = new Properties();
173173

174-
for (String option : text.substring(optionsSeperationIndex + 1).split(OPTION_VALUE_DELIMINATOR)) {
174+
for (String option : text.substring(optionsSeparationIndex + 1).split(OPTION_VALUE_DELIMITER)) {
175175
String[] optionArgs = option.split("=");
176176
properties.put(optionArgs[0], optionArgs[1]);
177177
}

src/main/asciidoc/reference/mongodb.adoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ public class ApplicationContextEventTestsAppConfig extends AbstractMongoConfigur
362362

363363
In order to use authentication with XML configuration use the `credentials` attribue on `<mongo-client>`.
364364

365-
NOTE: When using XML configuration along with username/password containing reserved characters `:`, `@`, `,` need to be URL encoded.
365+
NOTE: Username/password credentials used in XML configuration must be URL encoded when these contain reserved characters such as `:`, `%`, `@`, `,`.
366366
Example: `m0ng0@dmin:mo_res:bw6},Qsdxx@admin@database` -> `m0ng0%40dmin:mo_res%3Abw6%7D%2CQsdxx%40admin@database`
367+
See https://tools.ietf.org/html/rfc3986#section-2.2[section 2.2 of RFC 3986] for further details.
367368

368369

369370
[[mongo.mongo-db-factory-xml]]

0 commit comments

Comments
 (0)