|
30 | 30 | import java.nio.file.Files; |
31 | 31 | import java.nio.file.Path; |
32 | 32 | import java.nio.file.Paths; |
| 33 | +import java.security.KeyPairGenerator; |
33 | 34 | import java.util.Base64; |
34 | 35 | import java.util.List; |
35 | 36 | import java.util.Map; |
36 | 37 | import java.util.Set; |
37 | 38 | import org.apache.commons.lang3.StringUtils; |
38 | 39 | import org.apache.gravitino.Configs; |
39 | 40 | import org.apache.gravitino.auth.AuthConstants; |
| 41 | +import org.apache.gravitino.auth.AuthenticatorType; |
40 | 42 | import org.apache.gravitino.dto.responses.ErrorConstants; |
41 | 43 | import org.apache.gravitino.idp.dto.requests.AddGroupRequest; |
42 | 44 | import org.apache.gravitino.idp.dto.requests.AddUserRequest; |
|
48 | 50 | import org.apache.gravitino.integration.test.util.BaseIT; |
49 | 51 | import org.apache.gravitino.integration.test.util.ITUtils; |
50 | 52 | import org.apache.gravitino.json.JsonUtils; |
| 53 | +import org.apache.gravitino.server.authentication.OAuthConfig; |
51 | 54 | import org.junit.jupiter.api.Assertions; |
52 | 55 | import org.junit.jupiter.api.BeforeAll; |
53 | 56 | import org.junit.jupiter.api.Test; |
@@ -84,6 +87,11 @@ public void startIntegrationTest() throws Exception { |
84 | 87 | configs.put(Configs.CACHE_ENABLED.getKey(), String.valueOf(false)); |
85 | 88 | configs.put(Configs.STORE_DELETE_AFTER_TIME.getKey(), String.valueOf(20 * 60 * 1000L)); |
86 | 89 | configs.put(Configs.SERVICE_ADMINS.getKey(), ADMIN); |
| 90 | + configs.put(Configs.AUTHENTICATORS.getKey(), AuthenticatorType.OAUTH.name().toLowerCase()); |
| 91 | + configs.put(OAuthConfig.SERVICE_AUDIENCE.getKey(), "service1"); |
| 92 | + configs.put(OAuthConfig.DEFAULT_SIGN_KEY.getKey(), oauthPublicSignKey()); |
| 93 | + configs.put(OAuthConfig.DEFAULT_SERVER_URI.getKey(), "test"); |
| 94 | + configs.put(OAuthConfig.DEFAULT_TOKEN_PATH.getKey(), "test"); |
87 | 95 | configs.put( |
88 | 96 | Configs.REST_API_EXTENSION_PACKAGES.getKey(), IdpRESTFeature.IDP_REST_EXTENSION_PACKAGE); |
89 | 97 | registerCustomConfigs(configs); |
@@ -117,8 +125,8 @@ private static void ensureDeployInitialAdminPasswordInDistributionEnv() throws I |
117 | 125 | @Test |
118 | 126 | void testIdpAuthorization() throws Exception { |
119 | 127 | Assertions.assertEquals(200, get("/version", ADMIN, ADMIN_PASSWORD).statusCode()); |
120 | | - // No Authorization: simple authenticator allows anonymous access; IdP filter rejects. |
121 | | - assertError(403, get("/idp/users/" + USER1, null, null), ErrorConstants.FORBIDDEN_CODE); |
| 128 | + // No Authorization: OAuth rejects the request before the IdP filter runs. |
| 129 | + Assertions.assertEquals(401, get("/idp/users/" + USER1, null, null).statusCode()); |
122 | 130 |
|
123 | 131 | postUser(USER2, USER_PASSWORD); |
124 | 132 | assertError( |
@@ -371,4 +379,10 @@ private static void assertError(int expectedStatus, HttpResponse<String> respons |
371 | 379 | private static int errorCode(HttpResponse<String> response) throws Exception { |
372 | 380 | return JsonUtils.objectMapper().readTree(response.body()).get("code").asInt(); |
373 | 381 | } |
| 382 | + |
| 383 | + private static String oauthPublicSignKey() throws Exception { |
| 384 | + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); |
| 385 | + generator.initialize(2048); |
| 386 | + return Base64.getEncoder().encodeToString(generator.generateKeyPair().getPublic().getEncoded()); |
| 387 | + } |
374 | 388 | } |
0 commit comments