use of org.apache.sling.distribution.common.DistributionException in project sling by apache.
the class PrivilegeDistributionRequestAuthorizationStrategy method checkPermissionForAdd.
private void checkPermissionForAdd(Session session, String[] paths) throws RepositoryException, DistributionException {
AccessControlManager acMgr = session.getAccessControlManager();
Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(jcrPrivilege), acMgr.privilegeFromName(Privilege.JCR_READ) };
for (String path : paths) {
if (!acMgr.hasPrivileges(path, privileges)) {
throw new DistributionException("Not enough privileges");
}
}
}
use of org.apache.sling.distribution.common.DistributionException in project sling by apache.
the class PrivilegeDistributionRequestAuthorizationStrategy method checkPermissionForDelete.
private void checkPermissionForDelete(Session session, String[] paths) throws RepositoryException, DistributionException {
AccessControlManager acMgr = session.getAccessControlManager();
Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(jcrPrivilege), acMgr.privilegeFromName(Privilege.JCR_REMOVE_NODE) };
for (String path : paths) {
String closestParentPath = getClosestParent(session, path);
if (closestParentPath == null || !acMgr.hasPrivileges(closestParentPath, privileges)) {
throw new DistributionException("Not enough privileges");
}
}
}
use of org.apache.sling.distribution.common.DistributionException in project sling by apache.
the class DistributionEventDistributeDistributionTrigger method register.
public void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionException {
// register an event handler on distribution package install (on a certain path) which triggers the chain distribution of that same package
Dictionary<String, Object> properties = new Hashtable<String, Object>();
// TODO : make it possible to configure the type of event handled here, currently 'package-installed' is hardcoded
properties.put(EventConstants.EVENT_TOPIC, DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED);
log.info("handler {} will chain distribute on path '{}'", requestHandler, pathPrefix);
if (bundleContext != null) {
ServiceRegistration triggerPathEventRegistration = bundleContext.registerService(EventHandler.class.getName(), new TriggerAgentEventListener(requestHandler, pathPrefix), properties);
if (triggerPathEventRegistration != null) {
registrations.put(requestHandler.toString(), triggerPathEventRegistration);
}
} else {
throw new DistributionException("cannot register trigger since bundle context is null");
}
}
use of org.apache.sling.distribution.common.DistributionException in project sling by apache.
the class AbstractJcrEventTrigger method register.
public void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionException {
Session session;
try {
session = getSession();
JcrEventDistributionTriggerListener listener = new JcrEventDistributionTriggerListener(requestHandler);
registeredListeners.put(requestHandler.toString(), listener);
session.getWorkspace().getObservationManager().addEventListener(listener, getEventTypes(), path, true, null, null, false);
} catch (RepositoryException e) {
throw new DistributionException("unable to register handler " + requestHandler, e);
}
}
use of org.apache.sling.distribution.common.DistributionException in project sling by apache.
the class ResourceEventDistributionTrigger method register.
public void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionException {
// register an event handler on path which triggers the agent on node / property changes / addition / removals
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT_TOPIC, new String[] { SlingConstants.TOPIC_RESOURCE_ADDED, SlingConstants.TOPIC_RESOURCE_CHANGED, SlingConstants.TOPIC_RESOURCE_REMOVED });
log.info("trigger agent {} on path '{}'", requestHandler, path);
properties.put(EventConstants.EVENT_FILTER, "(&(path=" + path + "/*) (!(" + DEAConstants.PROPERTY_APPLICATION + "=*)))");
ServiceRegistration triggerPathEventRegistration = bundleContext.registerService(EventHandler.class.getName(), new TriggerAgentEventListener(requestHandler), properties);
if (triggerPathEventRegistration != null) {
registrations.put(requestHandler.toString(), triggerPathEventRegistration);
} else {
throw new DistributionException("cannot register event handler service for triggering agent");
}
}
Aggregations