8344654: Some client tests still expect a SecurityManager after JEP486

Reviewed-by: prr, azvegint
This commit is contained in:
Harshitha Onkar 2024-11-26 20:10:48 +00:00
parent 3689f3909e
commit 5e15415cb9
14 changed files with 46 additions and 251 deletions

View File

@ -32,23 +32,16 @@
* @build jdk.test.lib.Platform
* @run main bug8064934
*/
import jdk.test.lib.Platform;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class bug8064934 {
private static final String NO_ASSOCIATION_ERROR_MESSAGE = "Error message: No application is associated with" +
" the specified file for this operation.";
public static void main(String[] args) {
// This test is intended only for Windows
if (!AccessController.doPrivileged((PrivilegedAction<Boolean>) Platform::isWindows)) {
System.out.println("The test is for Windows platform only");
return;
}
// Test whether Desktop is supported of not
if (!Desktop.isDesktopSupported()) {

View File

@ -27,9 +27,6 @@ import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -154,17 +151,9 @@ public class SystemTrayIconHelper {
return null;
}
static Field getField(final Class clz, final String fieldName) {
Field res = null;
try {
res = (Field)AccessController.doPrivileged((PrivilegedExceptionAction) () -> {
Field f = clz.getDeclaredField(fieldName);
f.setAccessible(true);
return f;
});
} catch (PrivilegedActionException ex) {
ex.printStackTrace();
}
static Field getField(final Class clz, final String fieldName) throws NoSuchFieldException {
Field res = clz.getDeclaredField(fieldName);
res.setAccessible(true);
return res;
}

View File

@ -23,7 +23,6 @@
*/
import java.awt.*;
import java.security.PublicKey;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.CountDownLatch;

View File

@ -78,17 +78,6 @@ public class IndependenceAWTTest {
tf1.requestFocus();
}
public void checkSecurity() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
System.out.println("security manager is not there");
getPrimaryClipboard();
} else {
sm.checkPermission(new AWTPermission("accessClipboard"));
getPrimaryClipboard();
}
}
// Get System Selection i.e. Primary Clipboard
private void getPrimaryClipboard() {
Properties ps = System.getProperties();
@ -148,7 +137,7 @@ public class IndependenceAWTTest {
}
public void doTest() throws Exception {
checkSecurity();
getPrimaryClipboard();
ExtendedRobot robot = new ExtendedRobot();
robot.waitForIdle(1000);
frame.setLocation(100, 100);

View File

@ -85,17 +85,6 @@ public class IndependenceSwingTest {
tf1.requestFocus();
}
public void checkSecurity() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
System.out.println("security manager is not there");
getPrimaryClipboard();
} else {
sm.checkPermission(new AWTPermission("accessClipboard"));
getPrimaryClipboard();
}
}
// Get System Selection i.e. Primary Clipboard
private void getPrimaryClipboard() {
Properties ps = System.getProperties();
@ -155,7 +144,7 @@ public class IndependenceSwingTest {
}
public void doTest() throws Exception {
checkSecurity();
getPrimaryClipboard();
ExtendedRobot robot = new ExtendedRobot();
robot.waitForIdle(1000);
frame.setLocation(100, 100);

View File

@ -74,24 +74,6 @@ public class SystemSelectionAWTTest {
tf1.setText("Selection Testing");
}
// Check whether Security manager is there
public void checkSecurity() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
System.out.println("security manager is not there");
getPrimaryClipboard();
} else {
try {
sm.checkPermission(new AWTPermission("accessClipboard"));
getPrimaryClipboard();
} catch(SecurityException e) {
clip = null;
System.out.println("Access to System selection is not allowed");
}
}
}
// Get the contents from the clipboard
void getClipboardContent() throws Exception {
t = clip.getContents(this);
@ -134,7 +116,7 @@ public class SystemSelectionAWTTest {
Point tf1Location = tf1.getLocationOnScreen();
Dimension tf1Size = tf1.getSize();
checkSecurity();
getPrimaryClipboard();
if (clip != null) {
robot.mouseMove(tf1Location.x + 5, tf1Location.y + tf1Size.height / 2);

View File

@ -75,24 +75,6 @@ public class SystemSelectionSwingTest {
jtf1.setText("Selection Testing");
}
// Check whether Security manager is there
public void checkSecurity() {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
System.out.println("security manager is not there");
getPrimaryClipboard();
} else {
try {
sm.checkPermission(new AWTPermission("accessClipboard"));
getPrimaryClipboard();
} catch(SecurityException e) {
clip = null;
System.out.println("Access to System selection is not allowed");
}
}
}
// Get the contents from the clipboard
void getClipboardContent() throws Exception {
t = clip.getContents(this);
@ -136,7 +118,7 @@ public class SystemSelectionSwingTest {
Point tf1Location = jtf1.getLocationOnScreen();
Dimension tf1Size = jtf1.getSize();
checkSecurity();
getPrimaryClipboard();
if (clip != null) {
robot.mouseMove(tf1Location.x + 5, tf1Location.y + tf1Size.height / 2);

View File

@ -34,8 +34,6 @@
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
// get array InputEvent.BUTTON_MASK via reflection
// get array InputEvent.BUTTON_DOWN_MASK via reflection
@ -52,22 +50,18 @@ public class ButtonArraysEquality {
}
// getButtonDownMasks()
Object obj = AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
try {
Class clazz = Class.forName("java.awt.event.InputEvent");
Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
if (method != null) {
method.setAccessible(true);
return method.invoke(null, (Object[])null);
}
}catch (Exception e){
throw new RuntimeException("Test failed. Exception occured:", e);
}
return null;
}
});
Object obj = null;
try {
Class clazz = Class.forName("java.awt.event.InputEvent");
Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
if (method != null) {
method.setAccessible(true);
obj = method.invoke(null, (Object[])null);
}
} catch (Exception e) {
throw new RuntimeException("Test failed. Exception occurred:", e);
}
int [] buttonDownMasks = new int [Array.getLength(obj)];
checkNullAndPutValuesToArray(buttonDownMasks, obj);

View File

@ -34,8 +34,6 @@
import java.awt.*;
import java.awt.event.InputEvent;
import java.lang.reflect.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class CheckGetMaskForButton{
static Robot robot;
@ -50,22 +48,17 @@ public class CheckGetMaskForButton{
}
//get same array via reflection
Object obj = AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
try {
Class clazz = Class.forName("java.awt.event.InputEvent");
Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
if (method != null) {
method.setAccessible(true);
return method.invoke(null, (Object[])null);
}
}catch (Exception e){
throw new RuntimeException("Test failed. Exception occured:", e);
}
return null;
Object obj = null;
try {
Class clazz = Class.forName("java.awt.event.InputEvent");
Method method = clazz.getDeclaredMethod("getButtonDownMasks",new Class [] {});
if (method != null) {
method.setAccessible(true);
obj = method.invoke(null, (Object[])null);
}
});
} catch (Exception e) {
throw new RuntimeException("Test failed. Exception occured:", e);
}
if (obj == null){
throw new RuntimeException("Test failed. The value obtained via reflection is "+obj);

View File

@ -37,7 +37,6 @@ import java.awt.print.*;
import javax.print.PrintService;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import java.util.PropertyPermission;
public class PrintToDir extends Frame implements Printable {
@ -122,17 +121,6 @@ public class PrintToDir extends Frame implements Printable {
public static void main(String arg[]) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
System.out.println("Security manager detected");
try {
security.checkPermission(new FilePermission("<<ALL FILES>>", "read,write"));
security.checkPermission(new PropertyPermission("user.dir", "read"));
} catch (SecurityException se) {
System.out.println("Security requirement not obtained. TEST PASSED");
return;
}
}
String[] testStr = {".", ""};
for (int i=0; i<testStr.length; i++) {
System.out.println("Testing file name = \""+testStr[i]+"\"");

View File

@ -68,9 +68,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.PrivilegedAction;
import java.security.AccessController;
import java.util.concurrent.atomic.AtomicBoolean;
public final class Util {
@ -452,32 +449,19 @@ public final class Util {
Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.Module.class);
// We may be called from non-X11 system, and this permission cannot be delegated to a test.
m_addExports.invoke(null, "sun.awt.X11", Util.class.getModule());
@SuppressWarnings("removal")
Method m_getWMID = (Method)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
Method method = _clazz.getDeclaredMethod("getWMID", new Class[] {});
if (method != null) {
method.setAccessible(true);
}
return method;
} catch (NoSuchMethodException e) {
assert false;
} catch (SecurityException e) {
assert false;
}
return null;
}
});
return ((Integer)m_getWMID.invoke(null, new Object[] {})).intValue();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
} catch (NoSuchMethodException nsme) {
nsme.printStackTrace();
} catch (IllegalAccessException iae) {
iae.printStackTrace();
} catch (InvocationTargetException ite) {
ite.printStackTrace();
Method m_getWMID = null;
try {
m_getWMID = _clazz.getDeclaredMethod("getWMID", new Class[] {});
if (m_getWMID != null) {
m_getWMID.setAccessible(true);
}
} catch (NoSuchMethodException e) {
assert false;
}
return (Integer) m_getWMID.invoke(null, new Object[]{});
} catch (ClassNotFoundException | NoSuchMethodException
| IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return -1;
}

View File

@ -57,13 +57,7 @@ public class MetadataFormatThreadTest implements Runnable {
public void run() {
try {
ClassLoader loader = (ClassLoader)
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
ClassLoader loader = (ClassLoader) Thread.currentThread().getContextClassLoader();
Class ct = loader.loadClass(test_class);
@ -84,13 +78,7 @@ public class MetadataFormatThreadTest implements Runnable {
final ClassLoader loader = new URLClassLoader(urls);
final Thread t = new Thread(new MetadataFormatThreadTest(code));
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
t.setContextClassLoader(loader);
return null;
}
});
t.setContextClassLoader(loader);
return t;
}

View File

@ -258,12 +258,7 @@ esac
echo -------------------------------
echo --- Applet Classpath Test ---
echo -------------------------------
#
# please note that we need to use "==" in setup of the java.security.policy
# property in order to overwrite policies defined in the user policy file
# For more details see:
# http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html)
#
${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ".${PATHSEP}${TEST_PLUGIN_JAR}" IIOPluginTest

View File

@ -1,70 +0,0 @@
/*
* Copyright (c) 2009, 2024, 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.
*/
/*
* @test
* @bug 6795356
* @summary Leak caused by javax.swing.UIDefaults.ProxyLazyValue.acc
* @author Alexander Potochkin
* @library ../../regtesthelpers
* @build Util
* @run main/othervm -Xmx128m bug6795356
*/
import java.lang.ref.WeakReference;
import java.security.ProtectionDomain;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.AccessControlContext;
import java.util.LinkedList;
import java.util.List;
import javax.swing.*;
public class bug6795356 {
volatile static WeakReference<ProtectionDomain> weakRef;
public static void main(String[] args) throws Exception {
ProtectionDomain domain = new ProtectionDomain(null, null);
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
// this initialize ProxyLazyValues
UIManager.getLookAndFeel();
return null;
}
}, new AccessControlContext(new ProtectionDomain[]{domain}));
weakRef = new WeakReference<ProtectionDomain>(domain);
domain = null;
Util.generateOOME();
if (weakRef.get() != null) {
throw new RuntimeException("Memory leak found!");
}
System.out.println("Test passed");
}
}