Skip to content

Commit

Permalink
8344799: Remove permissions checks from java.awt.Desktop
Browse files Browse the repository at this point in the history
Reviewed-by: azvegint
  • Loading branch information
prrace committed Nov 22, 2024
1 parent e21d06f commit 50c099d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 84 deletions.
3 changes: 0 additions & 3 deletions src/java.base/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@
java.management.rmi,
java.rmi,
java.sql.rowset;
exports sun.security.action to
java.desktop;
exports sun.security.internal.interfaces to
jdk.crypto.cryptoki;
exports sun.security.internal.spec to
Expand All @@ -346,7 +344,6 @@
exports sun.security.tools to
jdk.jartool;
exports sun.security.util to
java.desktop,
java.naming,
java.rmi,
java.security.jgss,
Expand Down
81 changes: 0 additions & 81 deletions src/java.desktop/share/classes/java/awt/Desktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.awt.desktop.SystemEventListener;
import java.awt.peer.DesktopPeer;
import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -47,7 +46,6 @@
import javax.swing.JMenuBar;

import sun.awt.SunToolkit;
import sun.security.util.SecurityConstants;

/**
* The {@code Desktop} class allows interact with various desktop capabilities.
Expand Down Expand Up @@ -274,15 +272,6 @@ private Desktop() {
}
}

private void checkEventsProcessingPermission() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission(
"canProcessApplicationEvents"));
}
}

/**
* Returns the {@code Desktop} instance of the current
* desktop context. On some platforms the Desktop API may not be
Expand Down Expand Up @@ -395,7 +384,6 @@ private void checkActionSupport(Action actionType){
*/
public void open(File file) throws IOException {
file = new File(file.getPath());
checkExec();
checkActionSupport(Action.OPEN);
checkFileValidation(file);

Expand All @@ -417,7 +405,6 @@ public void open(File file) throws IOException {
*/
public void edit(File file) throws IOException {
file = new File(file.getPath());
checkExec();
checkActionSupport(Action.EDIT);
file.canWrite();
checkFileValidation(file);
Expand All @@ -443,12 +430,6 @@ public void edit(File file) throws IOException {
*/
public void print(File file) throws IOException {
file = new File(file.getPath());
checkExec();
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPrintJobAccess();
}
checkActionSupport(Action.PRINT);
checkFileValidation(file);
if (file.isDirectory()) {
Expand All @@ -475,7 +456,6 @@ public void print(File file) throws IOException {
* @see java.net.URI
*/
public void browse(URI uri) throws IOException {
checkExec();
checkActionSupport(Action.BROWSE);
Objects.requireNonNull(uri);
peer.browse(uri);
Expand All @@ -491,7 +471,6 @@ public void browse(URI uri) throws IOException {
* found, or it fails to be launched
*/
public void mail() throws IOException {
checkExec();
checkActionSupport(Action.MAIL);
URI mailtoURI = null;
try{
Expand Down Expand Up @@ -528,7 +507,6 @@ public void mail() throws IOException {
* @see java.net.URI
*/
public void mail(URI mailtoURI) throws IOException {
checkExec();
checkActionSupport(Action.MAIL);
if (mailtoURI == null) throw new NullPointerException();

Expand All @@ -539,32 +517,6 @@ public void mail(URI mailtoURI) throws IOException {
peer.mail(mailtoURI);
}

private void checkExec() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new FilePermission("<<ALL FILES>>",
SecurityConstants.FILE_EXECUTE_ACTION));
}
}

private void checkRead() throws SecurityException {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new FilePermission("<<ALL FILES>>",
SecurityConstants.FILE_READ_ACTION));
}
}

private void checkQuitPermission() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkExit(0);
}
}

/**
* Adds sub-types of {@link SystemEventListener} to listen for notifications
* from the native system.
Expand All @@ -583,7 +535,6 @@ private void checkQuitPermission() {
* @since 9
*/
public void addAppEventListener(final SystemEventListener listener) {
checkEventsProcessingPermission();
peer.addAppEventListener(listener);
}

Expand All @@ -605,7 +556,6 @@ public void addAppEventListener(final SystemEventListener listener) {
* @since 9
*/
public void removeAppEventListener(final SystemEventListener listener) {
checkEventsProcessingPermission();
peer.removeAppEventListener(listener);
}

Expand All @@ -624,7 +574,6 @@ public void removeAppEventListener(final SystemEventListener listener) {
* @since 9
*/
public void setAboutHandler(final AboutHandler aboutHandler) {
checkEventsProcessingPermission();
checkActionSupport(Action.APP_ABOUT);
peer.setAboutHandler(aboutHandler);
}
Expand All @@ -644,7 +593,6 @@ public void setAboutHandler(final AboutHandler aboutHandler) {
* @since 9
*/
public void setPreferencesHandler(final PreferencesHandler preferencesHandler) {
checkEventsProcessingPermission();
checkActionSupport(Action.APP_PREFERENCES);
peer.setPreferencesHandler(preferencesHandler);
}
Expand All @@ -668,9 +616,6 @@ public void setPreferencesHandler(final PreferencesHandler preferencesHandler) {
* @since 9
*/
public void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
checkEventsProcessingPermission();
checkExec();
checkRead();
checkActionSupport(Action.APP_OPEN_FILE);
peer.setOpenFileHandler(openFileHandler);
}
Expand All @@ -693,12 +638,6 @@ public void setOpenFileHandler(final OpenFilesHandler openFileHandler) {
* @since 9
*/
public void setPrintFileHandler(final PrintFilesHandler printFileHandler) {
checkEventsProcessingPermission();
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPrintJobAccess();
}
checkActionSupport(Action.APP_PRINT_FILE);
peer.setPrintFileHandler(printFileHandler);
}
Expand Down Expand Up @@ -726,8 +665,6 @@ public void setPrintFileHandler(final PrintFilesHandler printFileHandler) {
* @since 9
*/
public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
checkEventsProcessingPermission();
checkExec();
checkActionSupport(Action.APP_OPEN_URI);
peer.setOpenURIHandler(openURIHandler);
}
Expand All @@ -746,8 +683,6 @@ public void setOpenURIHandler(final OpenURIHandler openURIHandler) {
* @since 9
*/
public void setQuitHandler(final QuitHandler quitHandler) {
checkEventsProcessingPermission();
checkQuitPermission();
checkActionSupport(Action.APP_QUIT_HANDLER);
peer.setQuitHandler(quitHandler);
}
Expand All @@ -762,8 +697,6 @@ public void setQuitHandler(final QuitHandler quitHandler) {
* @since 9
*/
public void setQuitStrategy(final QuitStrategy strategy) {
checkEventsProcessingPermission();
checkQuitPermission();
checkActionSupport(Action.APP_QUIT_STRATEGY);
peer.setQuitStrategy(strategy);
}
Expand All @@ -788,8 +721,6 @@ public void setQuitStrategy(final QuitStrategy strategy) {
* @since 9
*/
public void enableSuddenTermination() {
checkEventsProcessingPermission();
checkQuitPermission();
checkActionSupport(Action.APP_SUDDEN_TERMINATION);
peer.enableSuddenTermination();
}
Expand All @@ -806,8 +737,6 @@ public void enableSuddenTermination() {
* @since 9
*/
public void disableSuddenTermination() {
checkEventsProcessingPermission();
checkQuitPermission();
checkActionSupport(Action.APP_SUDDEN_TERMINATION);
peer.disableSuddenTermination();
}
Expand All @@ -822,7 +751,6 @@ public void disableSuddenTermination() {
* @since 9
*/
public void requestForeground(final boolean allWindows) {
checkEventsProcessingPermission();
checkActionSupport(Action.APP_REQUEST_FOREGROUND);
peer.requestForeground(allWindows);
}
Expand All @@ -839,8 +767,6 @@ public void requestForeground(final boolean allWindows) {
* @since 9
*/
public void openHelpViewer() {
checkExec();
checkEventsProcessingPermission();
checkActionSupport(Action.APP_HELP_VIEWER);
peer.openHelpViewer();
}
Expand All @@ -854,7 +780,6 @@ public void openHelpViewer() {
* @since 9
*/
public void setDefaultMenuBar(final JMenuBar menuBar) {
checkEventsProcessingPermission();
checkActionSupport(Action.APP_MENU_BAR);

if (menuBar != null) {
Expand All @@ -881,7 +806,6 @@ public void setDefaultMenuBar(final JMenuBar menuBar) {
*/
public void browseFileDirectory(File file) {
file = new File(file.getPath());
checkExec();
checkActionSupport(Action.BROWSE_FILE_DIR);
checkFileValidation(file);
File parentFile = file.getParentFile();
Expand All @@ -903,13 +827,8 @@ public void browseFileDirectory(File file) {
*
* @since 9
*/
@SuppressWarnings("removal")
public boolean moveToTrash(File file) {
file = new File(file.getPath());
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkDelete(file.getPath());
}
checkActionSupport(Action.MOVE_TO_TRASH);
checkFileValidation(file);
return peer.moveToTrash(file);
Expand Down

0 comments on commit 50c099d

Please sign in to comment.