use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.
the class ACLPackagerServletImpl method findResources.
/**
* Search the JCR for all rep:ACE nodes to be further filtered by Grant/Deny ACE rep:principalNames.
*
* @param resourceResolver ResourceResolver of initiating user
* @param principalNames Principal Names to filter rep:ACE nodes with; Only rep:ACE nodes with children
* with rep:principalNames in this list will be returned
* @return Set (ordered by path) of rep:ACE coverage who hold permissions for at least one Principal
* enumerated in principleNames
*/
@SuppressWarnings("squid:S3776")
private List<PathFilterSet> findResources(final ResourceResolver resourceResolver, final List<String> principalNames, final List<Pattern> includePatterns) {
boolean isOak = true;
try {
isOak = aemCapabilityHelper.isOak();
} catch (RepositoryException e) {
isOak = true;
}
final Set<Resource> resources = new TreeSet<Resource>(resourceComparator);
final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
String[] queries = CQ5_QUERIES;
if (isOak) {
queries = AEM6_QUERIES;
}
for (final String query : queries) {
final Iterator<Resource> hits = resourceResolver.findResources(query, QUERY_LANG);
while (hits.hasNext()) {
final Resource hit = hits.next();
Resource repPolicy = null;
if (isOak) {
// If Oak, get the parent node since the query is for the Grant/Deny nodes
if (hit.getParent() != null) {
repPolicy = hit.getParent();
}
} else {
// If not Oak, then the rep:ACL is the hit
repPolicy = hit;
}
if (this.isIncluded(repPolicy, includePatterns)) {
log.debug("Included by pattern [ {} ]", repPolicy.getPath());
} else {
continue;
}
final Iterator<Resource> aces = repPolicy.listChildren();
while (aces.hasNext()) {
final Resource ace = aces.next();
final ValueMap props = ace.adaptTo(ValueMap.class);
final String repPrincipalName = props.get("rep:principalName", String.class);
if (principalNames == null || principalNames.isEmpty() || principalNames.contains(repPrincipalName)) {
resources.add(repPolicy);
log.debug("Included by principal [ {} ]", repPolicy.getPath());
break;
}
}
}
}
for (final Resource resource : resources) {
pathFilterSets.add(new PathFilterSet(resource.getPath()));
}
log.debug("Found {} matching rep:policy resources.", pathFilterSets.size());
return pathFilterSets;
}
use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.
the class ACLPackagerServletImpl method doPost.
@Override
public final void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException {
final ResourceResolver resourceResolver = request.getResourceResolver();
final boolean preview = Boolean.parseBoolean(request.getParameter("preview"));
log.trace("Preview mode: {}", preview);
final ValueMap properties = this.getProperties(request);
final String[] principalNames = properties.get(PRINCIPAL_NAMES, new String[] {});
final List<PathFilterSet> packageResources = this.findResources(resourceResolver, Arrays.asList(principalNames), toPatterns(Arrays.asList(properties.get(INCLUDE_PATTERNS, new String[] {}))));
try {
// Add Principals
if (properties.get(INCLUDE_PRINCIPALS, DEFAULT_INCLUDE_PRINCIPALS)) {
packageResources.addAll(this.getPrincipalResources(resourceResolver, principalNames));
}
doPackaging(request, response, preview, properties, packageResources);
} catch (RepositoryException ex) {
log.error(ex.getMessage());
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
} catch (IOException ex) {
log.error(ex.getMessage());
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
} catch (JSONException ex) {
log.error(ex.getMessage());
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
}
}
use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.
the class ACLPackagerServletImpl method getPrincipalResources.
/**
* Gets the resources for the param principals.
*
* @param resourceResolver the ResourceResolver obj to get the principal resources;
* Must have read access to the principal resources.
* @param principalNames the principals to get
* @return a list of PathFilterSets covering the selectes principal names (if they exist)
* @throws RepositoryException
*/
private List<PathFilterSet> getPrincipalResources(final ResourceResolver resourceResolver, final String[] principalNames) throws RepositoryException {
final UserManager userManager = resourceResolver.adaptTo(UserManager.class);
final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
for (final String principalName : principalNames) {
final Authorizable authorizable = userManager.getAuthorizable(principalName);
if (authorizable != null) {
final Resource resource = resourceResolver.getResource(authorizable.getPath());
if (resource != null) {
final PathFilterSet principal = new PathFilterSet(resource.getPath());
// Exclude tokens as they are not vlt installable in AEM6/Oak
principal.addExclude(new DefaultPathFilter(resource.getPath() + "/\\.tokens"));
pathFilterSets.add(principal);
}
}
}
return pathFilterSets;
}
use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.
the class AuthorizablePackagerServletImpl method doPost.
@Override
public final void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException {
final ResourceResolver resourceResolver = request.getResourceResolver();
final boolean preview = Boolean.parseBoolean(request.getParameter("preview"));
log.debug("Preview mode: {}", preview);
final ValueMap properties = this.getProperties(request);
try {
final List<PathFilterSet> paths = this.findPaths(resourceResolver, properties.get("authorizableIds", new String[0]));
doPackaging(request, response, preview, properties, paths);
} catch (RepositoryException ex) {
log.error("Repository error while creating Query Package", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
} catch (IOException ex) {
log.error("IO error while creating Query Package", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
} catch (JSONException ex) {
log.error("JSON error while creating Query Package response", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
}
}
use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.
the class PackageHelperImpl method getPathFilterSetPreviewJSON.
/**
* {@inheritDoc}
*/
public String getPathFilterSetPreviewJSON(final Collection<PathFilterSet> pathFilterSets) throws JSONException {
final JSONObject json = new JSONObject();
json.put(KEY_STATUS, "preview");
json.put(KEY_PATH, "Not applicable (Preview)");
json.put(KEY_FILTER_SETS, new JSONArray());
for (final PathFilterSet pathFilterSet : pathFilterSets) {
final JSONObject tmp = new JSONObject();
tmp.put(KEY_IMPORT_MODE, "Not applicable (Preview)");
tmp.put(KEY_ROOT_PATH, pathFilterSet.getRoot());
json.accumulate("filterSets", tmp);
}
return json.toString();
}
Aggregations