Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

package fr.pilato.elasticsearch.crawler.fs.beans;

import fr.pilato.elasticsearch.crawler.fs.framework.FileAcl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Represents additional file attributes.
*/
Expand All @@ -27,6 +33,7 @@ public class Attributes {
private String owner;
private String group;
private int permissions;
private List<FileAcl> acl;

public String getOwner() {
return owner;
Expand All @@ -51,4 +58,16 @@ public int getPermissions() {
public void setPermissions(int permissions) {
this.permissions = permissions;
}

public List<FileAcl> getAcl() {
return acl != null ? Collections.unmodifiableList(acl) : null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just return the acl value.

}

public void setAcl(List<FileAcl> acl) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just write:

this.acl = acl;

if (acl == null || acl.isEmpty()) {
this.acl = null;
} else {
this.acl = new ArrayList<>(acl);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public class Folder {

private Path path;
private File file;
private Attributes attributes;

public Folder() {
path = new Path();
file = new File();
file.setContentType(CONTENT_TYPE);
attributes = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's needed.

}

/**
Expand All @@ -61,6 +63,7 @@ public Folder(String name, String root, String real, String virtual, LocalDateTi
file.setLastModified(localDateTimeToDate(modification));
file.setCreated(localDateTimeToDate(creation));
file.setLastAccessed(localDateTimeToDate(lastAccess));
attributes = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's needed.

}

public Path getPath() {
Expand All @@ -78,4 +81,12 @@ public File getFile() {
public void setFile(File file) {
this.file = file;
}

public Attributes getAttributes() {
return attributes;
}

public void setAttributes(Attributes attributes) {
this.attributes = attributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/paste ?

import java.util.List;

import static fr.pilato.elasticsearch.crawler.fs.framework.FsCrawlerUtil.*;
import static fr.pilato.elasticsearch.crawler.fs.framework.JsonUtil.asMap;
Expand Down Expand Up @@ -493,6 +495,12 @@ private void indexFile(FileAbstractModel fileAbstractModel, ScanStatistic stats,
if (fileAbstractModel.getPermissions() >= 0) {
doc.getAttributes().setPermissions(fileAbstractModel.getPermissions());
}
if (fsSettings.getFs().isAclSupport()) {
List<FileAcl> fileAcls = fileAbstractModel.getAcls();
if (!fileAcls.isEmpty()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to check this? Can't we just return whatever the fileAbstractModel.getAcls(); sent?

doc.getAttributes().setAcl(fileAcls);
}
}
}
// Attributes

Expand Down Expand Up @@ -634,6 +642,26 @@ private void indexDirectory(String path, String rootPath) throws Exception {
getModificationTime(folderInfo),
getLastAccessTime(folderInfo));

if (fsSettings.getFs().isAttributesSupport() && (fsSettings.getServer() == null || PROTOCOL.LOCAL.equals(fsSettings.getServer().getProtocol()))) {
Attributes attributes = new Attributes();
attributes.setOwner(getOwnerName(folderInfo));
attributes.setGroup(getGroupName(folderInfo));
int permissions = getFilePermissions(folderInfo);
if (permissions >= 0) {
attributes.setPermissions(permissions);
}
if (fsSettings.getFs().isAclSupport()) {
List<FileAcl> folderAcls = getFileAcls(folderInfo);
if (!folderAcls.isEmpty()) {
attributes.setAcl(folderAcls);
}
}

if (attributes.getOwner() != null || attributes.getGroup() != null || attributes.getAcl() != null || permissions >= 0) {
folder.setAttributes(attributes);
}
}

indexDirectory(SignTool.sign(path), folder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@

package fr.pilato.elasticsearch.crawler.fs.crawler;

import fr.pilato.elasticsearch.crawler.fs.framework.FileAcl;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class FileAbstractModel {
private final String name;
Expand All @@ -55,9 +59,11 @@ public class FileAbstractModel {
private final String group;
private final int permissions;
private final String extension;
private final List<FileAcl> acls;

public FileAbstractModel(String name, boolean file, LocalDateTime lastModifiedDate, LocalDateTime creationDate, LocalDateTime accessDate,
String extension, String path, String fullpath, long size, String owner, String group, int permissions) {
String extension, String path, String fullpath, long size, String owner, String group, int permissions,
List<FileAcl> acls) {
this.name = name;
this.file = file;
this.directory = !file;
Expand All @@ -71,6 +77,11 @@ public FileAbstractModel(String name, boolean file, LocalDateTime lastModifiedDa
this.group = group;
this.permissions = permissions;
this.extension = extension;
if (acls == null || acls.isEmpty()) {
this.acls = Collections.emptyList();
} else {
this.acls = Collections.unmodifiableList(new ArrayList<>(acls));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we write this?

this.acls = Collections.unmodifiableList(acls);

Or may be better:

Replace the whole:

        if (acls == null || acls.isEmpty()) {
            this.acls = Collections.emptyList();
        } else {
            this.acls = Collections.unmodifiableList(new ArrayList<>(acls));
        }

With:

this.acls = acls;

}
}

public String getName() {
Expand Down Expand Up @@ -125,6 +136,10 @@ public String getExtension() {
return extension;
}

public List<FileAcl> getAcls() {
return acls;
}

@Override
public String toString() {
return "FileAbstractModel{" + "name='" + name + '\'' +
Expand All @@ -137,6 +152,7 @@ public String toString() {
", owner='" + owner + '\'' +
", group='" + group + '\'' +
", permissions=" + permissions +
", acls=" + acls +
", extension='" + extension + '\'' +
", fullpath='" + fullpath + '\'' +
", size=" + size +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.Stream;

Expand Down Expand Up @@ -61,6 +62,8 @@ private String resolveSeparator(String path) {

@Override
public FileAbstractModel toFileAbstractModel(String path, File file) {
final boolean collectAcls = fsSettings.getFs().isAclSupport();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have to remove this line depending on what you do at the end of this method ;)

System.out.println("[ACL DEBUG] Collecting ACLs for file " + file.getAbsolutePath() + " -> " + collectAcls);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line.

return new FileAbstractModel(
file.getName(),
file.isFile(),
Expand All @@ -73,7 +76,8 @@ public FileAbstractModel toFileAbstractModel(String path, File file) {
file.length(),
getOwnerName(file),
getGroupName(file),
getFilePermissions(file));
getFilePermissions(file),
collectAcls ? getFileAcls(file) : Collections.emptyList());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also write:

fsSettings.getFs().isAclSupport() ? getFileAcls(file) : Collections.emptyList());

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public FileAbstractModel toFileAbstractModel(String path, FTPFile file) {
file.getSize(),
file.getUser(),
file.getGroup(),
FTPUtils.getFilePermissions(file));
FTPUtils.getFilePermissions(file),
Collections.emptyList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -82,7 +83,8 @@ public FileAbstractModel toFileAbstractModel(String path, SftpClient.DirEntry fi
file.getAttributes().getSize(),
Integer.toString(file.getAttributes().getUserId()),
Integer.toString(file.getAttributes().getGroupId()),
file.getAttributes().getPermissions());
file.getAttributes().getPermissions(),
Collections.emptyList());
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions docs/source/admin/fs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ The job file (``~/.fscrawler/test/_settings.yaml``) for the job name ``test`` mu
# inlcude user/group of file only if needed
attributes_support: false

# collect ACL metadata when available
acl_support: false

# do you REALLY want to store every file as a copy in the index ? Then set this to true
store_source: false

Expand Down
18 changes: 18 additions & 0 deletions docs/source/admin/fs/local-fs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Here is a list of Local FS settings (under ``fs.`` prefix)`:
+----------------------------+-----------------------+---------------------------------+
| ``fs.attributes_support`` | ``false`` | `Adding file attributes`_ |
+----------------------------+-----------------------+---------------------------------+
| ``fs.acl_support`` | ``false`` | `Collecting ACL metadata`_ |
+----------------------------+-----------------------+---------------------------------+
| ``fs.raw_metadata`` | ``false`` | `Enabling raw metadata`_ |
+----------------------------+-----------------------+---------------------------------+
| ``fs.filename_as_id`` | ``false`` | :ref:`filename-as-id` |
Expand Down Expand Up @@ -422,6 +424,22 @@ and ``attributes.permissions``, you can set ``attributes_support`` to ``true``.
On Windows systems, ``attributes.group`` and ``attributes.permissions`` are
not generated.

Collecting ACL metadata
^^^^^^^^^^^^^^^^^^^^^^^

To extract NTFS access control entries (principal, type, permissions and flags),
enable both ``attributes_support`` and ``acl_support``:

.. code:: yaml

name: "test"
fs:
attributes_support: true
acl_support: true

When ``acl_support`` is disabled, FSCrawler skips resolving ACLs even if
``attributes_support`` is active.

Enabling raw metadata
^^^^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions docs/source/admin/fs/rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ It will give you a response similar to:
"store_source" : false,
"index_content" : true,
"attributes_support" : false,
"acl_support" : false,
"raw_metadata" : true,
"xml_support" : false,
"index_folders" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ public void createIndexAndComponentTemplates() throws Exception {
// If needed, we create the component and index templates for the folder index
if (settings.getFs().isIndexFolders()) {
logger.debug("Creating/updating component templates for [{}]", settings.getElasticsearch().getIndexFolder());
loadAndPushComponentTemplate(majorVersion, "fscrawler_mapping_attributes", settings.getElasticsearch().getIndexFolder());
loadAndPushComponentTemplate(majorVersion, "fscrawler_mapping_file", settings.getElasticsearch().getIndexFolder());
loadAndPushComponentTemplate(majorVersion, "fscrawler_mapping_path", settings.getElasticsearch().getIndexFolder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
"group": {
"type": "keyword"
},
"acl": {
"properties": {
"flags": {
"type": "keyword"
},
"permissions": {
"type": "keyword"
},
"principal": {
"type": "keyword"
},
"type": {
"type": "keyword"
}
}
},
"owner": {
"type": "keyword"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
],
"priority": 600,
"composed_of": [
"fscrawler_INDEX_NAME_mapping_attributes",
"fscrawler_INDEX_NAME_mapping_file",
"fscrawler_INDEX_NAME_mapping_path"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
"group": {
"type": "keyword"
},
"acl": {
"properties": {
"flags": {
"type": "keyword"
},
"permissions": {
"type": "keyword"
},
"principal": {
"type": "keyword"
},
"type": {
"type": "keyword"
}
}
},
"owner": {
"type": "keyword"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
],
"priority": 600,
"composed_of": [
"fscrawler_INDEX_NAME_mapping_attributes",
"fscrawler_INDEX_NAME_mapping_file",
"fscrawler_INDEX_NAME_mapping_path"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
"group": {
"type": "keyword"
},
"acl": {
"properties": {
"flags": {
"type": "keyword"
},
"permissions": {
"type": "keyword"
},
"principal": {
"type": "keyword"
},
"type": {
"type": "keyword"
}
}
},
"owner": {
"type": "keyword"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
],
"priority": 600,
"composed_of": [
"fscrawler_INDEX_NAME_mapping_attributes",
"fscrawler_INDEX_NAME_mapping_file",
"fscrawler_INDEX_NAME_mapping_path"
],
Expand Down
Loading
Loading