Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credentials of URI in Hono-connection encoding added #1568

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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