-
Notifications
You must be signed in to change notification settings - Fork 307
Added ACL feature #2190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Added ACL feature #2190
Changes from all commits
0650126
d3f536e
4c235fa
472440b
63201fe
18a9feb
e1f132e
124b0f5
b61843c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
| */ | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
| } | ||
|
|
||
| public void setAcl(List<FileAcl> acl) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
|
|
@@ -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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it's needed. |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it's needed. |
||
| } | ||
|
|
||
| public Path getPath() { | ||
|
|
@@ -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 |
|---|---|---|
|
|
@@ -45,6 +45,8 @@ | |
| import java.time.temporal.ChronoUnit; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
@@ -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()) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| doc.getAttributes().setAcl(fileAcls); | ||
| } | ||
| } | ||
| } | ||
| // Attributes | ||
|
|
||
|
|
@@ -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); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
|
@@ -125,6 +136,10 @@ public String getExtension() { | |
| return extension; | ||
| } | ||
|
|
||
| public List<FileAcl> getAcls() { | ||
| return acls; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "FileAbstractModel{" + "name='" + name + '\'' + | ||
|
|
@@ -137,6 +152,7 @@ public String toString() { | |
| ", owner='" + owner + '\'' + | ||
| ", group='" + group + '\'' + | ||
| ", permissions=" + permissions + | ||
| ", acls=" + acls + | ||
| ", extension='" + extension + '\'' + | ||
| ", fullpath='" + fullpath + '\'' + | ||
| ", size=" + size + | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
|
|
@@ -61,6 +62,8 @@ private String resolveSeparator(String path) { | |
|
|
||
| @Override | ||
| public FileAbstractModel toFileAbstractModel(String path, File file) { | ||
| final boolean collectAcls = fsSettings.getFs().isAclSupport(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this line. |
||
| return new FileAbstractModel( | ||
| file.getName(), | ||
| file.isFile(), | ||
|
|
@@ -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()); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also write: fsSettings.getFs().isAclSupport() ? getFileAcls(file) : Collections.emptyList()); |
||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
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
aclvalue.