Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit ac698fa

Browse files
committed
#335 Certificate authority extensions are now configurable
And the command checks for a lot more of them by default
1 parent 5aa8478 commit ac698fa

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

src/main/java/com/marklogic/appdeployer/command/security/DeployCertificateAuthoritiesCommand.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,33 @@
33
import com.marklogic.appdeployer.ConfigDir;
44
import com.marklogic.appdeployer.command.AbstractCommand;
55
import com.marklogic.appdeployer.command.CommandContext;
6+
import com.marklogic.appdeployer.command.ResourceFilenameFilter;
67
import com.marklogic.appdeployer.command.SortOrderConstants;
78
import com.marklogic.mgmt.resource.security.CertificateAuthorityManager;
89
import org.springframework.http.ResponseEntity;
910

1011
import java.io.File;
12+
import java.util.HashSet;
13+
import java.util.Set;
1114

1215
public class DeployCertificateAuthoritiesCommand extends AbstractCommand {
1316

1417
public DeployCertificateAuthoritiesCommand() {
1518
setExecuteSortOrder(SortOrderConstants.DEPLOY_CERTIFICATE_AUTHORITIES);
19+
20+
ResourceFilenameFilter filter = new ResourceFilenameFilter();
21+
Set<String> extensions = new HashSet<>();
22+
extensions.add(".cer");
23+
extensions.add(".crt");
24+
extensions.add(".der");
25+
extensions.add(".p12");
26+
extensions.add(".p7b");
27+
extensions.add(".p7r");
28+
extensions.add(".pem");
29+
extensions.add(".pfx");
30+
extensions.add(".spc");
31+
filter.setSupportedFilenameExtensions(extensions);
32+
setResourceFilenameFilter(filter);
1633
}
1734

1835
@Override
@@ -21,16 +38,14 @@ public void execute(CommandContext context) {
2138
File dir = configDir.getCertificateAuthoritiesDir();
2239
if (dir.exists()) {
2340
CertificateAuthorityManager mgr = new CertificateAuthorityManager(context.getManageClient());
24-
for (File f : dir.listFiles()) {
25-
if (f.getName().endsWith("crt")) {
26-
if (logger.isInfoEnabled()) {
27-
logger.info("Creating certificate authority from file: " + f.getAbsolutePath());
28-
}
29-
String payload = copyFileToString(f, context);
30-
ResponseEntity<String> response = mgr.create(payload);
31-
if (logger.isInfoEnabled()) {
32-
logger.info("Created certificate authority, location: " + response.getHeaders().getLocation());
33-
}
41+
for (File f : listFilesInDirectory(dir)) {
42+
if (logger.isInfoEnabled()) {
43+
logger.info("Creating certificate authority from file: " + f.getAbsolutePath());
44+
}
45+
String payload = copyFileToString(f, context);
46+
ResponseEntity<String> response = mgr.create(payload);
47+
if (logger.isInfoEnabled()) {
48+
logger.info("Created certificate authority, location: " + response.getHeaders().getLocation());
3449
}
3550
}
3651
} else {
Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.marklogic.appdeployer.command.security;
22

3-
import org.junit.Test;
4-
53
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.appdeployer.command.ResourceFilenameFilter;
65
import com.marklogic.mgmt.resource.security.CertificateAuthorityManager;
76
import com.marklogic.rest.util.ResourcesFragment;
7+
import org.junit.Test;
8+
9+
import java.util.Set;
810

911
/**
1012
* All we can reliably do from a file-driven approach is create a certificate authority. The Management REST API in
@@ -14,24 +16,35 @@
1416
*/
1517
public class ManageCertificateAuthoritiesTest extends AbstractAppDeployerTest {
1618

17-
@Test
18-
public void test() {
19-
// Run the command to create a certificate authority
20-
initializeAppDeployer(new DeployCertificateAuthoritiesCommand());
21-
appDeployer.deploy(appConfig);
22-
23-
// Get the ID of the created certificate authority
24-
CertificateAuthorityManager mgr = new CertificateAuthorityManager(manageClient);
25-
ResourcesFragment resources = mgr.getAsXml();
26-
String id = resources.getListItemValue("MarkLogic TX Engineering", "idref");
27-
assertNotNull("The certificate authority should have been created", id);
28-
29-
// Delete the certificate authority
30-
mgr.delete(id);
31-
32-
// And then verify that it's gone
33-
resources = mgr.getAsXml();
34-
id = resources.getListItemValue("MarkLogic TX Engineering", "idref");
35-
assertNull("The certificate authority should no longer exist", id);
36-
}
19+
@Test
20+
public void test() {
21+
// Run the command to create a certificate authority
22+
initializeAppDeployer(new DeployCertificateAuthoritiesCommand());
23+
appDeployer.deploy(appConfig);
24+
25+
// Get the ID of the created certificate authority
26+
CertificateAuthorityManager mgr = new CertificateAuthorityManager(manageClient);
27+
ResourcesFragment resources = mgr.getAsXml();
28+
String id = resources.getListItemValue("MarkLogic TX Engineering", "idref");
29+
assertNotNull("The certificate authority should have been created", id);
30+
31+
// Delete the certificate authority
32+
mgr.delete(id);
33+
34+
// And then verify that it's gone
35+
resources = mgr.getAsXml();
36+
id = resources.getListItemValue("MarkLogic TX Engineering", "idref");
37+
assertNull("The certificate authority should no longer exist", id);
38+
}
39+
40+
@Test
41+
public void verifyFileExtensions() {
42+
DeployCertificateAuthoritiesCommand command = new DeployCertificateAuthoritiesCommand();
43+
ResourceFilenameFilter filter = (ResourceFilenameFilter) command.getResourceFilenameFilter();
44+
Set<String> extensions = filter.getSupportedFilenameExtensions();
45+
46+
for (String extension : new String[]{".cer", ".crt", ".der", ".p12", ".p7b", ".p7r", ".pem", ".pfx", ".spc"}) {
47+
assertTrue(extensions.contains(extension));
48+
}
49+
}
3750
}

0 commit comments

Comments
 (0)