Skip to content

Commit

Permalink
[#5987] improvement: Add more configurations for the config API (#5999)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Add more configurations for the config API

### Why are the changes needed?

Fix #5987 
Front end can use this config option to optimize the user experience.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?


![image](https://github.com/user-attachments/assets/a5f26c61-9e10-4dfa-bbcd-54cb887b1b71)
  • Loading branch information
jerqi authored Dec 26, 2024
1 parent 42ff30f commit ba8df39
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,20 @@ public class ConfigServlet extends HttpServlet {
ImmutableSet.of(OAuthConfig.DEFAULT_SERVER_URI, OAuthConfig.DEFAULT_TOKEN_PATH);

private static final ImmutableSet<ConfigEntry<?>> basicConfigEntries =
ImmutableSet.of(Configs.AUTHENTICATORS);
ImmutableSet.of(Configs.AUTHENTICATORS, Configs.ENABLE_AUTHORIZATION);

private final Map<String, String> configs = Maps.newHashMap();
private final Map<String, Object> configs = Maps.newHashMap();

public ConfigServlet(ServerConfig serverConfig) {
for (ConfigEntry<?> key : basicConfigEntries) {
String config = String.valueOf(serverConfig.get(key));
configs.put(key.getKey(), config);
configs.put(key.getKey(), serverConfig.get(key));
}

if (serverConfig
.get(Configs.AUTHENTICATORS)
.contains(AuthenticatorType.OAUTH.name().toLowerCase())) {
for (ConfigEntry<?> key : oauthConfigEntries) {
String config = String.valueOf(serverConfig.get(key));
configs.put(key.getKey(), config);
configs.put(key.getKey(), serverConfig.get(key));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.gravitino.server.web;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.apache.gravitino.server.ServerConfig;
import org.junit.jupiter.api.Test;

public class TestConfigServlet {

@Test
public void testConfigServlet() throws Exception {
ServerConfig serverConfig = new ServerConfig();
ConfigServlet configServlet = new ConfigServlet(serverConfig);
configServlet.init();
HttpServletResponse res = mock(HttpServletResponse.class);
PrintWriter writer = mock(PrintWriter.class);
when(res.getWriter()).thenReturn(writer);
configServlet.doGet(null, res);
verify(writer)
.write(
"{\"gravitino.authorization.enable\":false,\"gravitino.authenticators\":[\"simple\"]}");
configServlet.destroy();
}
}
2 changes: 1 addition & 1 deletion web/web/src/lib/store/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getAuthConfigs = createAsyncThunk('auth/getAuthConfigs', async () =
oauthUrl = `${res['gravitino.authenticator.oauth.serverUri']}${res['gravitino.authenticator.oauth.tokenPath']}`

// ** get the first authenticator from the response. response example: "[simple, oauth]"
authType = res['gravitino.authenticators'].slice(1, -1).split(',')[0].trim()
authType = res['gravitino.authenticators'][0].trim()

localStorage.setItem('oauthUrl', oauthUrl)

Expand Down

0 comments on commit ba8df39

Please sign in to comment.