Skip to content

Commit

Permalink
Merge pull request #1568 from bosch-io/bugfix/uri_ecnoding_of_hono_co…
Browse files Browse the repository at this point in the history
…nnection

Credentials of URI in Hono-connection encoding added
  • Loading branch information
thjaeckle authored Jan 24, 2023
2 parents fb742f8 + 948b85d commit f6adafe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -150,7 +152,8 @@ protected void preConversion(final Connection honoConnection) {

private String combineUriWithCredentials(final String uri, final UserPasswordCredentials credentials) {
return uri.replaceFirst("(\\S+://)(\\S+)",
"$1" + credentials.getUsername() + ":" + credentials.getPassword() + "@$2");
"$1" + URLEncoder.encode(credentials.getUsername(), StandardCharsets.UTF_8) + ":" +
URLEncoder.encode(credentials.getPassword(), StandardCharsets.UTF_8) + "@$2");
}

private Map<String, String> makeupSpecificConfig(final Connection connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -120,8 +122,8 @@ private Connection getExpectedHonoConnection(final Connection originalConnection
);
return ConnectivityModelFactory.newConnectionBuilder(originalConnection)
.uri(honoConfig.getBaseUri().toString().replaceFirst("(\\S+://)(\\S+)",
"$1" + honoConfig.getUserPasswordCredentials().getUsername()
+ ":" + honoConfig.getUserPasswordCredentials().getPassword()
"$1" + URLEncoder.encode(honoConfig.getUserPasswordCredentials().getUsername(), StandardCharsets.UTF_8)
+ ":" + URLEncoder.encode(honoConfig.getUserPasswordCredentials().getPassword(), StandardCharsets.UTF_8)
+ "@$2"))
.validateCertificate(honoConfig.isValidateCertificates())
.specificConfig(Map.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Things-Hono Test 1",
"connectionType": "hono",
"connectionStatus": "open",
"uri": "tcp://test_username:test_password@localhost:9922",
"uri": "tcp://test_username:test_password_w%2Fspecial_char@localhost:9922",
"sources": [
{
"addresses": [
Expand Down
2 changes: 1 addition & 1 deletion connectivity/service/src/test/resources/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ditto {
sasl-mechanism = PLAIN
bootstrap-servers = "tcp://server1:port1,tcp://server2:port2,tcp://server3:port3"
username = test_username
password = test_password
password = test_password_w/special_char
}

connection {
Expand Down

0 comments on commit f6adafe

Please sign in to comment.