Skip to content

Commit 17737f2

Browse files
Roy Teeuwenkwin
authored andcommitted
Add option to allow mutable install hooks for local AEM SDK development. Used for example by accesscontroltool
1 parent 76175d6 commit 17737f2

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ The following options are supported apart from the default settings mentioned in
1717
Option | Mandatory | Description | Default Value | Since Version
1818
--- | --- | --- | --- | ---
1919
`allowReadOnlyMutablePaths` (or `allowVarNodeOutsideContainer` deprecated) | no | `true` means read-only paths (i.e. paths to which the service session used for mutable package installation on publish does not have write permission) should be allowed. Otherwise those will only be allowed in author-only packages included in a container package. | `false` | 1.2.0
20-
`allowLibsNode` | no | `true` means that `libs` nodes are allowed in content packages. *Only set this to `true` when building packages which are part of the AEM product.* | `false` | 1.2.0
20+
`allowLibsNode` | no | `true` means that `libs` nodes are allowed in content packages. *Only set this to `true` when building packages which are part of the AEM product.* | `false` | 1.2.0
21+
`allowHooksInMutableContent` | no | `true` means that JCR Install Hooks are allowed in content packages. *Only set this to `true` when building packages for local AEM SDK development, where install hooks are supported for mutable content.* | `false` | 1.3.0
2122

2223
# Included Checks
2324

src/main/java/biz/netcentric/filevault/validator/aem/cloud/AemCloudValidator.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class AemCloudValidator implements NodePathValidator, MetaInfPathValidato
6464
private boolean hasMutableNodes;
6565
private final boolean allowReadOnlyMutablePaths;
6666
private final boolean allowLibsNode;
67+
private final boolean allowHooksInMutableContent;
6768
private boolean hasInstallHooks;
6869
private boolean hasImmutableNodes;
6970

@@ -72,11 +73,12 @@ public class AemCloudValidator implements NodePathValidator, MetaInfPathValidato
7273
private int numLibNodeViolations = 0;
7374
private int numMutableNodeViolations = 0;
7475

75-
public AemCloudValidator(boolean allowReadOnlyMutablePaths, boolean allowLibsNode, @Nullable PackageType packageType,
76-
@Nullable ValidationContext containerValidationContext, @NotNull ValidationMessageSeverity defaultSeverity) {
76+
public AemCloudValidator(boolean allowReadOnlyMutablePaths, boolean allowLibsNode, boolean allowHooksInMutableContent, @Nullable PackageType packageType,
77+
@Nullable ValidationContext containerValidationContext, @NotNull ValidationMessageSeverity defaultSeverity) {
7778
super();
7879
this.allowReadOnlyMutablePaths = allowReadOnlyMutablePaths;
7980
this.allowLibsNode = allowLibsNode;
81+
this.allowHooksInMutableContent = allowHooksInMutableContent;
8082
this.packageType = packageType;
8183
this.containerValidationContext = containerValidationContext;
8284
this.defaultSeverity = defaultSeverity;
@@ -165,7 +167,7 @@ static boolean isPackagePathInstalledConditionally(String runMode, Path packageR
165167
@Override
166168
public @Nullable Collection<ValidationMessage> done() {
167169
Collection<ValidationMessage> messages = new ArrayList<>();
168-
if (hasInstallHooks && hasMutableNodes) {
170+
if (hasInstallHooks && hasMutableNodes && !allowHooksInMutableContent) {
169171
messages.add(new ValidationMessage(defaultSeverity, VIOLATION_MESSAGE_INSTALL_HOOK_IN_MUTABLE_PACKAGE));
170172
}
171173
// for non-set package types usually the package type is determined by cp2fm, but it will be MIXED in case both mutable and immutable nodes are contained
@@ -181,7 +183,10 @@ static boolean isPackagePathInstalledConditionally(String runMode, Path packageR
181183
if (filePath.startsWith(INSTALL_HOOK_PATH) && filePath.toString().endsWith(".jar")) {
182184
// is it mutable content package?
183185
if (PackageType.CONTENT.equals(packageType)) {
184-
return Collections.singleton(new ValidationMessage(defaultSeverity, VIOLATION_MESSAGE_INSTALL_HOOK_IN_MUTABLE_PACKAGE));
186+
hasInstallHooks = true;
187+
if (!allowHooksInMutableContent) {
188+
return Collections.singleton(new ValidationMessage(defaultSeverity, VIOLATION_MESSAGE_INSTALL_HOOK_IN_MUTABLE_PACKAGE));
189+
}
185190
} else if (packageType == null) {
186191
// defer checking until one is sure that the package has mutable content
187192
hasInstallHooks = true;

src/main/java/biz/netcentric/filevault/validator/aem/cloud/AemCloudValidatorFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class AemCloudValidatorFactory implements ValidatorFactory {
2929
private static final String OPTION_ALLOW_VAR_NODE_OUTSIDE_CONTAINERS = "allowVarNodeOutsideContainer";
3030
private static final String OPTION_ALLOW_READONLY_MUTABLE_PATHS = "allowReadOnlyMutablePaths";
3131
private static final String OPTION_ALLOW_LIBS_NODE = "allowLibsNode";
32+
private static final String OPTION_ALLOW_HOOKS_IN_MUTABLE_CONTENT = "allowHooksInMutableContent";
3233

3334
private static final Logger LOGGER = LoggerFactory.getLogger(AemCloudValidatorFactory.class);
3435

@@ -43,10 +44,14 @@ public Validator createValidator(@NotNull ValidationContext context, @NotNull Va
4344
LOGGER.warn("Using deprecated option 'allowVarNodeOutsideContainer', please use 'allowReadOnlyMutablePaths' instead");
4445
}
4546
boolean allowLibsNode = false;
47+
boolean allowHooksInMutableContent = false;
4648
if (settings.getOptions().containsKey(OPTION_ALLOW_LIBS_NODE)) {
4749
allowLibsNode = Boolean.parseBoolean(settings.getOptions().get(OPTION_ALLOW_LIBS_NODE));
4850
}
49-
return new AemCloudValidator(allowReadOnlyMutablePaths, allowLibsNode, context.getProperties().getPackageType(), context.getContainerValidationContext(), settings.getDefaultSeverity());
51+
if (settings.getOptions().containsKey(OPTION_ALLOW_HOOKS_IN_MUTABLE_CONTENT)) {
52+
allowHooksInMutableContent = Boolean.parseBoolean(settings.getOptions().get(OPTION_ALLOW_HOOKS_IN_MUTABLE_CONTENT));
53+
}
54+
return new AemCloudValidator(allowReadOnlyMutablePaths, allowLibsNode, allowHooksInMutableContent, context.getProperties().getPackageType(), context.getContainerValidationContext(), settings.getDefaultSeverity());
5055
}
5156

5257
@Override

src/test/java/biz/netcentric/filevault/validator/aem/cloud/AemCloudValidatorTest.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
*/
1515

1616
import java.nio.file.Paths;
17+
import java.util.ArrayList;
1718
import java.util.Collection;
19+
import java.util.Optional;
1820

1921
import org.apache.jackrabbit.vault.packaging.PackageType;
2022
import org.apache.jackrabbit.vault.validation.spi.ValidationMessage;
2123
import org.apache.jackrabbit.vault.validation.spi.ValidationMessageSeverity;
2224
import org.junit.jupiter.api.Assertions;
2325
import org.junit.jupiter.api.Test;
2426

27+
import static biz.netcentric.filevault.validator.aem.cloud.AemCloudValidator.VIOLATION_MESSAGE_INSTALL_HOOK_IN_MUTABLE_PACKAGE;
28+
2529
class AemCloudValidatorTest {
2630

2731
@Test
@@ -53,16 +57,31 @@ void testIsPathWritableByDistributionJournalImporter() {
5357

5458
@Test
5559
void testMutablePaths(){
56-
AemCloudValidator validator = new AemCloudValidator(false, false, PackageType.CONTENT, null, ValidationMessageSeverity.ERROR);
60+
AemCloudValidator validator = new AemCloudValidator(false, false, false, PackageType.CONTENT, null, ValidationMessageSeverity.ERROR);
5761
Collection<ValidationMessage> messages = validator.validate("/var/subnode");
5862
Assertions.assertFalse(messages.isEmpty());
5963
}
6064

6165
@Test
6266
void testAllowReadOnlyMutablePaths(){
63-
AemCloudValidator validator = new AemCloudValidator(true, false, PackageType.CONTENT, null, ValidationMessageSeverity.ERROR);
67+
AemCloudValidator validator = new AemCloudValidator(true, false, false, PackageType.CONTENT, null, ValidationMessageSeverity.ERROR);
6468
Collection<ValidationMessage> messages = validator.validate("/var/subnode");
6569
Assertions.assertTrue(messages.isEmpty());
6670
}
6771

72+
@Test
73+
void testAllowHooksInMutableContent() {
74+
AemCloudValidator validator = new AemCloudValidator(true, false, false, PackageType.CONTENT, null, ValidationMessageSeverity.ERROR);
75+
Collection<ValidationMessage> messages = new ArrayList<>();
76+
Optional.ofNullable(validator.validateMetaInfPath(Paths.get("vault/hooks/install-hook.jar"))).ifPresent(messages::addAll);
77+
Optional.ofNullable(validator.done()).ifPresent(messages::addAll);
78+
Assertions.assertTrue(messages.stream().anyMatch(message -> message.getMessage().equals(VIOLATION_MESSAGE_INSTALL_HOOK_IN_MUTABLE_PACKAGE)));
79+
80+
validator = new AemCloudValidator(true, false, true, PackageType.CONTENT, null, ValidationMessageSeverity.ERROR);
81+
messages = new ArrayList<>();
82+
Optional.ofNullable(validator.validateMetaInfPath(Paths.get("vault/hooks/install-hook.jar"))).ifPresent(messages::addAll);
83+
Optional.ofNullable(validator.done()).ifPresent(messages::addAll);
84+
Assertions.assertTrue(messages.isEmpty());
85+
}
86+
6887
}

0 commit comments

Comments
 (0)