Search in sources :

Example 1 with UnixStylePermission

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());
}
Also used : DependencyVersion(org.expath.pkg.repo.deps.DependencyVersion) Txn(org.exist.storage.txn.Txn) java.util(java.util) BufferedInputStream(java.io.BufferedInputStream) QName(org.exist.dom.QName) SequenceIterator(org.exist.xquery.value.SequenceIterator) PermissionDeniedException(org.exist.security.PermissionDeniedException) org.exist.xquery(org.exist.xquery) DirectoryStream(java.nio.file.DirectoryStream) JarEntry(java.util.jar.JarEntry) org.exist.dom.memtree(org.exist.dom.memtree) Collection(org.exist.collections.Collection) UnixStylePermission(org.exist.security.UnixStylePermission) XmldbURI(org.exist.xmldb.XmldbURI) Attributes(org.xml.sax.Attributes) JarInputStream(java.util.jar.JarInputStream) EXistException(org.exist.EXistException) DocUtils(org.exist.xquery.util.DocUtils) DateTimeValue(org.exist.xquery.value.DateTimeValue) SystemProperties(org.exist.SystemProperties) Path(java.nio.file.Path) Permission(org.exist.security.Permission) Nullable(javax.annotation.Nullable) BatchUserInteraction(org.expath.pkg.repo.tui.BatchUserInteraction) PermissionFactory(org.exist.security.PermissionFactory) InputSource(org.xml.sax.InputSource) Files(java.nio.file.Files) GroupAider(org.exist.security.internal.aider.GroupAider) Type(org.exist.xquery.value.Type) FileSource(org.exist.source.FileSource) IOException(java.io.IOException) UserAider(org.exist.security.internal.aider.UserAider) Either(com.evolvedbinary.j8fu.Either) org.expath.pkg.repo(org.expath.pkg.repo) Logger(org.apache.logging.log4j.Logger) Element(org.w3c.dom.Element) Stream(java.util.stream.Stream) DBBroker(org.exist.storage.DBBroker) SAXException(org.xml.sax.SAXException) org.exist.util(org.exist.util) Sequence(org.exist.xquery.value.Sequence) TriggerException(org.exist.collections.triggers.TriggerException) LogManager(org.apache.logging.log4j.LogManager) Package(org.expath.pkg.repo.Package) AttrList(org.exist.util.serializer.AttrList) InputStream(java.io.InputStream) UnixStylePermission(org.exist.security.UnixStylePermission) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Aggregations

Either (com.evolvedbinary.j8fu.Either)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DirectoryStream (java.nio.file.DirectoryStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 java.util (java.util)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 EXistException (org.exist.EXistException)1 SystemProperties (org.exist.SystemProperties)1 Collection (org.exist.collections.Collection)1 TriggerException (org.exist.collections.triggers.TriggerException)1 QName (org.exist.dom.QName)1 org.exist.dom.memtree (org.exist.dom.memtree)1