Skip to content

Commit d85dd77

Browse files
author
Eirik Bjørsnøs
committed
8344365: SecurityManager cleanups in java.sql and java.sql.rowset modules
Reviewed-by: rriggs, bchristi
1 parent 9e92a9e commit d85dd77

File tree

9 files changed

+54
-397
lines changed

9 files changed

+54
-397
lines changed

src/java.sql.rowset/share/classes/com/sun/rowset/CachedRowSetImpl.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,16 +31,12 @@
3131
import java.math.*;
3232
import java.util.*;
3333
import java.text.*;
34-
import java.security.AccessController;
35-
import java.security.PrivilegedActionException;
36-
import java.security.PrivilegedExceptionAction;
3734

3835
import javax.sql.rowset.*;
3936
import javax.sql.rowset.spi.*;
4037
import javax.sql.rowset.serial.*;
4138
import com.sun.rowset.internal.*;
4239
import com.sun.rowset.providers.*;
43-
import sun.reflect.misc.ReflectUtil;
4440

4541
import static java.nio.charset.StandardCharsets.US_ASCII;
4642

@@ -357,7 +353,6 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern
357353
* <P>
358354
* @throws SQLException if an error occurs
359355
*/
360-
@SuppressWarnings("removal")
361356
public CachedRowSetImpl() throws SQLException {
362357

363358
try {
@@ -367,16 +362,7 @@ public CachedRowSetImpl() throws SQLException {
367362
}
368363

369364
// set the Reader, this maybe overridden latter
370-
try {
371-
provider = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
372-
@Override
373-
public SyncProvider run() throws SyncFactoryException {
374-
return SyncFactory.getInstance(DEFAULT_SYNC_PROVIDER);
375-
}
376-
}, null, new RuntimePermission("accessClassInPackage.com.sun.rowset.providers"));
377-
} catch (PrivilegedActionException pae) {
378-
throw (SyncFactoryException) pae.getException();
379-
}
365+
provider = SyncFactory.getInstance(DEFAULT_SYNC_PROVIDER);
380366

381367
if (!(provider instanceof RIOptimisticProvider)) {
382368
throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidp").toString());
@@ -2976,7 +2962,6 @@ public Object getObject(int columnIndex) throws SQLException {
29762962
// create new instance of the class
29772963
SQLData obj = null;
29782964
try {
2979-
ReflectUtil.checkPackageAccess(c);
29802965
@SuppressWarnings("deprecation")
29812966
Object tmp = c.newInstance();
29822967
obj = (SQLData) tmp;
@@ -5726,7 +5711,6 @@ public Object getObject(int columnIndex,
57265711
// create new instance of the class
57275712
SQLData obj = null;
57285713
try {
5729-
ReflectUtil.checkPackageAccess(c);
57305714
@SuppressWarnings("deprecation")
57315715
Object tmp = c.newInstance();
57325716
obj = (SQLData) tmp;

src/java.sql.rowset/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,6 @@
2929
import javax.sql.*;
3030
import java.util.*;
3131
import java.io.*;
32-
import sun.reflect.misc.ReflectUtil;
3332

3433
import com.sun.rowset.*;
3534
import java.text.MessageFormat;
@@ -575,7 +574,6 @@ private boolean updateOriginalRow(CachedRowSet crs)
575574
// create new instance of the class
576575
SQLData obj = null;
577576
try {
578-
ReflectUtil.checkPackageAccess(c);
579577
@SuppressWarnings("deprecation")
580578
Object tmp = c.newInstance();
581579
obj = (SQLData)tmp;

src/java.sql.rowset/share/classes/javax/sql/rowset/RowSetProvider.java

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,13 +25,9 @@
2525

2626
package javax.sql.rowset;
2727

28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
3028
import java.sql.SQLException;
31-
import java.util.PropertyPermission;
3229
import java.util.ServiceConfigurationError;
3330
import java.util.ServiceLoader;
34-
import sun.reflect.misc.ReflectUtil;
3531

3632
/**
3733
* A factory API that enables applications to obtain a
@@ -68,7 +64,7 @@ public class RowSetProvider {
6864

6965
static {
7066
// Check to see if the debug property is set
71-
String val = getSystemProperty(ROWSET_DEBUG_PROPERTY);
67+
String val = System.getProperty(ROWSET_DEBUG_PROPERTY);
7268
// Allow simply setting the prop to turn on debug
7369
debug = val != null && !"false".equals(val);
7470
}
@@ -128,7 +124,8 @@ public static RowSetFactory newFactory()
128124
String factoryClassName = null;
129125
try {
130126
trace("Checking for Rowset System Property...");
131-
factoryClassName = getSystemProperty(ROWSET_FACTORY_NAME);
127+
128+
factoryClassName = System.getProperty(ROWSET_FACTORY_NAME);
132129
if (factoryClassName != null) {
133130
trace("Found system property, value=" + factoryClassName);
134131
if (factoryClassName.equals(ROWSET_FACTORY_IMPL)) {
@@ -193,11 +190,6 @@ public static RowSetFactory newFactory(String factoryClassName, ClassLoader cl)
193190
if(factoryClassName == null) {
194191
throw new SQLException("Error: factoryClassName cannot be null");
195192
}
196-
try {
197-
ReflectUtil.checkPackageAccess(factoryClassName);
198-
} catch (@SuppressWarnings("removal") java.security.AccessControlException e) {
199-
throw new SQLException("Access Exception",e);
200-
}
201193

202194
try {
203195
// getFactoryClass takes care of adding the read edge if
@@ -225,22 +217,14 @@ public static RowSetFactory newFactory(String factoryClassName, ClassLoader cl)
225217
* @return The ClassLoader to use.
226218
*
227219
*/
228-
@SuppressWarnings("removal")
229-
private static ClassLoader getContextClassLoader() throws SecurityException {
230-
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
231-
232-
public ClassLoader run() {
233-
ClassLoader cl = null;
234-
235-
cl = Thread.currentThread().getContextClassLoader();
220+
private static ClassLoader getContextClassLoader() {
221+
ClassLoader cl = Thread.currentThread().getContextClassLoader();
236222

237-
if (cl == null) {
238-
cl = ClassLoader.getSystemClassLoader();
239-
}
223+
if (cl == null) {
224+
cl = ClassLoader.getSystemClassLoader();
225+
}
240226

241-
return cl;
242-
}
243-
});
227+
return cl;
244228
}
245229

246230
/**
@@ -276,7 +260,6 @@ private static Class<?> getFactoryClass(String factoryClassName, ClassLoader cl,
276260
}
277261
}
278262

279-
ReflectUtil.checkPackageAccess(factoryClass);
280263
return factoryClass;
281264
}
282265

@@ -302,32 +285,6 @@ private static RowSetFactory loadViaServiceLoader() throws SQLException {
302285

303286
}
304287

305-
/**
306-
* Returns the requested System Property. If a {@code SecurityException}
307-
* occurs, just return NULL
308-
* @param propName - System property to retrieve
309-
* @return The System property value or NULL if the property does not exist
310-
* or a {@code SecurityException} occurs.
311-
*/
312-
@SuppressWarnings("removal")
313-
private static String getSystemProperty(final String propName) {
314-
String property = null;
315-
try {
316-
property = AccessController.doPrivileged(new PrivilegedAction<String>() {
317-
318-
public String run() {
319-
return System.getProperty(propName);
320-
}
321-
}, null, new PropertyPermission(propName, "read"));
322-
} catch (SecurityException se) {
323-
trace("error getting " + propName + ": "+ se);
324-
if (debug) {
325-
se.printStackTrace();
326-
}
327-
}
328-
return property;
329-
}
330-
331288
/**
332289
* Debug routine which will output tracing if the System Property
333290
* -Djavax.sql.rowset.RowSetFactory.debug is set

src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SQLInputImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
2727
import java.sql.*;
2828
import java.util.Arrays;
2929
import java.util.Map;
30-
import sun.reflect.misc.ReflectUtil;
3130

3231
/**
3332
* An input stream used for custom mapping user-defined types (UDTs).
@@ -477,7 +476,6 @@ public Object readObject() throws SQLException {
477476
// create new instance of the class
478477
SQLData obj = null;
479478
try {
480-
ReflectUtil.checkPackageAccess(c);
481479
@SuppressWarnings("deprecation")
482480
Object tmp = c.newInstance();
483481
obj = (SQLData)tmp;

src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialJavaObject.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
import java.util.Arrays;
3131
import java.util.Vector;
3232
import javax.sql.rowset.RowSetWarning;
33-
import jdk.internal.reflect.CallerSensitive;
34-
import jdk.internal.reflect.Reflection;
35-
import sun.reflect.misc.ReflectUtil;
3633

3734
/**
3835
* A serializable mapping in the Java programming language of an SQL
@@ -125,23 +122,9 @@ public Object getObject() throws SerialException {
125122
* the serialized object
126123
* @see Class#getFields
127124
*/
128-
@CallerSensitive
129125
public Field[] getFields() throws SerialException {
130126
if (fields != null) {
131127
Class<?> c = this.obj.getClass();
132-
@SuppressWarnings("removal")
133-
SecurityManager sm = System.getSecurityManager();
134-
if (sm != null) {
135-
/*
136-
* Check if the caller is allowed to access the specified class's package.
137-
* If access is denied, throw a SecurityException.
138-
*/
139-
Class<?> caller = Reflection.getCallerClass();
140-
if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(),
141-
c.getClassLoader())) {
142-
ReflectUtil.checkPackageAccess(c);
143-
}
144-
}
145128
return c.getFields();
146129
} else {
147130
throw new SerialException("SerialJavaObject does not contain" +

0 commit comments

Comments
 (0)