Skip to content

Commit f206162

Browse files
authored
Merge pull request #3179 from ControlSystemStudio/native-http-client-fix
Need URL encoding in username/password when authenticating with native HttpClient
2 parents 28b52e0 + ee49ebd commit f206162

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/authentication/SaveAndRestoreAuthenticationProvider.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@
3434
public class SaveAndRestoreAuthenticationProvider implements ServiceAuthenticationProvider {
3535

3636
@Override
37-
public void authenticate(String username, String password){
37+
public void authenticate(String username, String password) {
3838
SaveAndRestoreService saveAndRestoreService = SaveAndRestoreService.getInstance();
3939
try {
4040
UserData userData = saveAndRestoreService.authenticate(username, password);
4141
Logger.getLogger(SaveAndRestoreAuthenticationProvider.class.getName())
4242
.log(Level.INFO, "User " + userData.getUserName() + " successfully signed in");
4343
} catch (Exception e) {
44+
// NOTE!!! Exception message and/or stack trace could contain request URL and consequently
45+
// user's password, so do not log or propagate it.
4446
Logger.getLogger(SaveAndRestoreAuthenticationProvider.class.getName())
45-
.log(Level.WARNING, "Failed to authenticate user " + username + " against save&restore service", e);
46-
throw new RuntimeException(e);
47+
.log(Level.WARNING, "Failed to authenticate user " + username + " with save&restore service");
48+
throw new RuntimeException("Failed to authenticate user " + username + " with save&restore service");
4749
}
4850
}
4951

@@ -53,7 +55,7 @@ public void logout(String token) {
5355
}
5456

5557
@Override
56-
public AuthenticationScope getAuthenticationScope(){
58+
public AuthenticationScope getAuthenticationScope() {
5759
return AuthenticationScope.SAVE_AND_RESTORE;
5860
}
5961

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
import java.net.CookieManager;
3535
import java.net.CookiePolicy;
3636
import java.net.URI;
37+
import java.net.URLEncoder;
3738
import java.net.http.HttpClient;
3839
import java.net.http.HttpRequest;
3940
import java.net.http.HttpResponse;
41+
import java.nio.charset.StandardCharsets;
4042
import java.time.Duration;
4143
import java.util.Base64;
4244
import java.util.List;
@@ -582,9 +584,9 @@ public List<Node> deleteTag(TagData tagData) {
582584
public UserData authenticate(String userName, String password) {
583585
String stringBuilder = Preferences.jmasarServiceUrl +
584586
"/login?username=" +
585-
userName +
587+
URLEncoder.encode(userName, StandardCharsets.UTF_8) +
586588
"&password=" +
587-
password;
589+
URLEncoder.encode(password, StandardCharsets.UTF_8);
588590
HttpRequest request = HttpRequest.newBuilder()
589591
.uri(URI.create(stringBuilder))
590592
.POST(HttpRequest.BodyPublishers.noBody())

0 commit comments

Comments
 (0)