Permalink
Browse files

Created additional chown and chrp functions and split chown away from

setPermissions
  • Loading branch information...
1 parent 76c910c commit 16bc41ba5d5db82bc2dbe3b0127c2ed641b4d9d6 @adamretter adamretter committed Feb 11, 2014
@@ -336,6 +336,52 @@ public Void modify(DocumentImpl document) throws SyntaxException, PermissionDeni
}
@Override
+ public void chgrp(final String group) throws XMLDBException {
+ final XmldbURI collUri = collection.getPathURI();
+
+ try {
+ executeWithBroker(new BrokerOperation<Void>() {
+ @Override
+ public Void withBroker(final DBBroker broker) throws XMLDBException, LockException, PermissionDeniedException, IOException, EXistException, TriggerException, SyntaxException {
+ return modifyCollection(broker, collUri, new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
+ @Override
+ public Void modify(org.exist.collections.Collection collection) throws PermissionDeniedException, SyntaxException, LockException {
+ final Permission permission = collection.getPermissionsNoLock();
+ permission.setGroup(group);
+ return null;
+ }
+ });
+ }
+ });
+ } catch(final Exception e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Failed to modify permission on Collection '" + collUri.toString() + "'", e);
+ }
+ }
+
+ @Override
+ public void chown(final Account u) throws XMLDBException {
+ final XmldbURI collUri = collection.getPathURI();
+
+ try {
+ executeWithBroker(new BrokerOperation<Void>() {
+ @Override
+ public Void withBroker(final DBBroker broker) throws XMLDBException, LockException, PermissionDeniedException, IOException, EXistException, TriggerException, SyntaxException {
+ return modifyCollection(broker, collUri, new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
+ @Override
+ public Void modify(org.exist.collections.Collection collection) throws PermissionDeniedException, SyntaxException, LockException {
+ final Permission permission = collection.getPermissionsNoLock();
+ permission.setOwner(u);
+ return null;
+ }
+ });
+ }
+ });
+ } catch(final Exception e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Failed to modify permission on Collection '" + collUri.toString() + "'", e);
+ }
+ }
+
+ @Override
public void chown(final Account u, final String group) throws XMLDBException {
final XmldbURI collUri = collection.getPathURI();
@@ -360,6 +406,48 @@ public Void modify(org.exist.collections.Collection collection) throws Permissio
}
@Override
+ public void chgrp(final Resource resource, final String group) throws XMLDBException {
+ try {
+ executeWithBroker(new BrokerOperation() {
+ @Override
+ public Void withBroker(final DBBroker broker) throws XMLDBException, LockException, PermissionDeniedException, IOException, EXistException, TriggerException, SyntaxException {
+ return modifyResource(broker, resource, new DatabaseItemModifier<DocumentImpl, Void>() {
+ @Override
+ public Void modify(DocumentImpl document) throws PermissionDeniedException, LockException {
+ document.getPermissions().setGroup(group);
+ return null;
+ }
+ });
+ }
+ });
+ } catch(final Exception e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Failed to modify permission on Resource '" + resource.getId() + "'", e);
+ }
+
+ }
+
+ @Override
+ public void chown(final Resource resource, final Account u) throws XMLDBException {
+ try {
+ executeWithBroker(new BrokerOperation() {
+ @Override
+ public Void withBroker(final DBBroker broker) throws XMLDBException, LockException, PermissionDeniedException, IOException, EXistException, TriggerException, SyntaxException {
+ return modifyResource(broker, resource, new DatabaseItemModifier<DocumentImpl, Void>() {
+ @Override
+ public Void modify(DocumentImpl document) throws PermissionDeniedException, LockException {
+ document.getPermissions().setOwner(u);
+ return null;
+ }
+ });
+ }
+ });
+ } catch(final Exception e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Failed to modify permission on Resource '" + resource.getId() + "'", e);
+ }
+
+ }
+
+ @Override
public void chown(final Resource resource, final Account u, final String group) throws XMLDBException {
try {
executeWithBroker(new BrokerOperation() {
@@ -311,13 +311,51 @@ public void unlockResource(Resource res) throws XMLDBException {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
}
}
-
+
+ /**
+ * Change the owner gid of the current collection
+ *
+ * @param group Description of the Parameter
+ * @exception XMLDBException Description of the Exception
+ */
+ @Override
+ public void chgrp(String group) throws XMLDBException {
+ try {
+ final List<Object> params = new ArrayList<Object>(4);
+ params.add(parent.getPath());
+ params.add(group);
+
+ parent.getClient().execute("chgrp", params);
+ } catch (final XmlRpcException e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Change the owner uid of the current collection
+ *
+ * @param u Description of the Parameter
+ * @exception XMLDBException Description of the Exception
+ */
+ @Override
+ public void chown(Account u) throws XMLDBException {
+ try {
+ final List<Object> params = new ArrayList<Object>(4);
+ params.add(parent.getPath());
+ params.add(u.getName());
+
+ parent.getClient().execute("chown", params);
+ } catch (final XmlRpcException e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
+ }
+ }
+
/**
- * Change the owner of the current collection
+ * Change the owner of the current collection
*
- *@param u Description of the Parameter
- *@param group Description of the Parameter
- *@exception XMLDBException Description of the Exception
+ * @param u Description of the Parameter
+ * @param group Description of the Parameter
+ * @exception XMLDBException Description of the Exception
*/
@Override
public void chown(Account u, String group) throws XMLDBException {
@@ -327,7 +365,51 @@ public void chown(Account u, String group) throws XMLDBException {
params.add(u.getName());
params.add(group);
- parent.getClient().execute("setPermissions", params);
+ parent.getClient().execute("chown", params);
+ } catch (final XmlRpcException e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Change the owner uid of a resource
+ *
+ * @param res Resource
+ * @param u The new owner of the resource
+ * @exception XMLDBException Description of the Exception
+ */
+ @Override
+ public void chgrp(Resource res, String group) throws XMLDBException {
+ //TODO : use dedicated function in XmldbURI
+ final String path = ((RemoteCollection) res.getParentCollection()).getPath() + "/" + res.getId();
+ try {
+ final List<Object> params = new ArrayList<Object>(4);
+ params.add(path);
+ params.add(group);
+
+ parent.getClient().execute("chgrp", params);
+ } catch (final XmlRpcException e) {
+ throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Change the owner uid of a resource
+ *
+ * @param res Resource
+ * @param u The new owner of the resource
+ * @exception XMLDBException Description of the Exception
+ */
+ @Override
+ public void chown(Resource res, Account u) throws XMLDBException {
+ //TODO : use dedicated function in XmldbURI
+ final String path = ((RemoteCollection) res.getParentCollection()).getPath() + "/" + res.getId();
+ try {
+ final List<Object> params = new ArrayList<Object>(4);
+ params.add(path);
+ params.add(u.getName());
+
+ parent.getClient().execute("chown", params);
} catch (final XmlRpcException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
}
@@ -351,7 +433,7 @@ public void chown(Resource res, Account u, String group) throws XMLDBException {
params.add(u.getName());
params.add(group);
- parent.getClient().execute("setPermissions", params);
+ parent.getClient().execute("chown", params);
} catch (final XmlRpcException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
}
@@ -64,26 +64,61 @@
//public void setPermissions(Collection collection, String owner, String group, int mode) throws XMLDBException;
//public void setPermissions(Resource resource, String owner, String group, int mode) throws XMLDBException;
-
+
/**
- * Change owner and group of the current collection.
+ * Change owner gid of the current collection.
*
- *@param u Description of the Parameter
- *@param group Description of the Parameter
- *@exception XMLDBException Description of the Exception
+ * @param group The group
+ * @throws XMLDBException
*/
- public void chown( Account u, String group ) throws XMLDBException;
+ public void chgrp(String group) throws XMLDBException;
+ /**
+ * Change owner uid of the current collection.
+ *
+ * @param u The user
+ * @throws XMLDBException
+ */
+ public void chown(Account u) throws XMLDBException;
/**
- * Change owner and group of the specified resource.
+ * Change owner uid and gid of the current collection.
*
- *@param res Description of the Parameter
- *@param u Description of the Parameter
- *@param group Description of the Parameter
- *@exception XMLDBException Description of the Exception
+ * @param u The user
+ * @param group The group
+ * @throws XMLDBException
+ */
+ public void chown(Account u, String group) throws XMLDBException;
+
+ /**
+ * Change owner gid of the specified resource.
+ *
+ * @param res The resource
+ * @param group The group
+ * @throws XMLDBException
+ */
+ public void chgrp(Resource res, String group)
+ throws XMLDBException;
+
+ /**
+ * Change owner uid of the specified resource.
+ *
+ * @param res The resource
+ * @param u The user
+ * @throws XMLDBException
+ */
+ public void chown(Resource res, Account u)
+ throws XMLDBException;
+
+ /**
+ * Change owner uid and gid of the specified resource.
+ *
+ * @param res The resource
+ * @param u The user
+ * @param group The group
+ * @throws XMLDBException
*/
- public void chown( Resource res, Account u, String group )
+ public void chown(Resource res, Account u, String group)
throws XMLDBException;
@@ -786,19 +786,29 @@ boolean setPermissions(
int permissions)
throws EXistException, PermissionDeniedException, URISyntaxException;
- boolean setPermissions(
- final String resource,
- final String owner,
- final String ownerGroup,
- final int mode,
- final List<ACEAider> aces)
- throws EXistException, PermissionDeniedException, URISyntaxException;
-
- public boolean setPermissions(
- final String resource,
- final String owner,
- final String ownerGroup)
- throws EXistException, PermissionDeniedException, URISyntaxException;
+ boolean setPermissions(
+ final String resource,
+ final String owner,
+ final String ownerGroup,
+ final int mode,
+ final List<ACEAider> aces)
+ throws EXistException, PermissionDeniedException, URISyntaxException;
+
+ public boolean chgrp(
+ final String resource,
+ final String ownerGroup)
+ throws EXistException, PermissionDeniedException, URISyntaxException;
+
+ public boolean chown(
+ final String resource,
+ final String owner)
+ throws EXistException, PermissionDeniedException, URISyntaxException;
+
+ public boolean chown(
+ final String resource,
+ final String owner,
+ final String ownerGroup)
+ throws EXistException, PermissionDeniedException, URISyntaxException;
public boolean lockResource(String path, String userName)
throws EXistException, PermissionDeniedException, URISyntaxException;
@@ -3744,7 +3744,43 @@ private String retrieveAllAsString(int resultId, HashMap<String, Object> paramet
}
@Override
- public boolean setPermissions(final String resource, final String owner, final String ownerGroup) throws EXistException, PermissionDeniedException, URISyntaxException {
+ public boolean chgrp(final String resource, final String ownerGroup) throws EXistException, PermissionDeniedException, URISyntaxException {
+ executeWithBroker(new BrokerOperation<Void>() {
+ @Override
+ public Void withBroker(final DBBroker broker) throws EXistException, URISyntaxException, PermissionDeniedException {
+ PermissionFactory.updatePermissions(broker, XmldbURI.xmldbUriFor(resource), new PermissionModifier(){
+ @Override
+ public void modify(Permission permission) throws PermissionDeniedException {
+ permission.setGroup(ownerGroup);
+ }
+ });
+ return null;
+ }
+ });
+
+ return true;
+ }
+
+ @Override
+ public boolean chown(final String resource, final String owner) throws EXistException, PermissionDeniedException, URISyntaxException {
+ executeWithBroker(new BrokerOperation<Void>() {
+ @Override
+ public Void withBroker(final DBBroker broker) throws EXistException, URISyntaxException, PermissionDeniedException {
+ PermissionFactory.updatePermissions(broker, XmldbURI.xmldbUriFor(resource), new PermissionModifier(){
+ @Override
+ public void modify(Permission permission) throws PermissionDeniedException {
+ permission.setOwner(owner);
+ }
+ });
+ return null;
+ }
+ });
+
+ return true;
+ }
+
+ @Override
+ public boolean chown(final String resource, final String owner, final String ownerGroup) throws EXistException, PermissionDeniedException, URISyntaxException {
executeWithBroker(new BrokerOperation<Void>() {
@Override
public Void withBroker(final DBBroker broker) throws EXistException, URISyntaxException, PermissionDeniedException {

0 comments on commit 16bc41b

Please sign in to comment.