|
18 | 18 | package org.openqa.selenium.remote.http.jdk;
|
19 | 19 |
|
20 | 20 | import com.google.auto.service.AutoService;
|
| 21 | + |
21 | 22 | import org.openqa.selenium.Credentials;
|
22 | 23 | import org.openqa.selenium.TimeoutException;
|
23 | 24 | import org.openqa.selenium.UsernameAndPassword;
|
@@ -78,9 +79,23 @@ public class JdkHttpClient implements HttpClient {
|
78 | 79 | .followRedirects(ALWAYS);
|
79 | 80 |
|
80 | 81 | Credentials credentials = config.credentials();
|
81 |
| - if (credentials != null) { |
| 82 | + String info = config.baseUri().getUserInfo(); |
| 83 | + if (info != null && !info.trim().isEmpty()) { |
| 84 | + String[] parts = info.split(":", 2); |
| 85 | + String username = parts[0]; |
| 86 | + String password = parts.length > 1 ? parts[1] : null; |
| 87 | + |
| 88 | + Authenticator authenticator = new Authenticator() { |
| 89 | + @Override |
| 90 | + protected PasswordAuthentication getPasswordAuthentication() { |
| 91 | + return new PasswordAuthentication(username, password.toCharArray()); |
| 92 | + } |
| 93 | + }; |
| 94 | + builder = builder.authenticator(authenticator); |
| 95 | + } else if (credentials != null) { |
82 | 96 | if (!(credentials instanceof UsernameAndPassword)) {
|
83 |
| - throw new IllegalArgumentException("Credentials must be a user name and password: " + credentials); |
| 97 | + throw new IllegalArgumentException( |
| 98 | + "Credentials must be a user name and password: " + credentials); |
84 | 99 | }
|
85 | 100 | UsernameAndPassword uap = (UsernameAndPassword) credentials;
|
86 | 101 | Authenticator authenticator = new Authenticator() {
|
|
0 commit comments