Skip to content

Commit 7b68202

Browse files
authored
chore(test): Restore PolarisAccessManager (#2413)
Restore `PolarisAccessManager` (with default implementation of `IcebergTokenAccessManager`) which was added as an extension point for running Polaris tests in downstream build environments under #789, but was mistakenly removed in #2343
1 parent d30232e commit 7b68202

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.service.it.env;
20+
21+
import jakarta.ws.rs.client.Client;
22+
import org.apache.polaris.service.it.ext.PolarisAccessManager;
23+
24+
/**
25+
* This class obtains access tokens from the {@code v1/oauth/tokens} endpoint defined by the Iceberg
26+
* REST Catalog spec.
27+
*
28+
* <p>Note: even though this endpoint is still part of the Iceberg REST Catalog spec it has been
29+
* deprecated per <a href="https://github.com/apache/iceberg/pull/10603">Iceberg PR#10603</a>.
30+
*/
31+
public class IcebergTokenAccessManager implements PolarisAccessManager {
32+
private final Client client;
33+
34+
public IcebergTokenAccessManager(Client client) {
35+
this.client = client;
36+
}
37+
38+
@Override
39+
public String obtainAccessToken(PolarisApiEndpoints endpoints, ClientCredentials credentials) {
40+
OAuth2Api api = new OAuth2Api(client, endpoints.catalogApiEndpoint(), "v1/oauth/tokens");
41+
return api.obtainAccessToken(credentials, "PRINCIPAL_ROLE:ALL");
42+
}
43+
}

integration-tests/src/main/java/org/apache/polaris/service/it/env/PolarisClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ public String obtainToken(ClientPrincipal principal) {
114114

115115
/** Requests an access token from the Polaris server for the given credentials. */
116116
public String obtainToken(ClientCredentials credentials) {
117-
OAuth2Api api = new OAuth2Api(client, endpoints.catalogApiEndpoint(), "v1/oauth/tokens");
118-
return api.obtainAccessToken(credentials, "PRINCIPAL_ROLE:ALL");
117+
return polarisServerManager().accessManager(client).obtainAccessToken(endpoints, credentials);
119118
}
120119

121120
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.service.it.ext;
20+
21+
import org.apache.polaris.service.it.env.ClientCredentials;
22+
import org.apache.polaris.service.it.env.PolarisApiEndpoints;
23+
24+
public interface PolarisAccessManager {
25+
26+
String obtainAccessToken(PolarisApiEndpoints endpoints, ClientCredentials credentials);
27+
}

integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisServerManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import jakarta.ws.rs.client.Client;
2626
import jakarta.ws.rs.client.ClientBuilder;
2727
import java.util.ServiceLoader;
28+
import org.apache.polaris.service.it.env.IcebergTokenAccessManager;
2829
import org.apache.polaris.service.it.env.Server;
2930
import org.junit.jupiter.api.extension.ExtensionContext;
3031

@@ -50,6 +51,10 @@ public interface PolarisServerManager {
5051
*/
5152
Server serverForContext(ExtensionContext context);
5253

54+
default PolarisAccessManager accessManager(Client client) {
55+
return new IcebergTokenAccessManager(client);
56+
}
57+
5358
/** Create a new HTTP client for accessing the server targeted by tests. */
5459
default Client createClient() {
5560
return ClientBuilder.newBuilder()

0 commit comments

Comments
 (0)