Search in sources :

Example 11 with DistributionException

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");
        }
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) DistributionException(org.apache.sling.distribution.common.DistributionException) Privilege(javax.jcr.security.Privilege)

Example 12 with DistributionException

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");
        }
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) DistributionException(org.apache.sling.distribution.common.DistributionException) Privilege(javax.jcr.security.Privilege)

Example 13 with DistributionException

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");
    }
}
Also used : Hashtable(java.util.Hashtable) EventHandler(org.osgi.service.event.EventHandler) DistributionException(org.apache.sling.distribution.common.DistributionException) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 14 with DistributionException

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);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) DistributionException(org.apache.sling.distribution.common.DistributionException) Session(javax.jcr.Session)

Example 15 with DistributionException

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");
    }
}
Also used : Hashtable(java.util.Hashtable) EventHandler(org.osgi.service.event.EventHandler) DistributionException(org.apache.sling.distribution.common.DistributionException) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

DistributionException (org.apache.sling.distribution.common.DistributionException)35 IOException (java.io.IOException)8 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)8 Session (javax.jcr.Session)6 Nonnull (javax.annotation.Nonnull)5 RepositoryException (javax.jcr.RepositoryException)5 PersistenceException (org.apache.sling.api.resource.PersistenceException)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)5 InputStream (java.io.InputStream)4 Resource (org.apache.sling.api.resource.Resource)4 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 DigestOutputStream (java.security.DigestOutputStream)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 LoginException (org.apache.sling.api.resource.LoginException)3 SimpleDistributionResponse (org.apache.sling.distribution.impl.SimpleDistributionResponse)3 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)3