Skip to content

Commit

Permalink
Introduce new API _plugins/_security/ssl/certs (opensearch-project#1841)
Browse files Browse the repository at this point in the history
Signed-off-by: cliu123 <lc12251109@gmail.com>
  • Loading branch information
cliu123 committed May 17, 2022
1 parent 9638ca3 commit dce5826
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import java.io.IOException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -44,16 +44,18 @@
import org.opensearch.security.user.User;
import org.opensearch.threadpool.ThreadPool;

import static org.opensearch.security.dlic.rest.support.Utils.addRoutesPrefix;


/**
* Rest API action to get SSL certificate information related to http and transport encryption.
* Only super admin users are allowed to access this API.
* Currently this action serves GET request for _opendistro/_security/api/ssl/certs endpoint
* Currently this action serves GET request for _plugins/_security/api/ssl/certs endpoint
*/
public class SecuritySSLCertsInfoAction extends BaseRestHandler {
private static final List<Route> routes = Collections.singletonList(
new Route(Method.GET, "/_opendistro/_security/api/ssl/certs")
);
private static final List<Route> routes = addRoutesPrefix(ImmutableList.of(
new Route(Method.GET, "/ssl/certs")
));

private final Logger log = LogManager.getLogger(this.getClass());
private Settings settings;
Expand Down Expand Up @@ -82,7 +84,7 @@ public List<Route> routes() {
* GET request to fetch transport certificate details
*
* Sample request:
* GET _opendistro/_security/api/ssl/certs
* GET _plugins/_security/api/ssl/certs
*
* Sample response:
* {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import net.minidev.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import org.opensearch.common.settings.Settings;
import org.opensearch.security.ssl.util.SSLConfigConstants;
Expand All @@ -31,9 +33,24 @@
import org.opensearch.security.test.helper.file.FileHelper;
import org.opensearch.security.test.helper.rest.RestHelper;

import static org.opensearch.security.OpenSearchSecurityPlugin.LEGACY_OPENDISTRO_PREFIX;
import static org.opensearch.security.OpenSearchSecurityPlugin.PLUGINS_PREFIX;

@RunWith(Parameterized.class)
public class SecuritySSLCertsInfoActionTests extends SingleClusterTest {
private final String ENDPOINT;

public SecuritySSLCertsInfoActionTests(String endpoint){
ENDPOINT = endpoint;
}

private final String ENDPOINT = "_opendistro/_security/api/ssl/certs";
@Parameterized.Parameters
public static Iterable<String> endpoints() {
return ImmutableList.of(
LEGACY_OPENDISTRO_PREFIX + "/api/ssl/certs",
PLUGINS_PREFIX + "/api/ssl/certs"
);
}

private final List<Map<String, String>> NODE_CERT_DETAILS = ImmutableList.of(
ImmutableMap.of(
Expand Down

0 comments on commit dce5826

Please sign in to comment.