8195624: Desktop API cannot be used without permission to read "os.version"

Reviewed-by: prr
This commit is contained in:
Sergey Bylokhov 2018-05-30 22:03:12 -07:00
parent bb315314c8
commit bff7725b4d
3 changed files with 44 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package sun.awt.windows;
import java.awt.Desktop.Action;
import java.awt.EventQueue;
import java.awt.desktop.SystemEventListener;
@ -38,9 +37,8 @@ import java.awt.peer.DesktopPeer;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import javax.swing.event.EventListenerList;
import sun.awt.OSInfo;
import javax.swing.event.EventListenerList;
/**
* Concrete implementation of the interface {@code DesktopPeer} for
@ -49,19 +47,15 @@ import sun.awt.OSInfo;
* @see DesktopPeer
*/
final class WDesktopPeer implements DesktopPeer {
/* Contants for the operation verbs */
/* Constants for the operation verbs */
private static String ACTION_OPEN_VERB = "open";
private static String ACTION_EDIT_VERB = "edit";
private static String ACTION_PRINT_VERB = "print";
private static boolean isEventUserSessionSupported = false;
private static native void init();
WDesktopPeer() {
init();
isEventUserSessionSupported = OSInfo.getWindowsVersion()
.compareTo(OSInfo.WINDOWS_VISTA) >= 0;
}
@Override
@ -75,9 +69,8 @@ final class WDesktopPeer implements DesktopPeer {
case MOVE_TO_TRASH:
case APP_SUDDEN_TERMINATION:
case APP_EVENT_SYSTEM_SLEEP:
return true;
case APP_EVENT_USER_SESSION:
return isEventUserSessionSupported;
return true;
default:
return false;
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.awt.Desktop;
/**
* @test
* @bug 8195624
* @summary Desktop.getDesktop() should work without permissions
* @run main/othervm/policy=java.policy -Djava.security.manager DefaultPermissions
*/
public final class DefaultPermissions {
public static void main(final String[] args) {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop();
}
}
}

View File

@ -0,0 +1 @@
;