Skip to content

Commit fa30d36

Browse files
committed
Add API for restricting operations for sensitive files
This change adds the following API: * org.eclipse.core.resources.IWorkspace.isRestrictedContentEnabled() * org.eclipse.core.resources.IWorkspace.setRestrictedContentEnabled(boolean) * org.eclipse.core.resources.IFile.isContentRestricted() * org.eclipse.core.resources.IFile.setContentRestricted(boolean) The goal of this API is to allow Eclipse-based IDEs to restrict certain platform functionality on a per-file basis, for sensitive files. To restrict access to sensitive files, at runtime call: 1. IWorkspace.setRestrictedContentEnabled(true) 2. For each sensitive file, call: IFile.setContentRestricted(true) Neither the IWorkspace nor the IFile flags are persisted, to enable restricted handling these flags must be set for each session. The restrictions will apply to following functionality: * File search * Storing file history Potentially more platform functionality will be restricted, if the workspace has restricted handling enabled. See: #2588
1 parent 4d9d68a commit fa30d36

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

resources/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.core.resources; singleton:=true
5-
Bundle-Version: 3.23.300.qualifier
5+
Bundle-Version: 3.24.0.qualifier
66
Bundle-Activator: org.eclipse.core.resources.ResourcesPlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ public class Workspace extends PlatformObject implements IWorkspace, ICoreConsta
271271
*/
272272
protected IFileModificationValidator validator = null;
273273

274+
private boolean enableRestrictedContent;
275+
274276
/**
275277
* Data structure for holding the multi-part outcome of
276278
* <code>IWorkspace.computeProjectBuildConfigOrder</code>.
@@ -2945,4 +2947,14 @@ private void createMultiple(ConcurrentMap<File, byte[]> filesToCreate, int updat
29452947
subMonitor.done();
29462948
}
29472949
}
2950+
2951+
@Override
2952+
public boolean isRestrictedContentEnabled() {
2953+
return enableRestrictedContent;
2954+
}
2955+
2956+
@Override
2957+
public void setRestrictedContentEnabled(boolean enabled) {
2958+
this.enableRestrictedContent = enabled;
2959+
}
29482960
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/WorkspaceDescription.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,5 @@ public boolean isKeepDerivedState() {
227227
public void setKeepDerivedState(boolean keepDerivedState) {
228228
this.keepDerivedState = keepDerivedState;
229229
}
230+
230231
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/IFile.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
* @noextend This interface is not intended to be extended by clients.
5454
*/
5555
public interface IFile extends IResource, IEncodedStorage, IAdaptable {
56+
57+
/**
58+
* Session property used to mark a file as containing restricted content
59+
*
60+
* @since 3.24
61+
*/
62+
QualifiedName RESTRICTED_CONTENT = new QualifiedName(ResourcesPlugin.PI_RESOURCES, "restrictedContent"); //$NON-NLS-1$
63+
5664
/**
5765
* Character encoding constant (value 0) which identifies
5866
* files that have an unknown character encoding scheme.
@@ -1414,4 +1422,31 @@ public default String readString() throws CoreException {
14141422
public default String getLineSeparator(boolean checkParent) throws CoreException {
14151423
return getProject().getDefaultLineSeparator();
14161424
}
1425+
1426+
/**
1427+
* Returns whether the current file is marked as containing restricted
1428+
* (sensitive) content, where some IDE functionality related to the file content
1429+
* might be limited.
1430+
*
1431+
* @return whether the current file is marked as containing sensitive content.
1432+
* This flag is not persisted and is {@code false} by default.
1433+
* @since 3.24
1434+
*/
1435+
default boolean isContentRestricted() throws CoreException {
1436+
IWorkspace workspace = getWorkspace();
1437+
return workspace != null && workspace.isRestrictedContentEnabled()
1438+
&& getSessionProperty(RESTRICTED_CONTENT) != null;
1439+
}
1440+
1441+
/**
1442+
* Marks the current file as containing restricted (sensitive) content. Some IDE
1443+
* functionality related to the file content might be limited as long as the
1444+
* file is marked as restricted. This flag is not persisted and is {@code false}
1445+
* by default.
1446+
*
1447+
* @since 3.24
1448+
*/
1449+
default void setContentRestricted(boolean restricted) throws CoreException {
1450+
setSessionProperty(RESTRICTED_CONTENT, Boolean.toString(restricted));
1451+
}
14171452
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/IWorkspace.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,4 +1861,28 @@ public default void write(Map<IFile, byte[]> contentMap, boolean force, boolean
18611861
e.getKey().write(e.getValue(), force, derived, keepHistory, subMon.split(1));
18621862
}
18631863
}
1864+
1865+
/**
1866+
* Returns whether certain IDE functionality should be disabled for restricted
1867+
* (sensitive) files. Examples are file history and search.
1868+
*
1869+
* @return <code>true</code> if restricted (sensitive) files handling is enabled
1870+
* by the IDE, <code>false</code> otherwise
1871+
* @see IFile#setContentRestricted(boolean)
1872+
* @see IFile#isContentRestricted()
1873+
* @since 3.24
1874+
*/
1875+
boolean isRestrictedContentEnabled();
1876+
1877+
/**
1878+
* Specifies whether certain IDE functionality should be disabled for restricted
1879+
* (sensitive) files. Examples are file history and search.
1880+
*
1881+
* @param enabled <code>true</code> to enable restricted (sensitive) files
1882+
* handling, <code>false</code> otherwise
1883+
* @see IFile#setContentRestricted(boolean)
1884+
* @see IFile#isContentRestricted()
1885+
* @since 3.24
1886+
*/
1887+
void setRestrictedContentEnabled(boolean enabled);
18641888
}

0 commit comments

Comments
 (0)