Skip to content

Commit

Permalink
Add functionality to export users in CSV format
Browse files Browse the repository at this point in the history
This format is compatible with
https://helpx.adobe.com/enterprise/using/bulk-upload-users.html#csv-format

Fix Web Console deployment with sling-m-p

This closes #703
This closes #443
This closes #707
  • Loading branch information
kwin committed May 7, 2024
1 parent ba3c803 commit 03b5b06
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* (C) Copyright 2024 Cognizant Netcentric.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package biz.netcentric.cq.tools.actool.helper;

import java.util.Objects;

import javax.jcr.RepositoryException;

/**
* Wraps a {@link RepositoryException} with an unchecked exception.
* This is useful for usage within lambdas.
*
*/
public class UncheckedRepositoryException extends RuntimeException {

private static final long serialVersionUID = 2727436608772501551L;

/**
* Constructs an instance of this class.
*
* @param cause
* the {@code RepositoryException}
*
* @throws NullPointerException
* if the cause is {@code null}
*/
public UncheckedRepositoryException(RepositoryException cause) {
super(Objects.requireNonNull(cause));
}

/**
* Returns the cause of this exception.
*
* @return the {@code RepositoryException} which is the cause of this exception.
*/
@Override
public synchronized RepositoryException getCause() {
return (RepositoryException) super.getCause();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,66 +37,24 @@ public class AcToolTouchUiServlet extends SlingAllMethodsServlet {

private static final Logger LOG = LoggerFactory.getLogger(AcToolTouchUiServlet.class);

@Reference(policyOption = ReferencePolicyOption.GREEDY)
private WebConsoleConfigTracker webConsoleConfigTracker;

@Reference(policyOption = ReferencePolicyOption.GREEDY)
private AcToolUiService acToolUiService;

@Override
protected void doGet(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws ServletException, IOException {

if (StringUtils.isBlank(req.getRequestPathInfo().getSuffix())) {
String targetUrl = req.getResourceResolver().resolve(req.getPathInfo()).getPath() + ".html/" + AcToolUiService.PAGE_NAME;
resp.getWriter().println("<script type=\"text/javascript\">location.href='" + targetUrl + "'</script>");
return;
}

acToolUiService.doGet(req, resp, req.getRequestPathInfo().getResourcePath(), true);

}

@Override
protected void doPost(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws ServletException, IOException {

if (!mayApplyConfig(req.getResourceResolver().adaptTo(User.class))) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "You do not have sufficent permissions to apply the configuration");
return;
}

acToolUiService.doPost(req, resp);
LOG.debug("Applied AC tool config via Touch UI by user {}", req.getUserPrincipal());
}

private boolean mayApplyConfig(User requestUser) {

try {

if (requestUser != null) {
if (StringUtils.equals(requestUser.getID(), "admin")) {
LOG.debug("Admin user is allowed to apply AC Tool");
return true;
}

if (ArrayUtils.contains(webConsoleConfigTracker.getAllowedUsers(), requestUser.getID())) {
LOG.debug("User {} is allowed to apply AC Tool (allowed users: {})", requestUser.getID(), ArrayUtils.toString(webConsoleConfigTracker.getAllowedUsers()));
return true;
}

Iterator<Group> memberOfIt = requestUser.memberOf();

while (memberOfIt.hasNext()) {
Group memberOfGroup = memberOfIt.next();
if (ArrayUtils.contains(webConsoleConfigTracker.getAllowedGroups(), memberOfGroup.getID())) {
LOG.debug("Group {} is allowed to apply AC Tool (allowed groups: {})", memberOfGroup.getID(), ArrayUtils.toString(webConsoleConfigTracker.getAllowedGroups()));
return true;
}
}
}
return false;
} catch (Exception e) {
throw new IllegalStateException("Could not check if user may apply AC Tool configuration: " + e, e);
}
}

}
Loading

0 comments on commit 03b5b06

Please sign in to comment.