Skip to content

Commit d428670

Browse files
committed
Revert change that made core webdriver API depend on httpclient.
This reintroduces our own Credentials API, with a single subclass. Since there's now a working implementation, I've kept the protocol as it was, but really Credentials could be something like a finger print, so just "username" and "password" is not always going to be a workable solution. This reverts commit 16842a8.
1 parent a80727b commit d428670

File tree

11 files changed

+109
-14
lines changed

11 files changed

+109
-14
lines changed

java/client/src/org/openqa/selenium/Alert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.openqa.selenium;
1919

20-
import org.apache.http.auth.Credentials;
20+
import org.openqa.selenium.security.Credentials;
2121

2222
public interface Alert {
2323
void dismiss();

java/client/src/org/openqa/selenium/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ java_library(name = 'webdriver-api',
88
'//java/client/src/org/openqa/selenium/interactions:interactions',
99
'//java/client/src/org/openqa/selenium/interactions:exceptions',
1010
'//java/client/src/org/openqa/selenium/logging:api',
11+
'//java/client/src/org/openqa/selenium/security:security',
1112
],
1213
visibility = ['PUBLIC'],
1314
)

java/client/src/org/openqa/selenium/build.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ java_library(name = "webdriver-api",
8484
":codecs",
8585
"//java/client/src/org/openqa/selenium/interactions:api",
8686
"//java/client/src/org/openqa/selenium/logging:api",
87-
"//third_party/java/httpcomponents:httpclient",
87+
"//java/client/src/org/openqa/selenium/security",
8888
])
8989

9090
java_library(name = "client-combined",

java/client/src/org/openqa/selenium/htmlunit/HtmlUnitAlert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import java.util.Map;
2323
import java.util.Queue;
2424

25-
import org.apache.http.auth.Credentials;
2625
import org.openqa.selenium.Alert;
2726
import org.openqa.selenium.ElementNotVisibleException;
2827
import org.openqa.selenium.NoAlertPresentException;
28+
import org.openqa.selenium.security.Credentials;
2929

3030
import com.gargoylesoftware.htmlunit.AlertHandler;
3131
import com.gargoylesoftware.htmlunit.Page;

java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.google.common.collect.Lists;
2525
import com.google.common.collect.Maps;
2626

27-
import org.apache.http.auth.Credentials;
2827
import org.openqa.selenium.Alert;
2928
import org.openqa.selenium.Beta;
3029
import org.openqa.selenium.By;
@@ -60,6 +59,8 @@
6059
import org.openqa.selenium.logging.NeedsLocalLogs;
6160
import org.openqa.selenium.remote.internal.JsonToWebElementConverter;
6261
import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
62+
import org.openqa.selenium.security.Credentials;
63+
import org.openqa.selenium.security.UserAndPassword;
6364

6465
import java.net.URL;
6566
import java.util.Date;
@@ -936,9 +937,16 @@ public void sendKeys(String keysToSend) {
936937

937938
@Beta
938939
public void setCredentials(Credentials credentials) {
939-
execute(DriverCommand.SET_ALERT_CREDENTIALS, ImmutableMap
940-
.of("username", credentials.getUserPrincipal().getName(), "password",
941-
credentials.getPassword()));
940+
if (!(credentials instanceof UserAndPassword)) {
941+
throw new RuntimeException("Unsupported credentials: " + credentials);
942+
}
943+
944+
UserAndPassword userAndPassword = (UserAndPassword) credentials;
945+
execute(
946+
DriverCommand.SET_ALERT_CREDENTIALS,
947+
ImmutableMap.of(
948+
"username", userAndPassword.getUsername(),
949+
"password", userAndPassword.getPassword()));
942950
}
943951

944952
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
java_library(name = 'security',
2+
srcs = glob(['*.java']),
3+
deps = [
4+
'//java/client/src/org/openqa/selenium:beta',
5+
],
6+
visibility = [
7+
'//java/client/src/org/openqa/selenium:core',
8+
'//java/client/src/org/openqa/selenium:webdriver-api',
9+
],
10+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.security;
19+
20+
import org.openqa.selenium.Beta;
21+
22+
/**
23+
* Marker interface used to indicate that this object can be used for
24+
* authentication.
25+
*/
26+
@Beta
27+
public interface Credentials {
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.security;
19+
20+
import org.openqa.selenium.Beta;
21+
22+
/**
23+
* Represents the authentication credentials for a user with username and password
24+
*/
25+
@Beta
26+
public class UserAndPassword implements Credentials {
27+
28+
private final String username;
29+
private final String password;
30+
31+
public UserAndPassword(String username, String password) {
32+
this.username = username;
33+
this.password = password;
34+
}
35+
36+
public String getUsername() {
37+
return username;
38+
}
39+
40+
public String getPassword() {
41+
return password;
42+
}
43+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
java_library(name = "security",
3+
srcs = [ "*.java" ],
4+
deps = [
5+
"//java/client/src/org/openqa/selenium:beta",
6+
])

java/client/test/org/openqa/selenium/AuthenticatedPageLoadingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
2323
import static org.openqa.selenium.testing.Ignore.Driver.FIREFOX;
2424
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
25-
import static org.openqa.selenium.testing.Ignore.Driver.IE;
2625
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
2726
import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS;
2827
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;
2928

30-
import org.apache.http.auth.UsernamePasswordCredentials;
3129
import org.junit.Test;
30+
import org.openqa.selenium.security.Credentials;
31+
import org.openqa.selenium.security.UserAndPassword;
3232
import org.openqa.selenium.testing.Ignore;
3333
import org.openqa.selenium.testing.JUnit4TestBase;
3434

@@ -42,7 +42,7 @@ public void canAuthenticateUsingBasicAuthentication() {
4242

4343
Alert alert = wait.until(alertIsPresent());
4444

45-
UsernamePasswordCredentials user = new UsernamePasswordCredentials("test", "test");
45+
Credentials user = new UserAndPassword("test", "test");
4646

4747
alert.authenticateUsing(user);
4848

0 commit comments

Comments
 (0)