Skip to content

Commit

Permalink
Merge pull request #396 from wttech/actions-checks
Browse files Browse the repository at this point in the history
refactor :app:aem:actions.checks module
  • Loading branch information
dprzybyl authored Jul 24, 2023
2 parents 566e977 + df1fd70 commit 6440600
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 19 deletions.
1 change: 0 additions & 1 deletion app/aem/actions.checks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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<String> ids) {
return new CheckExcludes(group, ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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<String> ids) {
return new CheckIncludes(group, ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> ids) {
public Action mapAction(
@Required(value = "ids", description = "users' or groups' ids e.g.: ['author']") List<String> ids) {
return new CheckNotExists(ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<String> 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<String> permissions,
@Named(value = "glob", description = "regular expression to narrow set of paths") String glob) {
return new CheckPermissions(id, path, glob, permissions, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<String> 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<String> permissions,
@Named(value = "glob", description = "regular expression to narrow set of paths") String glob) {
return new CheckPermissions(id, path, glob, permissions, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
1 change: 0 additions & 1 deletion examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down

0 comments on commit 6440600

Please sign in to comment.