Skip to content

Commit 7c9b138

Browse files
committed
Add API for restricting operations for sensitive files
This change adds the following API: * org.eclipse.core.resources.IWorkspaceDescription.isRestrictedContentEnabled() * org.eclipse.core.resources.IWorkspaceDescription.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. IWorkspaceDescription.setRestrictedContentEnabled(true) 2. For each sensitive file, call: IFile.setContentRestricted(true) Neither the IWorkspaceDescription 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 7c9b138

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-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/WorkspaceDescription.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class WorkspaceDescription extends ModelObject implements IWorkspaceDescr
3434
protected int operationsPerSnapshot;
3535
protected long deltaExpiration;
3636
private int parallelBuildsCount;
37+
private boolean enableRestrictedContent;
3738

3839
public WorkspaceDescription(String name) {
3940
super(name);
@@ -51,6 +52,8 @@ public WorkspaceDescription(String name) {
5152
operationsPerSnapshot = node.getInt(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT, PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT_DEFAULT);
5253
deltaExpiration = node.getLong(PreferenceInitializer.PREF_DELTA_EXPIRATION, PreferenceInitializer.PREF_DELTA_EXPIRATION_DEFAULT);
5354
parallelBuildsCount = node.getInt(ResourcesPlugin.PREF_MAX_CONCURRENT_BUILDS, PreferenceInitializer.PREF_MAX_CONCURRENT_BUILDS_DEFAULT);
55+
// set at runtime:
56+
enableRestrictedContent = false;
5457
}
5558

5659
/**
@@ -227,4 +230,14 @@ public boolean isKeepDerivedState() {
227230
public void setKeepDerivedState(boolean keepDerivedState) {
228231
this.keepDerivedState = keepDerivedState;
229232
}
233+
234+
@Override
235+
public boolean isRestrictedContentEnabled() {
236+
return enableRestrictedContent;
237+
}
238+
239+
@Override
240+
public void setRestrictedContentEnabled(boolean enabled) {
241+
this.enableRestrictedContent = enabled;
242+
}
230243
}

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

Lines changed: 34 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,30 @@ 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+
return getWorkspace().getDescription().isRestrictedContentEnabled()
1437+
&& getSessionProperty(RESTRICTED_CONTENT) != null;
1438+
}
1439+
1440+
/**
1441+
* Marks the current file as containing restricted (sensitive) content. Some IDE
1442+
* functionality related to the file content might be limited as long as the
1443+
* file is marked as restricted. This flag is not persisted and is {@code false}
1444+
* by default.
1445+
*
1446+
* @since 3.24
1447+
*/
1448+
default void setContentRestricted(boolean restricted) throws CoreException {
1449+
setSessionProperty(RESTRICTED_CONTENT, Boolean.toString(restricted));
1450+
}
14171451
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ public interface IWorkspaceDescription {
114114
*/
115115
boolean isApplyFileStatePolicy();
116116

117+
/**
118+
* Returns whether certain IDE functionality should be disabled for restricted
119+
* (sensitive) files. Examples are file history and search.
120+
*
121+
* @return <code>true</code> if restricted (sensitive) files handling is enabled
122+
* by the IDE, <code>false</code> otherwise
123+
* @see IFile#setContentRestricted(boolean)
124+
* @see IFile#isContentRestricted()
125+
* @since 3.24
126+
*/
127+
boolean isRestrictedContentEnabled();
128+
117129
/**
118130
* Returns the interval between automatic workspace snapshots.
119131
*
@@ -302,6 +314,18 @@ public interface IWorkspaceDescription {
302314
*/
303315
void setMaxConcurrentBuilds(int n);
304316

317+
/**
318+
* Specifies whether certain IDE functionality should be disabled for restricted
319+
* (sensitive) files. Examples are file history and search.
320+
*
321+
* @param enabled <code>true</code> to enable restricted (sensitive) files
322+
* handling, <code>false</code> otherwise
323+
* @see IFile#setContentRestricted(boolean)
324+
* @see IFile#isContentRestricted()
325+
* @since 3.24
326+
*/
327+
void setRestrictedContentEnabled(boolean enabled);
328+
305329
/**
306330
* @return the max number of builds that can happen concurrently during workspace build. 1 means no job (current thread).
307331
* @since 3.13

0 commit comments

Comments
 (0)