diff --git a/app/aem/actions.checks/build.gradle.kts b/app/aem/actions.checks/build.gradle.kts index 441e3e399..7a09acc1a 100644 --- a/app/aem/actions.checks/build.gradle.kts +++ b/app/aem/actions.checks/build.gradle.kts @@ -36,6 +36,9 @@ aem { dependencies { implementation(project(":app:aem:api")) + + compileOnly("org.projectlombok:lombok:1.18.8") + annotationProcessor("org.projectlombok:lombok:1.18.8") } tasks { diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/ActionGroup.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/ActionGroup.java index 555e95e25..c9d6a5dde 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/ActionGroup.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/ActionGroup.java @@ -20,7 +20,11 @@ package com.cognifide.apm.checks.actions; -public class ActionGroup { +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ActionGroup { public static final String CHECKS = "checks"; } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludes.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludes.java index c1aa259e6..d6451f15d 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludes.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exclude/CheckExcludes.java @@ -75,7 +75,7 @@ private ActionResult process(final Context context, boolean execute) { } private boolean checkMembers(final Context context, final ActionResult actionResult, final Group group, - final List errors) { + final List errors) { boolean checkFailed = false; for (String authorizableId : authorizableIds) { try { @@ -96,16 +96,11 @@ private boolean checkMembers(final Context context, final ActionResult actionRes } private Group tryGetGroup(final Context context, final ActionResult actionResult) { - Group group; - + Group group = null; try { group = context.getAuthorizableManager().getGroup(groupId); - } catch (RepositoryException e) { - actionResult.logError(MessagingUtils.createMessage(e)); - return null; - } catch (ActionExecutionException e) { + } catch (RepositoryException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); - return null; } return group; } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckAuthorizableExists.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckAuthorizableExists.java index 72c407329..a9405009f 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckAuthorizableExists.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/exists/CheckAuthorizableExists.java @@ -76,7 +76,7 @@ public ActionResult process(final Context context, boolean execute) { } private boolean checkIfAuthIsNull(final boolean execute, final ActionResult actionResult, - final Authorizable authorizable) throws RepositoryException { + final Authorizable authorizable) { if (authorizable == null) { actionResult.logError("Authorizable " + id + " does not exist"); if (execute) { diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckPermissions.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckPermissions.java index bee004b79..6d25bb575 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckPermissions.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/actions/permissions/CheckPermissions.java @@ -26,8 +26,6 @@ import com.cognifide.apm.checks.utils.ActionUtils; import com.cognifide.apm.checks.utils.MessagingUtils; import com.day.cq.security.util.CqActions; -import com.google.common.base.Function; -import com.google.common.collect.Lists; import java.security.Principal; import java.util.ArrayList; import java.util.Collection; @@ -35,6 +33,7 @@ import java.util.List; import java.util.Set; import java.util.regex.Pattern; +import java.util.stream.Collectors; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; @@ -43,7 +42,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.security.principal.PrincipalIterator; import org.apache.jackrabbit.api.security.user.Authorizable; -import org.apache.sling.api.resource.LoginException; public class CheckPermissions implements Action { @@ -58,7 +56,7 @@ public class CheckPermissions implements Action { private final String authorizableId; public CheckPermissions(final String authorizableId, final String path, final String glob, - final List permissions, boolean isAllow) { + final List permissions, boolean isAllow) { this.authorizableId = authorizableId; this.path = path; this.glob = glob; @@ -102,16 +100,16 @@ private ActionResult process(final Context context, boolean execute) { } catch (final PathNotFoundException e) { actionResult.logError("Path " + path + " not found"); - } catch (RepositoryException | ActionExecutionException | LoginException e) { + } catch (RepositoryException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; } private void checkPermissionsForGlob(Session session, final boolean execute, final ActionResult actionResult, - final Authorizable authorizable, final Set authorizablesToCheck, - final CqActions actions, final List privilegesToCheck) - throws RepositoryException, LoginException { + final Authorizable authorizable, final Set authorizablesToCheck, + final CqActions actions, final List privilegesToCheck) + throws RepositoryException { final List subpaths = getAllSubpaths(session, path); Pattern pattern = Pattern.compile(path + StringUtils.replace(glob, "*", ".*")); boolean foundMatch = false; @@ -139,7 +137,7 @@ private void checkPermissionsForGlob(Session session, final boolean execute, fin } private boolean checkPermissionsForPath(final Set authorizablesToCheck, - final CqActions actions, final List privilegesToCheck, String subpath) + final CqActions actions, final List privilegesToCheck, String subpath) throws RepositoryException { Collection allowedActions = actions.getAllowedActions(subpath, authorizablesToCheck); final boolean containsAll = allowedActions.containsAll(privilegesToCheck); @@ -147,7 +145,7 @@ private boolean checkPermissionsForPath(final Set authorizablesToChec } private void logFailure(boolean execute, ActionResult actionResult, final Authorizable authorizable, - String subpath) throws RepositoryException { + String subpath) throws RepositoryException { actionResult.logError( "Not all required privileges are set for " + authorizable.getID() + " on " + subpath); if (execute) { @@ -155,7 +153,7 @@ private void logFailure(boolean execute, ActionResult actionResult, final Author } } - private List getAllSubpaths(Session session, final String path) throws RepositoryException, LoginException { + private List getAllSubpaths(Session session, final String path) throws RepositoryException { List subPaths = new ArrayList<>(); Node node = session.getNode(path); subPaths.addAll(crawl(node)); @@ -186,15 +184,8 @@ private Set getAuthorizablesToCheck(Authorizable authorizable, Contex return principals; } - private List preparePrivilegesToCheck() throws RepositoryException { - return Lists.transform(permissions, new toLowerCase()); + private List preparePrivilegesToCheck() { + return permissions.stream().map(String::toLowerCase).collect(Collectors.toList()); } - private static class toLowerCase implements Function { - - @Override - public String apply(String input) { - return input.toLowerCase(); - } - } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/ActionUtils.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/ActionUtils.java index da940d002..dbf3ff68e 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/ActionUtils.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/ActionUtils.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,56 +24,56 @@ import java.util.Iterator; import java.util.List; import javax.jcr.RepositoryException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ActionUtils { - public static final String ASSERTION_FAILED_MSG = "Assertion failed"; + public static final String ASSERTION_FAILED_MSG = "Assertion failed"; - private ActionUtils() { - } + /** + * Adding group to another group may result in cyclic relation. Let current group be the group where we + * want to add current authorizable to. If current authorizable contains group such that current group + * belongs to, then we prevent such operation. + * + * @param currentGroup The group where we want to add current authorizable + * @param groupToBeAdded Authorizable we want to add + * @throws ActionExecutionException Throw exception, if adding operation results in cyclic relation + */ + public static void checkCyclicRelations(Group currentGroup, Group groupToBeAdded) + throws ActionExecutionException { + try { + if (groupToBeAdded.getID().equals(currentGroup.getID())) { + throw new ActionExecutionException(MessagingUtils.addingGroupToItself(currentGroup.getID())); + } + Iterator parents = currentGroup.memberOf(); + while (parents.hasNext()) { + Group currentParent = parents.next(); + // Is added group among my parents? + if (currentParent.getID().equals(groupToBeAdded.getID())) { + throw new ActionExecutionException(MessagingUtils.cyclicRelationsForbidden( + currentGroup.getID(), groupToBeAdded.getID())); + } + // ... and are its children among my parents? + for (Iterator children = groupToBeAdded.getMembers(); children.hasNext(); ) { + Authorizable currentChild = children.next(); + if (currentParent.getID().equals(currentChild.getID())) { + throw new ActionExecutionException(MessagingUtils.cyclicRelationsForbidden( + currentChild.getID(), groupToBeAdded.getID())); + } + } + } + } catch (RepositoryException e) { + throw new ActionExecutionException(MessagingUtils.createMessage(e)); + } + } - /** - * Adding group to another group may result in cyclic relation. Let current group be the group where we - * want to add current authorizable to. If current authorizable contains group such that current group - * belongs to, then we prevent such operation. - * - * @param currentGroup The group where we want to add current authorizable - * @param groupToBeAdded Authorizable we want to add - * @throws ActionExecutionException Throw exception, if adding operation results in cyclic relation - */ - public static void checkCyclicRelations(Group currentGroup, Group groupToBeAdded) - throws ActionExecutionException { - try { - if (groupToBeAdded.getID().equals(currentGroup.getID())) { - throw new ActionExecutionException(MessagingUtils.addingGroupToItself(currentGroup.getID())); - } - Iterator parents = currentGroup.memberOf(); - while (parents.hasNext()) { - Group currentParent = parents.next(); - // Is added group among my parents? - if (currentParent.getID().equals(groupToBeAdded.getID())) { - throw new ActionExecutionException(MessagingUtils.cyclicRelationsForbidden( - currentGroup.getID(), groupToBeAdded.getID())); - } - // ... and are its children among my parents? - for (Iterator children = groupToBeAdded.getMembers(); children.hasNext(); ) { - Authorizable currentChild = children.next(); - if (currentParent.getID().equals(currentChild.getID())) { - throw new ActionExecutionException(MessagingUtils.cyclicRelationsForbidden( - currentChild.getID(), groupToBeAdded.getID())); - } - } - } - } catch (RepositoryException e) { - throw new ActionExecutionException(MessagingUtils.createMessage(e)); - } - } - - public static void logErrors(List errors, ActionResult actionResult) { - for (String error : errors) { - actionResult.logError(error); - } - } + public static void logErrors(List errors, ActionResult actionResult) { + for (String error : errors) { + actionResult.logError(error); + } + } } diff --git a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/MessagingUtils.java b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/MessagingUtils.java index 24740dba4..07c9ee484 100644 --- a/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/MessagingUtils.java +++ b/app/aem/actions.checks/src/main/java/com/cognifide/apm/checks/utils/MessagingUtils.java @@ -19,13 +19,13 @@ */ package com.cognifide.apm.checks.utils; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.commons.lang.StringUtils; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class MessagingUtils { - private MessagingUtils() { - } - public static String createMessage(Exception e) { return StringUtils.isBlank(e.getMessage()) ? "Internal error: " + e.getClass() : e.getMessage(); } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/ActionGroup.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/ActionGroup.java index 7bc14b991..8f4970558 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/ActionGroup.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/ActionGroup.java @@ -20,7 +20,11 @@ package com.cognifide.apm.main.actions; -public class ActionGroup { +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ActionGroup { public static final String CORE = "core"; } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/CommonFlags.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/CommonFlags.java index 75e5fcfd4..c454c0eec 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/CommonFlags.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/CommonFlags.java @@ -20,6 +20,10 @@ package com.cognifide.apm.main.actions; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class CommonFlags { public static final String IF_EXISTS = "IF-EXISTS"; diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addchildren/AddChildren.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addchildren/AddChildren.java index ebceb976f..96ce9189e 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addchildren/AddChildren.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addchildren/AddChildren.java @@ -28,16 +28,14 @@ import java.util.ArrayList; import java.util.List; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class AddChildren implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(AddChildren.class); - private final List authorizableIds; public AddChildren(final List authorizableIds) { @@ -60,12 +58,9 @@ private ActionResult process(Context context, boolean execute) { try { group = context.getCurrentGroup(); actionResult.setAuthorizable(group.getID()); - LOGGER.info(String.format("Adding authorizables %s to group with id = %s", - StringUtils.join(authorizableIds, ", "), group.getID())); - } catch (ActionExecutionException e) { - actionResult.logError(MessagingUtils.createMessage(e)); - return actionResult; - } catch (RepositoryException e) { + log.info("Adding authorizables {} to group with id = {}", + StringUtils.join(authorizableIds, ", "), group.getID()); + } catch (ActionExecutionException | RepositoryException e) { actionResult.logError(MessagingUtils.createMessage(e)); return actionResult; } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addparents/AddParents.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addparents/AddParents.java index acd500331..393607122 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addparents/AddParents.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/addparents/AddParents.java @@ -28,15 +28,13 @@ import java.util.ArrayList; import java.util.List; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class AddParents implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(AddParents.class); - private final List groupIds; public AddParents(final List groupIds) { @@ -72,8 +70,8 @@ private ActionResult process(final Context context, boolean execute) { if (authorizable.isGroup()) { ActionUtils.checkCyclicRelations(group, (Group) authorizable); } - LOGGER.info(String.format("Adding Authorizable with id = %s to group with id = %s", - authorizable.getID(), group.getID())); + log.info("Adding Authorizable with id = {} to group with id = {}", + authorizable.getID(), group.getID()); if (execute) { group.addMember(authorizable); diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/allow/Allow.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/allow/Allow.java index 1a09ee32c..e1f5f4643 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/allow/Allow.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/allow/Allow.java @@ -31,15 +31,13 @@ import java.util.List; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.security.user.Authorizable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class Allow implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(Allow.class); - private final String path; private final List permissions; @@ -49,8 +47,8 @@ public class Allow implements Action { private final boolean ignoreNonExistingPaths; public Allow(String path, List permissions, - String glob, List ntNames, - List itemNames, boolean ignoreNonExistingPaths) { + String glob, List ntNames, + List itemNames, boolean ignoreNonExistingPaths) { this.path = path; this.permissions = permissions; this.restrictions = new Restrictions(glob, ntNames, itemNames); @@ -75,8 +73,8 @@ private ActionResult process(final Context context, boolean simulate) { context.getSession().getNode(path); final PermissionActionHelper permissionActionHelper = new PermissionActionHelper( context.getValueFactory(), path, permissions, restrictions); - LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", - permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions)); + log.info("Adding permissions {} for authorizable with id = {} for path = {} {}", + permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions); if (simulate) { permissionActionHelper.checkPermissions(context.getAccessControlManager()); } else { diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/Purge.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/Purge.java index ab2a88322..0b5b41678 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/Purge.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/Purge.java @@ -29,17 +29,15 @@ import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class Purge implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(Purge.class); - private static final String PERMISSION_STORE_PATH = "/jcr:system/rep:permissionStore/crx.default/"; private final String path; @@ -63,8 +61,8 @@ private ActionResult process(final Context context, boolean execute) { try { Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); - LOGGER.info(String.format("Purging privileges for authorizable with id = %s under path = %s", - authorizable.getID(), path)); + log.info("Purging privileges for authorizable with id = {} under path = {}", + authorizable.getID(), path); if (execute) { purge(context, actionResult); } @@ -109,10 +107,10 @@ private void copyErrorMessages(ActionResult from, ActionResult to) { private NodeIterator getPermissions(Context context) throws ActionExecutionException, RepositoryException { JackrabbitSession session = context.getSession(); - String path = PERMISSION_STORE_PATH + context.getCurrentAuthorizable().getID(); + String authorizablePath = PERMISSION_STORE_PATH + context.getCurrentAuthorizable().getID(); NodeIterator result = null; - if (session.nodeExists(path)) { - Node node = session.getNode(path); + if (session.nodeExists(authorizablePath)) { + Node node = session.getNode(authorizablePath); result = node.getNodes(); } return result; diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/RemoveAll.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/RemoveAll.java index 908be046e..6d354e739 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/RemoveAll.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/clearpermissions/RemoveAll.java @@ -29,15 +29,13 @@ import javax.jcr.RepositoryException; import javax.jcr.security.AccessControlEntry; import javax.jcr.security.AccessControlManager; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.api.security.user.Authorizable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class RemoveAll implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(RemoveAll.class); - private final String path; public RemoveAll(final String path) { @@ -59,8 +57,8 @@ private ActionResult process(final Context context, boolean execute) { try { Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); - LOGGER.info(String.format("Removing all priveleges for authorizable with id = %s on path = %s", - authorizable.getID(), path)); + log.info("Removing all priveleges for authorizable with id = {} on path = {}", + authorizable.getID(), path); if (execute) { removeAll(context, authorizable); } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizable.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizable.java index e68749528..135128389 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizable.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizable.java @@ -25,15 +25,13 @@ import com.cognifide.apm.api.status.Status; import com.cognifide.apm.main.utils.MessagingUtils; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class CreateAuthorizable implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(CreateAuthorizable.class); - private final String path; private final String id; @@ -45,7 +43,7 @@ public class CreateAuthorizable implements Action { private final CreateAuthorizableStrategy createStrategy; public CreateAuthorizable(final String id, final String password, final String path, - final Boolean ignoreIfExists, final CreateAuthorizableStrategy createStrategy) { + final Boolean ignoreIfExists, final CreateAuthorizableStrategy createStrategy) { this.id = id; this.password = password; this.path = path; @@ -67,7 +65,7 @@ public ActionResult process(final Context context, boolean simulate) { ActionResult actionResult = context.createActionResult(); try { Authorizable authorizable = context.getAuthorizableManager().getAuthorizableIfExists(id); - LOGGER.info("Creating authorizable with id = " + id); + log.info("Creating authorizable with id = {}", id); if (authorizable != null) { logMessage(actionResult, authorizable); } else { diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizableStrategy.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizableStrategy.java index 81f720e54..4095a3557 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizableStrategy.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/createauthorizable/CreateAuthorizableStrategy.java @@ -43,7 +43,7 @@ public Group create(final String id, final String password, final String path, f group = context.getAuthorizableManager().createMockGroup(id); } - actionResult.logMessage("Group with id: " + id + " created"); + actionResult.logMessage(String.format("Group with id: %s created", id)); return group; } }, @@ -63,7 +63,7 @@ public User create(String id, String password, String path, Context context, user = context.getAuthorizableManager().createMockUser(id); } - actionResult.logMessage("User with id: " + id + " created"); + actionResult.logMessage(String.format("User with id: %s created", id)); return user; } }, @@ -79,7 +79,7 @@ public User create(String id, String password, String path, Context context, user = context.getAuthorizableManager().createMockUser(id); } - actionResult.logMessage("System user with id: " + id + " created"); + actionResult.logMessage(String.format("System user with id: %s created", id)); return user; } }; diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deletegroup/DeleteGroup.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deletegroup/DeleteGroup.java index b686d46a0..4adfa5d1d 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deletegroup/DeleteGroup.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deletegroup/DeleteGroup.java @@ -27,15 +27,13 @@ import java.util.ArrayList; import java.util.List; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.security.user.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class DeleteGroup implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(DeleteGroup.class); - private final List ids; public DeleteGroup(final List ids) { @@ -56,7 +54,7 @@ private ActionResult process(final Context context, boolean execute) { ActionResult actionResult = context.createActionResult(); List errors = new ArrayList<>(); - LOGGER.info(String.format("Removing groups with ids = %s", StringUtils.join(ids, ", "))); + log.info("Removing groups with ids = {}", StringUtils.join(ids, ", ")); for (String id : ids) { try { Group group = context.getAuthorizableManager().getGroupIfExists(id); diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/DeleteUserMapper.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/DeleteUserMapper.java index 8c790050f..dbf84a6e3 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/DeleteUserMapper.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/DeleteUserMapper.java @@ -69,7 +69,7 @@ public Action create( @Required(value = "userIds", description = "users' ids e.g.: ['author']") List ids, @Flag(value = CLEAR_PERMISSIONS, description = CLEAR_PERMISSIONS_DESC) boolean clearPermissions) { if (clearPermissions) { - List actions = ids.stream().map(id -> new DestroyUser(id)).collect(Collectors.toList()); + List actions = ids.stream().map(DestroyUser::new).collect(Collectors.toList()); return new CompositeAction(actions); } else { return new RemoveUser(ids); diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/RemoveUser.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/RemoveUser.java index a3706ce5c..445984bbe 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/RemoveUser.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deleteuser/RemoveUser.java @@ -27,15 +27,13 @@ import java.util.ArrayList; import java.util.List; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.security.user.User; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class RemoveUser implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(RemoveUser.class); - private final List ids; public RemoveUser(final List ids) { @@ -55,7 +53,7 @@ public ActionResult execute(final Context context) { private ActionResult process(final Context context, boolean execute) { ActionResult actionResult = context.createActionResult(); List errors = new ArrayList<>(); - LOGGER.info(String.format("Removing users with ids = %s", StringUtils.join(ids, ", "))); + log.info("Removing users with ids = {}", StringUtils.join(ids, ", ")); for (String id : ids) { try { User user = context.getAuthorizableManager().getUserIfExists(id); diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deny/Deny.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deny/Deny.java index a68e1a331..a9cca60ed 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deny/Deny.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/deny/Deny.java @@ -31,15 +31,13 @@ import java.util.List; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.security.user.Authorizable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class Deny implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(Deny.class); - private final String path; private final List permissions; @@ -49,8 +47,8 @@ public class Deny implements Action { private final boolean ignoreNonExistingPaths; public Deny(final String path, final List permissions, - final String glob, List ntNames, final List itemNames, - final boolean ignoreNonExistingPaths) { + final String glob, List ntNames, final List itemNames, + final boolean ignoreNonExistingPaths) { this.path = path; this.permissions = permissions; this.restrictions = new Restrictions(glob, ntNames, itemNames); @@ -75,8 +73,8 @@ private ActionResult process(final Context context, boolean simulate) { context.getSession().getNode(path); final PermissionActionHelper permissionActionHelper = new PermissionActionHelper( context.getValueFactory(), path, permissions, restrictions); - LOGGER.info(String.format("Denying permissions %s for authorizable with id = %s for path = %s %s", - permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions)); + log.info("Denying permissions {} for authorizable with id = {} for path = {} {}", + permissions.toString(), context.getCurrentAuthorizable().getID(), path, restrictions); if (simulate) { permissionActionHelper.checkPermissions(context.getAccessControlManager()); } else { diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildren/RemoveChildren.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildren/RemoveChildren.java index 82b17a9eb..e495d97da 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildren/RemoveChildren.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildren/RemoveChildren.java @@ -27,16 +27,14 @@ import java.util.ArrayList; import java.util.List; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class RemoveChildren implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(RemoveChildren.class); - private final List authorizableIds; public RemoveChildren(final List authorizableIds) { @@ -55,16 +53,13 @@ public ActionResult execute(final Context context) { private ActionResult process(final Context context, boolean execute) { ActionResult actionResult = context.createActionResult(); - Group group = null; + Group group; try { group = context.getCurrentGroup(); actionResult.setAuthorizable(group.getID()); - LOGGER.info(String.format("Removing authorizables %s from group with id = %s", - StringUtils.join(authorizableIds, ", "), group.getID())); - } catch (ActionExecutionException e) { - actionResult.logError(MessagingUtils.createMessage(e)); - return actionResult; - } catch (RepositoryException e) { + log.info("Removing authorizables {} from group with id = {}", + StringUtils.join(authorizableIds, ", "), group.getID()); + } catch (ActionExecutionException | RepositoryException e) { actionResult.logError(MessagingUtils.createMessage(e)); return actionResult; } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildrengroups/ClearFromGroupDetacher.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildrengroups/ClearFromGroupDetacher.java index bcc4ef92b..cd2ff9e7e 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildrengroups/ClearFromGroupDetacher.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removechildrengroups/ClearFromGroupDetacher.java @@ -25,15 +25,13 @@ import com.cognifide.apm.main.utils.MessagingUtils; import java.util.Iterator; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class ClearFromGroupDetacher { - static final Logger LOGGER = LoggerFactory.getLogger(ClearFromGroupDetacher.class); - private final Context context; private final boolean simulate; @@ -51,7 +49,7 @@ public ActionResult detachMembersFromGroup() { if (authorizable.isGroup()) { final Group group = context.getCurrentGroup(); - LOGGER.info(String.format("Removing all members of group with id = %s", group.getID())); + log.info("Removing all members of group with id = {}", group.getID()); Iterator groupMembers = getGroupMembers(actionResult, group); detachAllMembers(actionResult, group, groupMembers); @@ -71,8 +69,8 @@ public ActionResult detachAuthorizableFromParents() { Authorizable currentAuthorizable = context.getCurrentAuthorizable(); Iterator groups = getGroupParents(actionResult, currentAuthorizable); - LOGGER.info(String.format("Removing all memberships of authorizable with id = %s", - currentAuthorizable.getID())); + log.info("Removing all memberships of authorizable with id = {}", + currentAuthorizable.getID()); detachFromParents(actionResult, currentAuthorizable, groups); } catch (RepositoryException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); @@ -81,7 +79,7 @@ public ActionResult detachAuthorizableFromParents() { } private void detachFromParents(final ActionResult actionResult, final Authorizable authorizable, - Iterator groups) throws RepositoryException { + Iterator groups) throws RepositoryException { while (groups.hasNext()) { Group currentGroup = groups.next(); if (currentGroup.isGroup()) { @@ -106,7 +104,7 @@ private Iterator getGroupParents(final ActionResult actionResult, final A } private void detachAllMembers(final ActionResult actionResult, final Group group, - Iterator groupMembers) throws RepositoryException { + Iterator groupMembers) throws RepositoryException { while (groupMembers.hasNext()) { Authorizable currentMember = groupMembers.next(); if (currentMember.isGroup()) { diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeparents/RemoveParents.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeparents/RemoveParents.java index 698a159ad..c4e45d063 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeparents/RemoveParents.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeparents/RemoveParents.java @@ -27,15 +27,13 @@ import java.util.ArrayList; import java.util.List; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class RemoveParents implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(RemoveParents.class); - private final List groupIds; public RemoveParents(final List groupIds) { @@ -59,13 +57,8 @@ public ActionResult process(final Context context, boolean execute) { try { authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); - LOGGER.info( - String.format("Removing authorizable with id = %s from groups %s", authorizable.getID(), - groupIds)); - } catch (ActionExecutionException e) { - actionResult.logError(MessagingUtils.createMessage(e)); - return actionResult; - } catch (RepositoryException e) { + log.info("Removing authorizable with id = {} from groups {}", authorizable.getID(), groupIds); + } catch (ActionExecutionException | RepositoryException e) { actionResult.logError(MessagingUtils.createMessage(e)); return actionResult; } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeproperty/RemoveProperty.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeproperty/RemoveProperty.java index 17cd65080..76215e33f 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeproperty/RemoveProperty.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/removeproperty/RemoveProperty.java @@ -25,14 +25,12 @@ import com.cognifide.apm.api.exceptions.ActionExecutionException; import com.cognifide.apm.main.utils.MessagingUtils; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.user.Authorizable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class RemoveProperty implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(RemoveProperty.class); - private final String nameProperty; public RemoveProperty(final String nameProperty) { @@ -55,8 +53,8 @@ private ActionResult process(final Context context, boolean simulate) { try { Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); - LOGGER.info(String.format("Removing property %s from authorizable with id = %s", nameProperty, - authorizable.getID())); + log.info("Removing property {} from authorizable with id = {}", + nameProperty, authorizable.getID()); if (!simulate) { authorizable.removeProperty(nameProperty); } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setpassword/SetPassword.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setpassword/SetPassword.java index 7c4c613a3..4a840b71a 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setpassword/SetPassword.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setpassword/SetPassword.java @@ -25,14 +25,12 @@ import com.cognifide.apm.api.exceptions.ActionExecutionException; import com.cognifide.apm.main.utils.MessagingUtils; import javax.jcr.RepositoryException; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.user.User; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class SetPassword implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(SetPassword.class); - private final String password; public SetPassword(final String password) { @@ -54,7 +52,7 @@ private ActionResult process(final Context context, boolean execute) { try { User user = context.getCurrentUser(); actionResult.setAuthorizable(user.getID()); - LOGGER.info(String.format("Setting password for user with id = %s", user.getID())); + log.info("Setting password for user with id = {}", user.getID()); if (execute) { user.changePassword(password); } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setproperty/SetProperty.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setproperty/SetProperty.java index 2c6dd7eb8..a7a53c662 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setproperty/SetProperty.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/actions/setproperty/SetProperty.java @@ -26,14 +26,12 @@ import com.cognifide.apm.main.utils.MessagingUtils; import javax.jcr.RepositoryException; import javax.jcr.Value; +import lombok.extern.slf4j.Slf4j; import org.apache.jackrabbit.api.security.user.Authorizable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +@Slf4j public class SetProperty implements Action { - private static final Logger LOGGER = LoggerFactory.getLogger(SetProperty.class); - private final String nameProperty; private final String valueProperty; @@ -59,8 +57,8 @@ private ActionResult process(final Context context, boolean simulate) { try { Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); - LOGGER.info(String.format("Setting property %s for authorizable with id = %s", nameProperty, - authorizable.getID())); + log.info("Setting property {} for authorizable with id = {}", + nameProperty, authorizable.getID()); final Value value = context.getValueFactory().createValue(valueProperty); if (!simulate) { diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/utils/JackrabbitAccessControlListUtil.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/utils/JackrabbitAccessControlListUtil.java index 075713380..b01a2f1e7 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/utils/JackrabbitAccessControlListUtil.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/utils/JackrabbitAccessControlListUtil.java @@ -24,15 +24,15 @@ import javax.jcr.security.AccessControlManager; import javax.jcr.security.AccessControlPolicy; import javax.jcr.security.AccessControlPolicyIterator; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class JackrabbitAccessControlListUtil { - private JackrabbitAccessControlListUtil() { - } - public static JackrabbitAccessControlList getModifiableAcl(final AccessControlManager accessManager, - final String path) throws RepositoryException { + final String path) throws RepositoryException { final JackrabbitAccessControlList acl = getAccessControlList(accessManager, path); if (null != acl) { return acl; diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/ActionUtils.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/ActionUtils.java index 50a8e624c..1f6b7e4e5 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/ActionUtils.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/ActionUtils.java @@ -24,16 +24,16 @@ import java.util.Iterator; import java.util.List; import javax.jcr.RepositoryException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ActionUtils { public static final String ASSERTION_FAILED_MSG = "Assertion failed"; - private ActionUtils() { - } - /** * Adding group to another group may result in cyclic relation. Let current group be the group where we * want to add current authorizable to. If current authorizable contains group such that current group diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/MessagingUtils.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/MessagingUtils.java index 4761b5263..b1e7cbf64 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/MessagingUtils.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/MessagingUtils.java @@ -23,13 +23,13 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.commons.lang.StringUtils; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class MessagingUtils { - private MessagingUtils() { - } - public static String createMessage(Exception e) { return StringUtils.isBlank(e.getMessage()) ? "Internal error: " + e.getClass() : e.getMessage(); } diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/actions/Message.java b/app/aem/api/src/main/java/com/cognifide/apm/api/actions/Message.java index dbc78b2fa..ea402e96e 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/actions/Message.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/actions/Message.java @@ -19,6 +19,14 @@ */ package com.cognifide.apm.api.actions; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class Message { public static final String ERROR = "error"; @@ -27,21 +35,4 @@ public final class Message { private String type; - public Message(String text, String type) { - this.text = text; - this.type = type; - } - - // Gson library needs this - private Message() { - } - - public String getText() { - return text; - } - - public String getType() { - return type; - } - } diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java index 2b879befe..2cbf0ede5 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java @@ -108,22 +108,22 @@ public String getReplicatedBy() { @Override public void setValid(boolean flag) { - + // intentionally empty } @Override public void setLastExecuted(Date date) { - + // intentionally empty } @Override public void setPublishRun(boolean flag) { - + // intentionally empty } @Override public void setReplicatedBy(String userId) { - + // intentionally empty } @Override diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/services/ExecutionMode.java b/app/aem/api/src/main/java/com/cognifide/apm/api/services/ExecutionMode.java index b2b4b148b..9afeaec50 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/services/ExecutionMode.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/services/ExecutionMode.java @@ -70,5 +70,5 @@ public boolean isRun() { return false; } - abstract public String getName(); + public abstract String getName(); } diff --git a/app/aem/common.gradle.kts b/app/aem/common.gradle.kts index 96faa75b1..f31ccd692 100644 --- a/app/aem/common.gradle.kts +++ b/app/aem/common.gradle.kts @@ -49,5 +49,8 @@ plugins.withId("com.cognifide.aem.bundle") { "implementation"("javax.servlet:jsp-api:2.0") "implementation"("javax.servlet:servlet-api:2.4") "implementation"("org.slf4j:slf4j-log4j12:1.7.7") + + "compileOnly"("org.projectlombok:lombok:1.18.8") + "annotationProcessor"("org.projectlombok:lombok:1.18.8") } } \ No newline at end of file diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/Apm.java b/app/aem/core/src/main/java/com/cognifide/apm/core/Apm.java index 732586df8..e15a181ba 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/Apm.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/Apm.java @@ -19,10 +19,11 @@ */ package com.cognifide.apm.core; -public final class Apm { +import lombok.AccessLevel; +import lombok.NoArgsConstructor; - private Apm() { - } +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class Apm { public static final String FILE_EXT = ".apm"; } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionMapperRegistryImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionMapperRegistryImpl.java index d4e674877..b4e6f1b66 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionMapperRegistryImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionMapperRegistryImpl.java @@ -34,13 +34,12 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.scribe.utils.Preconditions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Component( immediate = true, @@ -50,10 +49,9 @@ Property.VENDOR } ) +@Slf4j public class ActionMapperRegistryImpl implements RegistryChangedListener, ActionMapperRegistry { - private static final Logger LOG = LoggerFactory.getLogger(ActionMapperRegistryImpl.class); - private static final String BUNDLE_HEADER = "APM-Actions"; private AnnotatedClassRegistry registry; @@ -101,12 +99,12 @@ private static Map createActionMappers(List> MapperDescriptor mapperDescriptor = mapperDescriptorFactory.create(clazz); mappers.put(mapperDescriptor.getName(), mapperDescriptor); } catch (InvalidActionMapperException e) { - LOG.warn("Cannot register ActionMapper of class " + clazz.getName(), e); + log.warn("Cannot register ActionMapper of class " + clazz.getName(), e); } } - if (LOG.isDebugEnabled()) { - LOG.debug("Created {} action mappers from {} classes", mappers.size(), classes.size()); + if (log.isDebugEnabled()) { + log.debug("Created {} action mappers from {} classes", mappers.size(), classes.size()); } return mappers; } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java index d74489e97..ff81a22c8 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java @@ -127,7 +127,7 @@ private static String checkCommonAuthorizable(List actionResults) for (ActionResult actionResult : actionResults) { String current = actionResult.getAuthorizable(); if (current != null && !StringUtils.equals(current, pattern)) { - String error = format("Cannot create CompositeActionResult, mismatch of authorizables. Found: {} Expected: {}", + String error = format("Cannot create CompositeActionResult, mismatch of authorizables. Found: %s Expected: %s", actionResult.getAuthorizable(), pattern); throw new IllegalArgumentException(error); } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/AbstractActionExecutor.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/AbstractActionExecutor.java index ad000a7cd..582cc1e8a 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/AbstractActionExecutor.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/AbstractActionExecutor.java @@ -31,7 +31,7 @@ public abstract class AbstractActionExecutor implements ActionExecutor { protected final Context context; - public AbstractActionExecutor(Context context, ActionFactory actionFactory) { + protected AbstractActionExecutor(Context context, ActionFactory actionFactory) { this.context = context; this.actionFactory = actionFactory; } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/ActionExecutorFactory.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/ActionExecutorFactory.java index ca9014e63..919612fc9 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/ActionExecutorFactory.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/executor/ActionExecutorFactory.java @@ -22,7 +22,10 @@ import com.cognifide.apm.api.actions.Context; import com.cognifide.apm.api.services.ExecutionMode; import com.cognifide.apm.core.actions.ActionFactory; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ActionExecutorFactory { public static ActionExecutor create(ExecutionMode mode, Context context, ActionFactory actionFactory) { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/AnnotatedClassRegistry.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/AnnotatedClassRegistry.java index e3c28b041..860b5daea 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/AnnotatedClassRegistry.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/AnnotatedClassRegistry.java @@ -27,23 +27,21 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import lombok.extern.slf4j.Slf4j; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.util.tracker.BundleTracker; import org.osgi.util.tracker.BundleTrackerCustomizer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Aggregator for classes with specified annotation

When bundle is state is changed (added, removed, * modified), then it is executed class scanner which looks for classes with prefixes specified in bundle * header */ +@Slf4j public class AnnotatedClassRegistry { - private static final Logger LOG = LoggerFactory.getLogger(AnnotatedClassRegistry.class); - private final BundleTracker tracker; private final Map>> classes = new ConcurrentHashMap<>(); @@ -90,7 +88,7 @@ public void addChangeListener(RegistryChangedListener changeListener) { this.listeners.add(changeListener); } - public List> getClasses() { + public List> getFlattenedClasses() { List> flattened = new ArrayList<>(); for (Map.Entry>> entry : classes.entrySet()) { flattened.addAll(entry.getValue()); @@ -102,28 +100,28 @@ public List> getClasses() { private void registerClasses(Bundle bundle) { final List> scanned = new ClassScanner(bundle, bundleContext) .findClasses(bundleHeader, annotationClass); - if (scanned.size() > 0) { + if (!scanned.isEmpty()) { classes.put(bundle.getBundleId(), scanned); notifyChangeListeners(); } - if (LOG.isDebugEnabled()) { - LOG.debug("Adding classes ({}) from bundle: {}", scanned.size(), bundle.getSymbolicName()); + if (log.isDebugEnabled()) { + log.debug("Adding classes ({}) from bundle: {}", scanned.size(), bundle.getSymbolicName()); } } private void unregisterClasses(Bundle bundle) { final List> registered = classes.get(bundle.getBundleId()); - if (LOG.isDebugEnabled()) { - LOG.debug("Removing classes ({}) from bundle: {}", registered.size(), bundle.getSymbolicName()); + if (log.isDebugEnabled()) { + log.debug("Removing classes ({}) from bundle: {}", registered.size(), bundle.getSymbolicName()); } classes.remove(bundle.getBundleId()); notifyChangeListeners(); } private void notifyChangeListeners() { - List> classes = getClasses(); + List> flattenedClasses = getFlattenedClasses(); for (RegistryChangedListener listener : listeners) { - listener.registryChanged(classes); + listener.registryChanged(flattenedClasses); } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/BundleUtils.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/BundleUtils.java index 417dcd77d..96539f9bb 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/BundleUtils.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/BundleUtils.java @@ -19,10 +19,13 @@ */ package com.cognifide.apm.core.actions.scanner; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class BundleUtils { public static boolean isFragment(Bundle bundle) { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/ClassScanner.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/ClassScanner.java index ff239bec2..5efd89c51 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/ClassScanner.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/scanner/ClassScanner.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,112 +26,110 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.sling.commons.osgi.PropertiesUtil; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Utility class for searching classes in specified bundle * If bundle context is provided it can also support fragment bundles */ +@Slf4j public class ClassScanner { - private final Bundle bundle; - - private final BundleContext context; - - public ClassScanner(Bundle bundle) { - this(bundle, null); - } - - public ClassScanner(Bundle bundle, BundleContext context) { - this.bundle = bundle; - this.context = context; - } - - private static final Logger LOG = LoggerFactory.getLogger(ClassScanner.class); - - public List> findClasses(String packageName) { - @SuppressWarnings("unchecked") final Enumeration classUrls = bundle - .findEntries(packageName.replace('.', '/'), "*.class", true); - final String bundleName = bundle.getSymbolicName(); - final ArrayList> classes = new ArrayList<>(); - - if (classUrls == null) { - LOG.warn("No classes found in bundle: {}", bundleName); - } else { - while (classUrls.hasMoreElements()) { - final URL url = classUrls.nextElement(); - final String className = toClassName(url); - - try { - if (BundleUtils.isFragment(bundle)) { - if (context == null) { - LOG.warn("Cannot load class from fragment bundle {} if context is unspecified", - bundleName); - } - - final Bundle hostBundle = BundleUtils.getHostBundle(context, bundle); - - if (hostBundle == null) { - LOG.warn("Cannot find host bundle for {}", bundleName); - } else { - classes.add(hostBundle.loadClass(className)); - } - } else { - classes.add(bundle.loadClass(className)); - } - } catch (ClassNotFoundException e) { - LOG.warn("Unable to load class", e); - } - } - } - - return classes; - } - - public List> findClasses(List packages, Class annotation) { - ArrayList> classes = new ArrayList<>(); - - for (String packageName : packages) { - for (Class clazz : findClasses(packageName)) { - if (clazz != null && (annotation == null || clazz.isAnnotationPresent(annotation))) { - classes.add(clazz); - } - } - } - - return classes; - } - - public List> findClasses(String header, Class annotation) { - return findClasses(parsePackagesFromHeader(header), annotation); - } - - public List> findClasses(Class annotation) { - return findClasses(Collections.singletonList("/"), annotation); - } - - public List> findClasses() { - return findClasses(Collections.singletonList("/"), null); - } - - private String toClassName(URL url) { - final String f = url.getFile(); - final String cn = f.substring(1, f.length() - ".class".length()); - return cn.replace('/', '.'); - } - - private List parsePackagesFromHeader(String header) { - String values = PropertiesUtil.toString(bundle.getHeaders().get(header), null); - if (values == null) { - return Collections.emptyList(); - } - String[] packages = StringUtils.deleteWhitespace(values).split(";"); - - return Arrays.asList(packages); - } + private final Bundle bundle; + + private final BundleContext context; + + public ClassScanner(Bundle bundle) { + this(bundle, null); + } + + public ClassScanner(Bundle bundle, BundleContext context) { + this.bundle = bundle; + this.context = context; + } + + public List> findClasses(String packageName) { + @SuppressWarnings("unchecked") final Enumeration classUrls = bundle + .findEntries(packageName.replace('.', '/'), "*.class", true); + final String bundleName = bundle.getSymbolicName(); + if (classUrls == null) { + log.warn("No classes found in bundle: {}", bundleName); + return Collections.emptyList(); + } + + final ArrayList> classes = new ArrayList<>(); + while (classUrls.hasMoreElements()) { + final URL url = classUrls.nextElement(); + final String className = toClassName(url); + + try { + if (BundleUtils.isFragment(bundle)) { + if (context == null) { + log.warn("Cannot load class from fragment bundle {} if context is unspecified", + bundleName); + } + + final Bundle hostBundle = BundleUtils.getHostBundle(context, bundle); + + if (hostBundle == null) { + log.warn("Cannot find host bundle for {}", bundleName); + } else { + classes.add(hostBundle.loadClass(className)); + } + } else { + classes.add(bundle.loadClass(className)); + } + } catch (ClassNotFoundException e) { + log.warn("Unable to load class", e); + } + } + + return classes; + } + + public List> findClasses(List packages, Class annotation) { + ArrayList> classes = new ArrayList<>(); + + for (String packageName : packages) { + for (Class clazz : findClasses(packageName)) { + if (clazz != null && (annotation == null || clazz.isAnnotationPresent(annotation))) { + classes.add(clazz); + } + } + } + + return classes; + } + + public List> findClasses(String header, Class annotation) { + return findClasses(parsePackagesFromHeader(header), annotation); + } + + public List> findClasses(Class annotation) { + return findClasses(Collections.singletonList("/"), annotation); + } + + public List> findClasses() { + return findClasses(Collections.singletonList("/"), null); + } + + private String toClassName(URL url) { + final String f = url.getFile(); + final String cn = f.substring(1, f.length() - ".class".length()); + return cn.replace('/', '.'); + } + + private List parsePackagesFromHeader(String header) { + String values = PropertiesUtil.toString(bundle.getHeaders().get(header), null); + if (values == null) { + return Collections.emptyList(); + } + String[] packages = StringUtils.deleteWhitespace(values).split(";"); + + return Arrays.asList(packages); + } } \ No newline at end of file diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/HistoryListServlet.java b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/HistoryListServlet.java index 0c6efb181..a43bab186 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/HistoryListServlet.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/HistoryListServlet.java @@ -31,6 +31,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -40,7 +41,7 @@ service = Servlet.class, property = { Property.PATH + "/bin/cqsm/history", - Property.METHOD + "GET", + Property.METHOD + HttpConstants.METHOD_GET, Property.DESCRIPTION + "CQSM History List Servlet", Property.VENDOR } @@ -48,7 +49,7 @@ public class HistoryListServlet extends SlingAllMethodsServlet { @Reference - private History history; + private transient History history; @Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) @@ -82,17 +83,14 @@ public boolean evaluate(Object object) { String value; switch (filterType) { case FILTER_AUTHOR: - case FILTER_PUBLISH: { + case FILTER_PUBLISH: value = executionModel.getInstanceType(); - } - break; - case FILTER_AUTOMATIC_RUN: { + break; + case FILTER_AUTOMATIC_RUN: value = executionModel.getExecutor(); - } - break; - default: { + break; + default: value = null; - } } return filterType.equals(value); } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptDownloadServlet.java b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptDownloadServlet.java index ddbae8fa9..23456488b 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptDownloadServlet.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptDownloadServlet.java @@ -20,38 +20,39 @@ package com.cognifide.apm.core.endpoints; import com.cognifide.apm.core.Property; +import com.day.cq.commons.jcr.JcrConstants; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.servlet.Servlet; import javax.servlet.ServletException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.osgi.service.component.annotations.Component; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Component( immediate = true, service = Servlet.class, property = { Property.PATH + "/bin/cqsm/fileDownload", - Property.METHOD + "GET", + Property.METHOD + HttpConstants.METHOD_GET, Property.DESCRIPTION + "CQSM File Download Servlet", Property.VENDOR } ) +@Slf4j public class ScriptDownloadServlet extends SlingSafeMethodsServlet { - private static final Logger LOGGER = LoggerFactory.getLogger(ScriptDownloadServlet.class); - private static final int BYTES_DOWNLOAD = 1024; @Override @@ -62,21 +63,21 @@ protected void doGet(final SlingHttpServletRequest request, final SlingHttpServl String mode = request.getParameter("mode"); + final ResourceResolver resourceResolver = request.getResourceResolver(); try { - final ResourceResolver resourceResolver = request.getResourceResolver(); final Session session = resourceResolver.adaptTo(Session.class); if (!("view").equals(mode)) { response.setContentType("application/octet-stream"); // Your content type response.setHeader("Content-Disposition", - "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); + "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString())); } - String path = StringUtils.replace(filePath, "_jcr_content", "jcr:content"); + String path = StringUtils.replace(filePath, "_jcr_content", JcrConstants.JCR_CONTENT); - Node jcrContent = session.getNode(path + "/jcr:content"); + Node jcrContent = session.getNode(path + "/" + JcrConstants.JCR_CONTENT); - InputStream input = jcrContent.getProperty("jcr:data").getBinary().getStream(); + InputStream input = jcrContent.getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); session.save(); int read; @@ -91,9 +92,8 @@ protected void doGet(final SlingHttpServletRequest request, final SlingHttpServl os.close(); } catch (RepositoryException e) { - LOGGER.error(e.getMessage(), e); + log.error(e.getMessage(), e); response.sendRedirect("/etc/cqsm.html"); - // response.sendError(500); } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptRemoveServlet.java b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptRemoveServlet.java index 2d8d2cf4f..d42978a13 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptRemoveServlet.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptRemoveServlet.java @@ -37,6 +37,7 @@ import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -46,7 +47,7 @@ service = Servlet.class, property = { Property.PATH + "/bin/cqsm/remove", - Property.METHOD + "POST", + Property.METHOD + HttpConstants.METHOD_POST, Property.DESCRIPTION + "CQSM Remove Scripts Servlet", Property.VENDOR } @@ -54,10 +55,10 @@ public class ScriptRemoveServlet extends SlingAllMethodsServlet { @Reference - private ScriptStorage scriptStorage; + private transient ScriptStorage scriptStorage; @Reference - private ScriptFinder scriptFinder; + private transient ScriptFinder scriptFinder; @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) @@ -71,14 +72,14 @@ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse removeAllFiles(resolver, response, all); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - ServletUtils.writeMessage(response, "error", "Invalid arguments specified"); + ServletUtils.writeMessage(response, ServletUtils.ERROR_RESPONSE_TYPE, "Invalid arguments specified"); } } private void removeAllFiles(ResourceResolver resolver, SlingHttpServletResponse response, String all) throws IOException { if (!Boolean.parseBoolean(all)) { - ServletUtils.writeMessage(response, "error", "Remove all scripts is not confirmed"); + ServletUtils.writeMessage(response, ServletUtils.ERROR_RESPONSE_TYPE, "Remove all scripts is not confirmed"); } else { final List paths = new LinkedList<>(); final List