Skip to content

Commit

Permalink
Introduce new API _plugins/_security/ssl/certs (#1841) (#1846)
Browse files Browse the repository at this point in the history
Signed-off-by: cliu123 <[email protected]>
(cherry picked from commit dce5826)
  • Loading branch information
cliu123 authored May 17, 2022
1 parent ac19824 commit 76092ff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
import org.opensearch.security.ssl.SecurityKeyStore;
import org.opensearch.security.support.ConfigConstants;
import org.opensearch.security.user.User;
import java.io.IOException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
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.Logger;
import org.apache.logging.log4j.LogManager;
Expand All @@ -35,25 +43,18 @@
import org.opensearch.rest.RestStatus;
import org.opensearch.threadpool.ThreadPool;

import java.io.IOException;
import java.security.cert.CertificateParsingException;
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 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 +83,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 @@ -26,13 +26,30 @@
import org.opensearch.common.settings.Settings;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.List;
import java.util.Map;

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 76092ff

Please sign in to comment.