@Override
  public void setPermissions(final Collection child, final Permission perm) throws XMLDBException {

    final XmldbURI childUri = XmldbURI.create(child.getName());

    try {
      executeWithBroker(
          new BrokerOperation<Void>() {
            @Override
            public Void withBroker(final DBBroker broker)
                throws XMLDBException, LockException, PermissionDeniedException, IOException,
                    EXistException, TriggerException, SyntaxException {
              return modifyCollection(
                  broker,
                  childUri,
                  new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
                    @Override
                    public Void modify(org.exist.collections.Collection collection)
                        throws PermissionDeniedException, LockException {
                      collection.setPermissions(perm);
                      return null;
                    }
                  });
            }
          });
    } catch (final Exception e) {
      throw new XMLDBException(
          ErrorCodes.VENDOR_ERROR,
          "Failed to modify permission on Collection '" + childUri.toString() + "'",
          e);
    }
  }
Example #2
0
  /* (non-Javadoc)
   * @see org.apache.tools.ant.Task#execute()
   */
  public void execute() throws BuildException {
    if (uri == null) throw new BuildException("You have to specify an XMLDB collection URI");
    if (resource == null && collection == null)
      throw new BuildException(
          "Missing parameter: either resource or collection should be specified");

    registerDatabase();
    try {
      log("Get base collection: " + uri, Project.MSG_DEBUG);
      Collection base = DatabaseManager.getCollection(uri, user, password);

      if (base == null) {
        throw new BuildException("Collection " + uri + " could not be found.");
      }

      log(
          "Create collection management service for collection " + base.getName(),
          Project.MSG_DEBUG);
      CollectionManagementServiceImpl service =
          (CollectionManagementServiceImpl) base.getService("CollectionManagementService", "1.0");
      if (resource != null) {
        log("Copying resource: " + resource, Project.MSG_INFO);
        Resource res = base.getResource(resource);
        if (res == null) throw new BuildException("Resource " + resource + " not found.");
        service.copyResource(resource, destination, name);
      } else {
        log("Copying collection: " + collection, Project.MSG_INFO);
        service.copy(collection, destination, name);
      }
    } catch (XMLDBException e) {
      throw new BuildException("XMLDB exception during remove: " + e.getMessage(), e);
    }
  }
  @Override
  public void setPermissions(
      Collection child,
      final String owner,
      final String group,
      final int mode,
      final List<ACEAider> aces)
      throws XMLDBException {

    final XmldbURI childUri = XmldbURI.create(child.getName());

    try {
      executeWithBroker(
          new BrokerOperation<Void>() {
            @Override
            public Void withBroker(final DBBroker broker)
                throws XMLDBException, LockException, PermissionDeniedException, IOException,
                    EXistException, TriggerException, SyntaxException {
              return modifyCollection(
                  broker,
                  childUri,
                  new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
                    @Override
                    public Void modify(org.exist.collections.Collection collection)
                        throws PermissionDeniedException, LockException {
                      final Permission permission = collection.getPermissions();
                      permission.setOwner(owner);
                      permission.setGroup(group);
                      permission.setMode(mode);
                      if (permission instanceof ACLPermission) {
                        final ACLPermission aclPermission = (ACLPermission) permission;
                        aclPermission.clear();
                        for (final ACEAider ace : aces) {
                          aclPermission.addACE(
                              ace.getAccessType(), ace.getTarget(), ace.getWho(), ace.getMode());
                        }
                      }
                      return null;
                    }
                  });
            }
          });
    } catch (final Exception e) {
      throw new XMLDBException(
          ErrorCodes.VENDOR_ERROR,
          "Failed to modify permission on Collection '" + childUri.toString() + "'",
          e);
    }
  }