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

Commit edb9b11

Browse files
committed
#353 Deploying protected paths and query rolesets via CMA
1 parent b4fc24a commit edb9b11

30 files changed

+667
-135
lines changed

src/main/java/com/marklogic/appdeployer/CmaConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class CmaConfig {
77
private boolean deployDatabases;
88
private boolean deployForests;
99
private boolean deployPrivileges;
10+
private boolean deployProtectedPaths;
11+
private boolean deployQueryRolesets;
1012
private boolean deployRoles;
1113
private boolean deployServers;
1214
private boolean deployUsers;
@@ -17,6 +19,8 @@ public void enableAll() {
1719
setDeployDatabases(true);
1820
setDeployForests(true);
1921
setDeployPrivileges(true);
22+
setDeployProtectedPaths(true);
23+
setDeployQueryRolesets(true);
2024
setDeployRoles(true);
2125
setDeployServers(true);
2226
setDeployUsers(true);
@@ -85,4 +89,20 @@ public boolean isCombineRequests() {
8589
public void setCombineRequests(boolean combineRequests) {
8690
this.combineRequests = combineRequests;
8791
}
92+
93+
public boolean isDeployProtectedPaths() {
94+
return deployProtectedPaths;
95+
}
96+
97+
public void setDeployProtectedPaths(boolean deployProtectedPaths) {
98+
this.deployProtectedPaths = deployProtectedPaths;
99+
}
100+
101+
public boolean isDeployQueryRolesets() {
102+
return deployQueryRolesets;
103+
}
104+
105+
public void setDeployQueryRolesets(boolean deployQueryRolesets) {
106+
this.deployQueryRolesets = deployQueryRolesets;
107+
}
88108
}

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ public void initialize() {
104104
config.getCmaConfig().setDeployPrivileges(Boolean.parseBoolean(prop));
105105
});
106106

107+
propertyConsumerMap.put("mlDeployProtectedPathsWithCma", (config, prop) -> {
108+
logger.info("Deploy protected paths" + cmaMessage + prop);
109+
config.getCmaConfig().setDeployProtectedPaths(Boolean.parseBoolean(prop));
110+
});
111+
112+
propertyConsumerMap.put("mlDeployQueryRolesetsWithCma", (config, prop) -> {
113+
logger.info("Deploy query rolesets" + cmaMessage + prop);
114+
config.getCmaConfig().setDeployQueryRolesets(Boolean.parseBoolean(prop));
115+
});
116+
107117
propertyConsumerMap.put("mlDeployRolesWithCma", (config, prop) -> {
108118
logger.info("Deploy servers" + cmaMessage + prop);
109119
config.getCmaConfig().setDeployRoles(Boolean.parseBoolean(prop));
@@ -730,7 +740,7 @@ public void initialize() {
730740
logger.info("Supported resources will only be deployed if their resource files are new or have been modified since the last deployment: " + prop);
731741
config.setIncrementalDeploy(Boolean.parseBoolean(prop));
732742
});
733-
743+
734744
propertyConsumerMap.put("mlUpdateMimetypeWhenPropertiesAreEqual", (config, prop) -> {
735745
logger.info("Update mimetype when properties are equal (defaults to false to avoid unnecessary ML restarts): " + prop);
736746
config.setUpdateMimetypeWhenPropertiesAreEqual(Boolean.parseBoolean(prop));

src/main/java/com/marklogic/appdeployer/command/SortOrderConstants.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ public abstract class SortOrderConstants {
44

55
public static Integer DEPLOY_PRIVILEGES = 5;
66
public static Integer DEPLOY_ROLES = 10;
7-
public static Integer DEPLOY_USERS = 15;
7+
public static Integer DEPLOY_PROTECTED_PATHS = 12; // depends on roles
8+
public static Integer DEPLOY_QUERY_ROLESETS = 13; // depends on roles
9+
public static Integer DEPLOY_USERS = 15; // depends on roles
10+
811
public static Integer DEPLOY_CERTIFICATE_AUTHORITIES = 20;
912
public static Integer DEPLOY_CERTIFICATE_TEMPLATES = 24;
1013
public static Integer GENERATE_TEMPORARY_CERTIFICATE = 25;
@@ -13,8 +16,6 @@ public abstract class SortOrderConstants {
1316
public static Integer DEPLOY_EXTERNAL_SECURITY = 35;
1417
public static Integer DEPLOY_PROTECTED_COLLECTIONS = 40;
1518
public static Integer DEPLOY_MIMETYPES = 45;
16-
public static Integer DEPLOY_PROTECTED_PATHS = 50;
17-
public static Integer DEPLOY_QUERY_ROLESETS = 55;
1819

1920
public static Integer DEPLOY_GROUPS = 90;
2021

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11
package com.marklogic.appdeployer.command.security;
22

3+
import com.fasterxml.jackson.databind.node.ObjectNode;
34
import com.marklogic.appdeployer.command.AbstractResourceCommand;
45
import com.marklogic.appdeployer.command.CommandContext;
56
import com.marklogic.appdeployer.command.SortOrderConstants;
7+
import com.marklogic.appdeployer.command.SupportsCmaCommand;
8+
import com.marklogic.mgmt.api.configuration.Configuration;
9+
import com.marklogic.mgmt.api.security.protectedpath.ProtectedPath;
610
import com.marklogic.mgmt.resource.ResourceManager;
711
import com.marklogic.mgmt.resource.security.ProtectedPathManager;
8-
import com.marklogic.mgmt.resource.security.UserManager;
912

1013
import java.io.File;
1114

12-
public class DeployProtectedPathsCommand extends AbstractResourceCommand {
15+
public class DeployProtectedPathsCommand extends AbstractResourceCommand implements SupportsCmaCommand {
1316

1417
public DeployProtectedPathsCommand() {
1518
setExecuteSortOrder(SortOrderConstants.DEPLOY_PROTECTED_PATHS);
1619
setUndoSortOrder(SortOrderConstants.DELETE_PROTECTED_PATHS);
20+
21+
setResourceClassType(ProtectedPath.class);
22+
}
23+
24+
@Override
25+
public boolean cmaShouldBeUsed(CommandContext context) {
26+
return context.getAppConfig().getCmaConfig().isDeployProtectedPaths();
27+
}
28+
29+
@Override
30+
public void addResourceToConfiguration(ObjectNode resource, Configuration configuration) {
31+
configuration.addProtectedPath(resource);
32+
}
33+
34+
@Override
35+
protected void deployConfiguration(CommandContext context, Configuration config) {
36+
if (context.getAppConfig().getCmaConfig().isCombineRequests()) {
37+
logger.info("Adding protected paths to combined CMA request");
38+
context.addCmaConfigurationToCombinedRequest(config);
39+
} else {
40+
super.deployConfiguration(context, config);
41+
}
1742
}
1843

1944
@Override
Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
package com.marklogic.appdeployer.command.security;
22

3+
import com.fasterxml.jackson.databind.node.ObjectNode;
34
import com.marklogic.appdeployer.command.AbstractResourceCommand;
45
import com.marklogic.appdeployer.command.CommandContext;
56
import com.marklogic.appdeployer.command.SortOrderConstants;
7+
import com.marklogic.appdeployer.command.SupportsCmaCommand;
8+
import com.marklogic.mgmt.api.configuration.Configuration;
9+
import com.marklogic.mgmt.api.security.queryroleset.QueryRoleset;
610
import com.marklogic.mgmt.resource.ResourceManager;
7-
import com.marklogic.mgmt.resource.security.QueryRolesetsManager;
11+
import com.marklogic.mgmt.resource.security.QueryRolesetManager;
812

913
import java.io.File;
1014

11-
public class DeployQueryRolesetsCommand extends AbstractResourceCommand {
15+
public class DeployQueryRolesetsCommand extends AbstractResourceCommand implements SupportsCmaCommand {
1216

1317
public DeployQueryRolesetsCommand() {
1418
setExecuteSortOrder(SortOrderConstants.DEPLOY_QUERY_ROLESETS);
1519
setUndoSortOrder(SortOrderConstants.DELETE_QUERY_ROLESETS);
20+
21+
setResourceClassType(QueryRoleset.class);
22+
}
23+
24+
@Override
25+
public boolean cmaShouldBeUsed(CommandContext context) {
26+
return context.getAppConfig().getCmaConfig().isDeployQueryRolesets();
27+
}
28+
29+
@Override
30+
public void addResourceToConfiguration(ObjectNode resource, Configuration configuration) {
31+
configuration.addQueryRoleset(resource);
32+
}
33+
34+
@Override
35+
protected void deployConfiguration(CommandContext context, Configuration config) {
36+
if (context.getAppConfig().getCmaConfig().isCombineRequests()) {
37+
logger.info("Adding query rolesets to combined CMA request");
38+
context.addCmaConfigurationToCombinedRequest(config);
39+
} else {
40+
super.deployConfiguration(context, config);
41+
}
1642
}
1743

1844
@Override
@@ -22,6 +48,6 @@ protected File[] getResourceDirs(CommandContext context) {
2248

2349
@Override
2450
protected ResourceManager getResourceManager(CommandContext context) {
25-
return new QueryRolesetsManager(context.getManageClient());
51+
return new QueryRolesetManager(context.getManageClient());
2652
}
2753
}

src/main/java/com/marklogic/mgmt/api/API.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.marklogic.mgmt.api.group.Group;
1616
import com.marklogic.mgmt.api.restapi.RestApi;
1717
import com.marklogic.mgmt.api.security.*;
18+
import com.marklogic.mgmt.api.security.protectedpath.ProtectedPath;
19+
import com.marklogic.mgmt.api.security.queryroleset.QueryRoleset;
1820
import com.marklogic.mgmt.api.server.Server;
1921
import com.marklogic.mgmt.api.task.Task;
2022
import com.marklogic.mgmt.api.trigger.Trigger;
@@ -31,6 +33,8 @@
3133
import com.marklogic.mgmt.util.SystemPropertySource;
3234

3335
import java.io.IOException;
36+
import java.util.ArrayList;
37+
import java.util.List;
3438

3539
/**
3640
* Big facade-style class for the MarkLogic Management API. Use this to instantiate or access any resource, as it will
@@ -230,6 +234,26 @@ public Forest getForest() {
230234
return forest(null);
231235
}
232236

237+
public ProtectedPath protectedPath(String pathExpression) {
238+
ProtectedPath path = new ProtectedPath(pathExpression);
239+
path.setApi(this);
240+
return pathExpression != null && path.exists() ?
241+
getResource(pathExpression, new ProtectedPathManager(getManageClient()), ProtectedPath.class) : path;
242+
}
243+
244+
public QueryRoleset queryRoleset(String... roleNames) {
245+
List<String> names = new ArrayList<>();
246+
for (String name : roleNames) {
247+
names.add(name);
248+
}
249+
QueryRoleset roleset = new QueryRoleset();
250+
roleset.setApi(this);
251+
roleset.setRoleName(names);
252+
return roleNames != null && roleset.exists() ?
253+
getResource(roleset.getRoleNamesAsJsonArrayString(), new QueryRolesetManager(getManageClient()), QueryRoleset.class) :
254+
roleset;
255+
}
256+
233257
public Server server(String name) {
234258
return server(name, (Integer)null);
235259
}

src/main/java/com/marklogic/mgmt/api/configuration/Configuration.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public class Configuration {
3131
@JsonProperty("privilege")
3232
private List<ObjectNode> privileges;
3333

34+
@JsonProperty("protected-path")
35+
private List<ObjectNode> protectedPaths;
36+
37+
@JsonProperty("query-roleset")
38+
private List<ObjectNode> queryRolesets;
39+
3440
@JsonProperty("role")
3541
private List<ObjectNode> roles;
3642

@@ -47,6 +53,8 @@ public boolean hasResources() {
4753
(forests != null && !forests.isEmpty()) ||
4854
(groups != null && !groups.isEmpty()) ||
4955
(privileges != null && !privileges.isEmpty()) ||
56+
(protectedPaths != null && !protectedPaths.isEmpty()) ||
57+
(queryRolesets != null && !queryRolesets.isEmpty()) ||
5058
(roles != null && !roles.isEmpty()) ||
5159
(servers != null && !servers.isEmpty()) ||
5260
(users != null && !users.isEmpty());
@@ -81,6 +89,16 @@ public void addGroup(ObjectNode g) {
8189
groups.add(g);
8290
}
8391

92+
public void addProtectedPath(ObjectNode node) {
93+
if (protectedPaths == null) protectedPaths = new ArrayList<>();
94+
protectedPaths.add(node);
95+
}
96+
97+
public void addQueryRoleset(ObjectNode node) {
98+
if (queryRolesets == null) queryRolesets = new ArrayList<>();
99+
queryRolesets.add(node);
100+
}
101+
84102
public void addRole(ObjectNode r) {
85103
if (roles == null) roles = new ArrayList<>();
86104
roles.add(r);
@@ -164,4 +182,20 @@ public List<ObjectNode> getPrivileges() {
164182
public void setPrivileges(List<ObjectNode> privileges) {
165183
this.privileges = privileges;
166184
}
185+
186+
public List<ObjectNode> getProtectedPaths() {
187+
return protectedPaths;
188+
}
189+
190+
public void setProtectedPaths(List<ObjectNode> protectedPaths) {
191+
this.protectedPaths = protectedPaths;
192+
}
193+
194+
public List<ObjectNode> getQueryRolesets() {
195+
return queryRolesets;
196+
}
197+
198+
public void setQueryRolesets(List<ObjectNode> queryRolesets) {
199+
this.queryRolesets = queryRolesets;
200+
}
167201
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.marklogic.mgmt.api.security.protectedpath;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlElement;
6+
7+
@XmlAccessorType(XmlAccessType.FIELD)
8+
public class PathNamespace {
9+
10+
private String prefix;
11+
12+
@XmlElement(name = "namespace-uri")
13+
private String namespaceUri;
14+
15+
public PathNamespace() {
16+
}
17+
18+
public PathNamespace(String prefix, String namespaceUri) {
19+
this.prefix = prefix;
20+
this.namespaceUri = namespaceUri;
21+
}
22+
23+
public String getPrefix() {
24+
return prefix;
25+
}
26+
27+
public void setPrefix(String prefix) {
28+
this.prefix = prefix;
29+
}
30+
31+
public String getNamespaceUri() {
32+
return namespaceUri;
33+
}
34+
35+
public void setNamespaceUri(String namespaceUri) {
36+
this.namespaceUri = namespaceUri;
37+
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.marklogic.mgmt.api.security.protectedpath;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlElement;
6+
7+
@XmlAccessorType(XmlAccessType.FIELD)
8+
public class Permission {
9+
10+
@XmlElement(name = "role-name")
11+
private String roleName;
12+
private String capability;
13+
14+
public Permission() {
15+
}
16+
17+
public Permission(String roleName, String capability) {
18+
this.roleName = roleName;
19+
this.capability = capability;
20+
}
21+
22+
public String getRoleName() {
23+
return roleName;
24+
}
25+
26+
public void setRoleName(String roleName) {
27+
this.roleName = roleName;
28+
}
29+
30+
public String getCapability() {
31+
return capability;
32+
}
33+
34+
public void setCapability(String capability) {
35+
this.capability = capability;
36+
}
37+
}

0 commit comments

Comments
 (0)