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,12 @@ public int getPermissions() {
public void setPermissions(int permissions) {
this.permissions = permissions;
}

public List<FileAcl> getAcl() {
return acl;
}

public void setAcl(List<FileAcl> acl) {
this.acl = acl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Folder {

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

public Folder() {
path = new Path();
Expand Down Expand Up @@ -78,4 +79,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,7 @@
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
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 +494,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()) {
doc.getAttributes().setAcl(fileAcls);
}
}
}
// Attributes

Expand Down Expand Up @@ -634,6 +641,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.toPath());
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,10 @@

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

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

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

public class FileAbstractModel {
private final String name;
Expand All @@ -55,9 +57,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 +75,7 @@ public FileAbstractModel(String name, boolean file, LocalDateTime lastModifiedDa
this.group = group;
this.permissions = permissions;
this.extension = extension;
this.acls = acls;
}

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

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

@Override
public String toString() {
return "FileAbstractModel{" + "name='" + name + '\'' +
Expand All @@ -137,6 +146,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 @@ -73,7 +74,8 @@ public FileAbstractModel toFileAbstractModel(String path, File file) {
file.length(),
getOwnerName(file),
getGroupName(file),
getFilePermissions(file));
getFilePermissions(file),
fsSettings.getFs().isAclSupport() ? getFileAcls(file.toPath()) : 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
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