Skip to content

Commit

Permalink
Merge branch 'master' into fix-path
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ScriptRunner.kt
  • Loading branch information
dprzybyl committed Jul 25, 2023
2 parents 2f086b8 + 6440600 commit f3c9ff0
Show file tree
Hide file tree
Showing 91 changed files with 1,175 additions and 520 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 @@ -23,6 +23,7 @@
import com.cognifide.apm.api.actions.ActionResult;
import com.cognifide.apm.api.actions.Context;
import com.cognifide.apm.api.exceptions.ActionExecutionException;
import com.cognifide.apm.api.exceptions.AuthorizableNotFoundException;
import com.cognifide.apm.checks.utils.ActionUtils;
import com.cognifide.apm.checks.utils.MessagingUtils;
import java.util.ArrayList;
Expand All @@ -37,7 +38,7 @@ public class CheckExcludes implements Action {

private final String groupId;

public CheckExcludes(final String groupId, final List<String> authorizableIds) {
public CheckExcludes(String groupId, List<String> authorizableIds) {
this.groupId = groupId;
this.authorizableIds = authorizableIds;
}
Expand All @@ -48,12 +49,11 @@ public ActionResult simulate(Context context) {
}

@Override
public ActionResult execute(final Context context) {
public ActionResult execute(Context context) {
return process(context, true);
}

private ActionResult process(final Context context, boolean execute) {

private ActionResult process(Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
Group group = tryGetGroup(context, actionResult);
if (group == null) {
Expand All @@ -74,8 +74,7 @@ private ActionResult process(final Context context, boolean execute) {
return actionResult;
}

private boolean checkMembers(final Context context, final ActionResult actionResult, final Group group,
final List<String> errors) {
private boolean checkMembers(Context context, ActionResult actionResult, Group group, List<String> errors) {
boolean checkFailed = false;
for (String authorizableId : authorizableIds) {
try {
Expand All @@ -95,19 +94,12 @@ private boolean checkMembers(final Context context, final ActionResult actionRes
return checkFailed;
}

private Group tryGetGroup(final Context context, final ActionResult actionResult) {
Group group;

private Group tryGetGroup(Context context, ActionResult actionResult) {
try {
group = context.getAuthorizableManager().getGroup(groupId);
} catch (RepositoryException e) {
return context.getAuthorizableManager().getGroup(groupId);
} catch (RepositoryException | ActionExecutionException | AuthorizableNotFoundException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return null;
} catch (ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
return null;
}
return group;
return null;
}

}
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 @@ -23,6 +23,7 @@
import com.cognifide.apm.api.actions.ActionResult;
import com.cognifide.apm.api.actions.Context;
import com.cognifide.apm.api.exceptions.ActionExecutionException;
import com.cognifide.apm.api.exceptions.AuthorizableNotFoundException;
import com.cognifide.apm.checks.utils.ActionUtils;
import com.cognifide.apm.checks.utils.MessagingUtils;
import java.util.ArrayList;
Expand All @@ -37,7 +38,7 @@ public class CheckIncludes implements Action {

private final String authorizableId;

public CheckIncludes(final String id, final List<String> groupIds) {
public CheckIncludes(String id, List<String> groupIds) {
this.authorizableId = id;
this.groupIds = groupIds;
}
Expand All @@ -48,11 +49,11 @@ public ActionResult simulate(Context context) {
}

@Override
public ActionResult execute(final Context context) {
public ActionResult execute(Context context) {
return process(context, true);
}

private ActionResult process(final Context context, boolean execute) {
private ActionResult process(Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
Group authorizable = tryGetGroup(context, actionResult);
if (authorizable == null) {
Expand All @@ -71,11 +72,9 @@ private ActionResult process(final Context context, boolean execute) {
ActionUtils.logErrors(errors, actionResult);

return actionResult;

}

private boolean checkMembers(final Context context, final ActionResult actionResult,
final Group authorizable, final List<String> errors) {
private boolean checkMembers(Context context, ActionResult actionResult, Group authorizable, List<String> errors) {
boolean checkFailed = false;
for (String id : groupIds) {
try {
Expand All @@ -86,17 +85,17 @@ private boolean checkMembers(final Context context, final ActionResult actionRes
checkFailed = true;
}
actionResult.logMessage(id + " is a member of group " + authorizableId);
} catch (RepositoryException | ActionExecutionException e) {
} catch (RepositoryException | ActionExecutionException | AuthorizableNotFoundException e) {
errors.add(MessagingUtils.createMessage(e));
}
}
return checkFailed;
}

private Group tryGetGroup(final Context context, final ActionResult actionResult) {
private Group tryGetGroup(Context context, ActionResult actionResult) {
try {
return context.getAuthorizableManager().getGroup(authorizableId);
} catch (RepositoryException | ActionExecutionException e) {
} catch (RepositoryException | ActionExecutionException | AuthorizableNotFoundException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return null;
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 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);
}
}
Loading

0 comments on commit f3c9ff0

Please sign in to comment.