|
30 | 30 | import jakarta.inject.Inject; |
31 | 31 | import jakarta.ws.rs.client.Client; |
32 | 32 | import jakarta.ws.rs.client.ClientBuilder; |
33 | | -import jakarta.ws.rs.client.Entity; |
34 | 33 | import jakarta.ws.rs.core.MediaType; |
35 | | -import jakarta.ws.rs.core.MultivaluedHashMap; |
36 | 34 | import jakarta.ws.rs.core.Response; |
37 | 35 | import jakarta.ws.rs.core.Response.Status; |
38 | 36 | import java.util.Map; |
39 | 37 | import java.util.Set; |
40 | 38 | import java.util.function.Consumer; |
41 | 39 | import org.apache.iceberg.rest.responses.ErrorResponse; |
42 | 40 | import org.apache.iceberg.rest.responses.ErrorResponseParser; |
43 | | -import org.apache.iceberg.rest.responses.OAuthTokenResponse; |
44 | 41 | import org.apache.polaris.service.events.EventAttributes; |
45 | 42 | import org.apache.polaris.service.events.PolarisEvent; |
46 | 43 | import org.apache.polaris.service.events.PolarisEventType; |
@@ -83,11 +80,6 @@ public Map<String, String> getConfigOverrides() { |
83 | 80 | .put("polaris.rate-limiter.token-bucket.type", "default") |
84 | 81 | .put("polaris.metrics.tags.environment", "prod") |
85 | 82 | .put("polaris.realm-context.realms", "POLARIS,POLARIS2") |
86 | | - // Bootstrapping both realms with known credentials so each realm can mint its own |
87 | | - // access token. Tokens are bound to per-realm secret hashes and cannot be shared. |
88 | | - .put( |
89 | | - "polaris.bootstrap.credentials", |
90 | | - "POLARIS,test-admin,test-secret;POLARIS2,test-admin2,test-secret2") |
91 | 83 | .put("polaris.metrics.realm-id-tag.enable-in-api-metrics", "true") |
92 | 84 | .put("polaris.metrics.realm-id-tag.enable-in-http-metrics", "true") |
93 | 85 | .put("polaris.authentication.token-broker.type", "symmetric-key") |
@@ -146,14 +138,10 @@ public void testRateLimiter() { |
146 | 138 | requestAsserter.accept(Status.TOO_MANY_REQUESTS); |
147 | 139 | } |
148 | 140 |
|
149 | | - // Ensure that a different realm identifier gets a separate limit. Access tokens are |
150 | | - // bound to per-realm principal secrets, so mint a token for POLARIS2 rather than reusing |
151 | | - // the POLARIS admin token (which would correctly return 401 after credentials binding). |
| 141 | + // Ensure that a different realm identifier gets a separate limit |
152 | 142 | MockRateLimiter.allowProceed = true; |
153 | | - String polaris2Token = |
154 | | - obtainAccessTokenForRealm(polarisEndpoints, "POLARIS2", "test-admin2", "test-secret2"); |
155 | 143 | Consumer<Status> requestAsserter2 = |
156 | | - constructRequestAsserter(polarisEndpoints, polaris2Token, "POLARIS2"); |
| 144 | + constructRequestAsserter(polarisEndpoints, adminToken, "POLARIS2"); |
157 | 145 | requestAsserter2.accept(Status.OK); |
158 | 146 | } |
159 | 147 |
|
@@ -255,27 +243,4 @@ private static Consumer<Status> constructRequestAsserter( |
255 | 243 | } |
256 | 244 | }; |
257 | 245 | } |
258 | | - |
259 | | - /** |
260 | | - * Mints an access token in the given realm using client credentials. Realm must be bootstrapped |
261 | | - * with those credentials (see {@link Profile}). |
262 | | - */ |
263 | | - private static String obtainAccessTokenForRealm( |
264 | | - PolarisApiEndpoints endpoints, String realm, String clientId, String clientSecret) { |
265 | | - MultivaluedHashMap<String, String> form = new MultivaluedHashMap<>(); |
266 | | - form.add("grant_type", "client_credentials"); |
267 | | - form.add("client_id", clientId); |
268 | | - form.add("client_secret", clientSecret); |
269 | | - form.add("scope", "PRINCIPAL_ROLE:ALL"); |
270 | | - try (Client httpClient = ClientBuilder.newBuilder().build(); |
271 | | - Response response = |
272 | | - httpClient |
273 | | - .target(String.format("%s/v1/oauth/tokens", endpoints.catalogApiEndpoint())) |
274 | | - .request(MediaType.APPLICATION_JSON_TYPE) |
275 | | - .header("Polaris-Realm", realm) |
276 | | - .post(Entity.form(form))) { |
277 | | - assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode()); |
278 | | - return response.readEntity(OAuthTokenResponse.class).token(); |
279 | | - } |
280 | | - } |
281 | 246 | } |
0 commit comments