use of org.exist.security.UnixStylePermission in project exist by eXist-db.
the class Deployment method setPermissions.
/**
* Set owner, group and permissions. For XQuery resources, always set the executable flag.
* @param mime
* @param permission
*/
private void setPermissions(final DBBroker broker, final Optional<RequestedPerms> requestedPerms, final boolean isCollection, final MimeType mime, final Permission permission) throws PermissionDeniedException {
int mode = permission.getMode();
if (requestedPerms.isPresent()) {
final RequestedPerms perms = requestedPerms.get();
PermissionFactory.chown(broker, permission, Optional.of(perms.user), perms.group);
mode = perms.permissions.map(permStr -> {
try {
final UnixStylePermission other = new UnixStylePermission(broker.getBrokerPool().getSecurityManager());
other.setMode(permStr);
return other.getMode();
} catch (final PermissionDeniedException | SyntaxException e) {
LOG.warn("Unable to set permissions string: {}. Falling back to default.", permStr);
return permission.getMode();
}
}).fold(l -> l, r -> r);
}
if (isCollection || (mime != null && mime.getName().equals(MimeType.XQUERY_TYPE.getName()))) {
// TODO(AR) Whoever did this - this is a really bad idea. You are circumventing the security of the system
mode = mode | 0111;
}
PermissionFactory.chmod(broker, permission, Optional.of(mode), Optional.empty());
}
Aggregations