From df1fd7025c21ab6bb9c0e10867d3d0ebd69a82be Mon Sep 17 00:00:00 2001 From: Dominik Przybyl Date: Sun, 23 Jul 2023 02:34:07 +0200 Subject: [PATCH] refactor :app:aem:actions.checks module --- app/aem/actions.checks/build.gradle.kts | 1 - .../actions/exclude/CheckExcludesMapper.java | 11 +++++++++-- .../actions/exists/CheckGroupExistsMapper.java | 16 ++++++++++++++-- .../actions/exists/CheckUserExistsMapper.java | 16 ++++++++++++++-- .../actions/include/CheckIncludesMapper.java | 15 +++++++++++---- .../actions/notexists/CheckNotExistsMapper.java | 9 +++++++-- .../actions/password/CheckPasswordMapper.java | 8 ++++++-- .../actions/permissions/CheckAllowMapper.java | 9 ++++++++- .../actions/permissions/CheckDenyMapper.java | 10 +++++++++- .../actions/property/CheckPropertyMapper.java | 7 ++++++- examples/build.gradle.kts | 1 - 11 files changed, 84 insertions(+), 19 deletions(-) diff --git a/app/aem/actions.checks/build.gradle.kts b/app/aem/actions.checks/build.gradle.kts index fd2c33a0e..b04e28f1d 100644 --- a/app/aem/actions.checks/build.gradle.kts +++ b/app/aem/actions.checks/build.gradle.kts @@ -22,7 +22,6 @@ aem { val currentVersion = rootProject.version as String version.set(currentVersion) description.set(project.description) - property("dependencies", "com.cognifide.apm:apm-ui.apps:" + currentVersion.substringBefore("-SNAPSHOT")) } } jar { diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludesMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludesMapper.java index 46de025a2..0d07bc561 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludesMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludesMapper.java @@ -22,6 +22,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; import java.util.Collections; import java.util.List; @@ -32,16 +33,22 @@ public final class CheckExcludesMapper { public static final String REFERENCE = "Verify that provided group DOES NOT contain any of listed authorizables."; @Mapping( + examples = "CHECK-EXCLUDES 'authors' 'author'", reference = REFERENCE ) - public Action mapAction(String group, String id) { + public Action mapAction( + @Required(value = "group", description = "group's id e.g.: 'authors'") String group, + @Required(value = "id", description = "users' or groups' id e.g.: 'author'") String id) { return mapAction(group, Collections.singletonList(id)); } @Mapping( + examples = "CHECK-EXCLUDES 'authors' ['author']", reference = REFERENCE ) - public Action mapAction(String group, List ids) { + public Action mapAction( + @Required(value = "group", description = "group's id e.g.: 'authors'") String group, + @Required(value = "ids", description = "users' or groups' ids e.g.: ['author']") List ids) { return new CheckExcludes(group, ids); } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckGroupExistsMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckGroupExistsMapper.java index 348bfca64..8d86db8c4 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckGroupExistsMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckGroupExistsMapper.java @@ -22,7 +22,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; -import com.cognifide.apm.api.actions.annotations.Named; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; @Mapper(value = "CHECK-GROUP-EXISTS", group = ActionGroup.CHECKS) @@ -32,9 +32,21 @@ public final class CheckGroupExistsMapper { + " Optionally it can be used to verify that given group resides in specific path."; @Mapping( + examples = "CHECK-GROUP-EXISTS 'authors'", reference = REFERENCE ) - public Action mapAction(String id, @Named("path") String path) { + public Action mapAction( + @Required(value = "id", description = "group's id e.g.: 'authors'") String id) { + return mapAction(id, null); + } + + @Mapping( + examples = "CHECK-GROUP-EXISTS 'authors' '/home/groups/client/domain'", + reference = REFERENCE + ) + public Action mapAction( + @Required(value = "id", description = "group's id e.g.: 'authors'") String id, + @Required(value = "path", description = "group's home e.g.: '/home/groups/client/domain'") String path) { return new CheckAuthorizableExists(id, path, true); } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckUserExistsMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckUserExistsMapper.java index 938e9f16d..5078ee8cd 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckUserExistsMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckUserExistsMapper.java @@ -22,7 +22,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; -import com.cognifide.apm.api.actions.annotations.Named; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; @Mapper(value = "CHECK-USER-EXISTS", group = ActionGroup.CHECKS) @@ -32,9 +32,21 @@ public final class CheckUserExistsMapper { + " Optionally it can be used to verify that given user resides in specific path."; @Mapping( + examples = "CHECK-USER-EXISTS 'author'", reference = REFERENCE ) - public Action mapAction(String id, @Named("path") String path) { + public Action mapAction( + @Required(value = "id", description = "user's login e.g.: 'author'") String id) { + return mapAction(id, null); + } + + @Mapping( + examples = "CHECK-USER-EXISTS 'author' '/home/users/client/domain'", + reference = REFERENCE + ) + public Action mapAction( + @Required(value = "id", description = "user's login e.g.: 'author'") String id, + @Required(value = "path", description = "user's home e.g.: '/home/users/client/domain'") String path) { return new CheckAuthorizableExists(id, path, false); } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/include/CheckIncludesMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/include/CheckIncludesMapper.java index 56de9ebac..66791e8b3 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/include/CheckIncludesMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/include/CheckIncludesMapper.java @@ -22,6 +22,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; import java.util.Collections; import java.util.List; @@ -32,16 +33,22 @@ public final class CheckIncludesMapper { public static final String REFERENCE = "Verify that provided group contains all listed authorizables."; @Mapping( + examples = "CHECK-INCLUDES 'authors' 'author'", reference = REFERENCE ) - public Action mapAction(String id, String group) { - return mapAction(id, Collections.singletonList(group)); + public Action mapAction( + @Required(value = "group", description = "group's id e.g.: 'authors'") String group, + @Required(value = "id", description = "users' or groups' id e.g.: 'author'") String id) { + return mapAction(group, Collections.singletonList(id)); } @Mapping( + examples = "CHECK-INCLUDES 'authors' ['author']", reference = REFERENCE ) - public Action mapAction(String id, List groups) { - return new CheckIncludes(id, groups); + public Action mapAction( + @Required(value = "group", description = "group's id e.g.: 'authors'") String group, + @Required(value = "ids", description = "users' or groups' ids e.g.: ['author']") List ids) { + return new CheckIncludes(group, ids); } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/notexists/CheckNotExistsMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/notexists/CheckNotExistsMapper.java index fc061552f..afabbbab2 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/notexists/CheckNotExistsMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/notexists/CheckNotExistsMapper.java @@ -22,6 +22,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; import java.util.Collections; import java.util.List; @@ -32,16 +33,20 @@ public final class CheckNotExistsMapper { public static final String REFERENCE = "Verify that specific authorizables do not exist."; @Mapping( + examples = "CHECK-NOT-EXISTS 'author'", reference = REFERENCE ) - public Action mapAction(String id) { + public Action mapAction( + @Required(value = "id", description = "users' or groups' id e.g.: 'author'") String id) { return mapAction(Collections.singletonList(id)); } @Mapping( + examples = "CHECK-NOT-EXISTS ['author']", reference = REFERENCE ) - public Action mapAction(List ids) { + public Action mapAction( + @Required(value = "ids", description = "users' or groups' ids e.g.: ['author']") List ids) { return new CheckNotExists(ids); } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/password/CheckPasswordMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/password/CheckPasswordMapper.java index 1b478456c..4a3b5a6f4 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/password/CheckPasswordMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/password/CheckPasswordMapper.java @@ -22,6 +22,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; @Mapper(value = "CHECK-PASSWORD", group = ActionGroup.CHECKS) @@ -30,9 +31,12 @@ public final class CheckPasswordMapper { public static final String REFERENCE = "Verify that specific password is set for given authorizable."; @Mapping( + examples = "CHECK-PASSWORD 'author' 'p@$$w0rd'", reference = REFERENCE ) - public Action mapAction(String userId, String password) { - return new CheckPassword(userId, password); + public Action mapAction( + @Required(value = "id", description = "user's login e.g.: 'author'") String id, + @Required(value = "password", description = "user's password e.g.: 'p@$$w0rd'") String password) { + return new CheckPassword(id, password); } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckAllowMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckAllowMapper.java index 9320b5060..d4ef3c8b8 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckAllowMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckAllowMapper.java @@ -23,7 +23,9 @@ import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; import com.cognifide.apm.api.actions.annotations.Named; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; +import java.util.Collections; import java.util.List; @Mapper(value = "CHECK-ALLOW", group = ActionGroup.CHECKS) @@ -33,9 +35,14 @@ public final class CheckAllowMapper { + " on specified path."; @Mapping( + examples = "CHECK-ALLOW author '/content/dam' [READ, 'jcr:all']", reference = REFERENCE ) - public Action mapAction(String id, String path, List permissions, @Named("glob") String glob) { + public Action mapAction( + @Required(value = "id", description = "users' or groups' id e.g.: 'author'") String id, + @Required(value = "path", description = "e.g.: '/content/dam'") String path, + @Required(value = "permissions", description = "e.g.: [READ, 'jcr:all']") List permissions, + @Named(value = "glob", description = "regular expression to narrow set of paths") String glob) { return new CheckPermissions(id, path, glob, permissions, true); } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckDenyMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckDenyMapper.java index 5f51e4bed..2f068078b 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckDenyMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckDenyMapper.java @@ -22,7 +22,10 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; +import com.cognifide.apm.api.actions.annotations.Named; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; +import java.util.Collections; import java.util.List; @Mapper(value = "CHECK-DENY", group = ActionGroup.CHECKS) @@ -32,9 +35,14 @@ public final class CheckDenyMapper { + " on specified path."; @Mapping( + examples = "CHECK-DENY author '/content/dam' [READ, 'jcr:all']", reference = REFERENCE ) - public Action mapAction(String id, String path, String glob, List permissions) { + public Action mapAction( + @Required(value = "id", description = "users' or groups' id e.g.: 'author'") String id, + @Required(value = "path", description = "e.g.: '/content/dam'") String path, + @Required(value = "permissions", description = "e.g.: [READ, 'jcr:all']") List permissions, + @Named(value = "glob", description = "regular expression to narrow set of paths") String glob) { return new CheckPermissions(id, path, glob, permissions, false); } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/property/CheckPropertyMapper.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/property/CheckPropertyMapper.java index c4cf1c69d..e7be20401 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/property/CheckPropertyMapper.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/property/CheckPropertyMapper.java @@ -22,6 +22,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.api.actions.annotations.Mapper; import com.cognifide.apm.api.actions.annotations.Mapping; +import com.cognifide.apm.api.actions.annotations.Required; import com.cognifide.apm.checks.actions.ActionGroup; @Mapper(value = "CHECK-PROPERTY", group = ActionGroup.CHECKS) @@ -30,9 +31,13 @@ public final class CheckPropertyMapper { public static final String REFERENCE = "Verify that a property is set to specific value for given authorizable."; @Mapping( + examples = "CHECK-PROPERTY 'author' 'title' 'John Doe'", reference = REFERENCE ) - public Action mapAction(String id, String name, String value) { + public Action mapAction( + @Required(value = "id", description = "users' or groups' id e.g.: 'author'") String id, + @Required(value = "name", description = "property name") String name, + @Required(value = "value", description = "property value") String value) { return new CheckProperty(id, name, value); } } diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 98ba3e73f..4a4545cf4 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -40,7 +40,6 @@ aem { version.set(currentVersion) description.set(project.description) property("installhook.apm.class", "com.cognifide.apm.core.tools.ApmInstallHook") - property("dependencies", "com.cognifide.apm:apm-ui.apps:$currentVersion") } } }