Skip to content

Commit efdd957

Browse files
committed
added support for encoded header names and basic auth passwords. fixes apache#5067
1 parent 08ed425 commit efdd957

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import lombok.Getter;
2929
import lombok.Setter;
3030
import org.apache.commons.lang.StringUtils;
31+
import org.apache.hop.core.encryption.Encr;
3132
import org.apache.hop.core.exception.HopException;
3233
import org.apache.hop.core.util.HttpClientManager;
3334
import org.apache.hop.core.util.Utils;
@@ -76,7 +77,7 @@ public class RestConnection extends HopMetadataBase implements IHopMetadata {
7677
@HopMetadataProperty(key = "username")
7778
private String username;
7879

79-
@HopMetadataProperty(key = "username", password = true)
80+
@HopMetadataProperty(key = "password", password = true)
8081
private String password;
8182

8283
// Bearer auth
@@ -90,7 +91,7 @@ public class RestConnection extends HopMetadataBase implements IHopMetadata {
9091
@HopMetadataProperty(key = "auth_header_prefix")
9192
private String authorizationPrefix;
9293

93-
@HopMetadataProperty(key = "auth_header_value")
94+
@HopMetadataProperty(key = "auth_header_value", password = true)
9495
private String authorizationHeaderValue;
9596

9697
public RestConnection(IVariables variables) {
@@ -129,7 +130,11 @@ public Invocation.Builder getInvocationBuilder(String url) throws HopException {
129130
}
130131
if (authType.equals("Basic")) {
131132
if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
132-
client.register(HttpAuthenticationFeature.basic(username, password));
133+
134+
client.register(
135+
HttpAuthenticationFeature.basic(
136+
variables.resolve(username),
137+
Encr.decryptPasswordOptionallyEncrypted(variables.resolve(password))));
133138
target = client.target(url);
134139
invocationBuilder = target.request();
135140
}
@@ -139,11 +144,12 @@ public Invocation.Builder getInvocationBuilder(String url) throws HopException {
139144
variables.resolve(authorizationHeaderName),
140145
variables.resolve(authorizationPrefix)
141146
+ " "
142-
+ variables.resolve(authorizationHeaderValue));
147+
+ Encr.decryptPasswordOptionallyEncrypted(
148+
variables.resolve(authorizationHeaderValue)));
143149
} else {
144150
invocationBuilder.header(
145151
variables.resolve(authorizationHeaderName),
146-
variables.resolve(authorizationHeaderValue));
152+
Encr.decryptPasswordOptionallyEncrypted(variables.resolve(authorizationHeaderValue)));
147153
}
148154
} else if (authType.equals("Bearer")) {
149155
if (!StringUtils.isEmpty(bearerToken)) {

0 commit comments

Comments
 (0)