Skip to content

Commit 959fa4a

Browse files
committedNov 28, 2024
8344299: SM cleanup in javax.naming modules
Reviewed-by: alanb, dfuchs
1 parent 43000a3 commit 959fa4a

24 files changed

+88
-382
lines changed
 

‎src/java.base/share/classes/sun/security/util/SecurityConstants.java

-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ private SecurityConstants () {
9696
public static final RuntimePermission GET_PD_PERMISSION =
9797
new RuntimePermission("getProtectionDomain");
9898

99-
// java.lang.Class, java.lang.ClassLoader, java.lang.Thread
100-
public static final RuntimePermission GET_CLASSLOADER_PERMISSION =
101-
new RuntimePermission("getClassLoader");
102-
10399
// java.lang.Thread
104100
public static final RuntimePermission GET_STACK_TRACE_PERMISSION =
105101
new RuntimePermission("getStackTrace");

‎src/java.naming/share/classes/com/sun/jndi/ldap/ClientId.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -84,8 +84,8 @@ class ClientId {
8484
if ((socketFactory != null) &&
8585
!socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) {
8686
try {
87-
Class<?> socketFactoryClass =
88-
Obj.helper.loadClass(socketFactory);
87+
Class<?> socketFactoryClass = Class.forName(socketFactory,
88+
true, Thread.currentThread().getContextClassLoader());
8989
this.sockComparator = socketFactoryClass.getMethod(
9090
"compare", new Class<?>[]{Object.class, Object.class});
9191
Method getDefault = socketFactoryClass.getMethod(

‎src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444

4545
import java.lang.reflect.Method;
4646
import java.lang.reflect.InvocationTargetException;
47-
import java.security.AccessController;
48-
import java.security.PrivilegedAction;
4947
import java.security.cert.Certificate;
5048
import java.security.cert.X509Certificate;
5149
import java.util.Arrays;
@@ -183,10 +181,8 @@ public final class Connection implements Runnable {
183181
= hostnameVerificationDisabledValue();
184182

185183
private static boolean hostnameVerificationDisabledValue() {
186-
PrivilegedAction<String> act = () -> System.getProperty(
184+
String prop = System.getProperty(
187185
"com.sun.jndi.ldap.object.disableEndpointIdentification");
188-
@SuppressWarnings("removal")
189-
String prop = AccessController.doPrivileged(act);
190186
if (prop == null) {
191187
return false;
192188
}
@@ -259,7 +255,7 @@ void setBound() {
259255
throw ce;
260256
}
261257

262-
worker = Obj.helper.createThread(this);
258+
worker = new Thread(this);
263259
worker.setDaemon(true);
264260
worker.start();
265261
}
@@ -313,7 +309,8 @@ private SocketFactory getSocketFactory(String socketFactoryName) throws Exceptio
313309
}
314310
@SuppressWarnings("unchecked")
315311
Class<? extends SocketFactory> socketFactoryClass =
316-
(Class<? extends SocketFactory>) Obj.helper.loadClass(socketFactoryName);
312+
(Class<? extends SocketFactory>) Class.forName(socketFactoryName,
313+
true, Thread.currentThread().getContextClassLoader());
317314
Method getDefault =
318315
socketFactoryClass.getMethod("getDefault");
319316
SocketFactory factory = (SocketFactory) getDefault.invoke(null, new Object[]{});

‎src/java.naming/share/classes/com/sun/jndi/ldap/EventQueue.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private static class QueueElement {
7171

7272
// package private
7373
EventQueue() {
74-
qThread = Obj.helper.createThread(this);
74+
qThread = new Thread(this);
7575
qThread.setDaemon(true); // not a user thread
7676
qThread.start();
7777
}

‎src/java.naming/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 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,10 +25,6 @@
2525

2626
package com.sun.jndi.ldap;
2727

28-
import java.security.AccessControlContext;
29-
import java.security.AccessController;
30-
import java.security.PrivilegedActionException;
31-
import java.security.PrivilegedExceptionAction;
3228
import java.util.Vector;
3329
import javax.naming.*;
3430
import javax.naming.directory.*;
@@ -41,16 +37,12 @@
4137
final class LdapBindingEnumeration
4238
extends AbstractLdapNamingEnumeration<Binding> {
4339

44-
@SuppressWarnings("removal")
45-
private final AccessControlContext acc = AccessController.getContext();
46-
4740
LdapBindingEnumeration(LdapCtx homeCtx, LdapResult answer, Name remain,
4841
Continuation cont) throws NamingException
4942
{
5043
super(homeCtx, answer, remain, cont);
5144
}
5245

53-
@SuppressWarnings("removal")
5446
@Override
5547
protected Binding
5648
createItem(String dn, Attributes attrs, Vector<Control> respCtls)
@@ -61,12 +53,7 @@ final class LdapBindingEnumeration
6153

6254
if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) {
6355
// serialized object or object reference
64-
try {
65-
PrivilegedExceptionAction<Object> pa = () -> Obj.decodeObject(attrs);
66-
obj = AccessController.doPrivileged(pa, acc);
67-
} catch (PrivilegedActionException e) {
68-
throw (NamingException)e.getException();
69-
}
56+
obj = Obj.decodeObject(attrs);
7057
}
7158
if (obj == null) {
7259
// DirContext object

‎src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 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
@@ -32,8 +32,6 @@
3232
import javax.naming.ldap.LdapName;
3333
import javax.naming.ldap.Rdn;
3434

35-
import java.security.AccessController;
36-
import java.security.PrivilegedAction;
3735
import java.util.Arrays;
3836
import java.util.Collections;
3937
import java.util.Locale;
@@ -220,7 +218,7 @@ static final class SearchArgs {
220218

221219
// System property value
222220
private static final String ALLOWED_MECHS_SP_VALUE =
223-
getMechsAllowedToSendCredentials();
221+
System.getProperty(ALLOWED_MECHS_SP);
224222

225223
// Set of authentication mechanisms allowed by the system property
226224
private static final Set<String> MECHS_ALLOWED_BY_SP =
@@ -2706,13 +2704,6 @@ public void reconnect(Control[] connCtls) throws NamingException {
27062704
ensureOpen(); // open or reauthenticated
27072705
}
27082706

2709-
// Load 'mechsAllowedToSendCredentials' system property value
2710-
@SuppressWarnings("removal")
2711-
private static String getMechsAllowedToSendCredentials() {
2712-
PrivilegedAction<String> pa = () -> System.getProperty(ALLOWED_MECHS_SP);
2713-
return System.getSecurityManager() == null ? pa.run() : AccessController.doPrivileged(pa);
2714-
}
2715-
27162707
// Get set of allowed authentication mechanism names from the property value
27172708
private static Set<String> getMechsFromPropertyValue(String propValue) {
27182709
if (propValue == null || propValue.isBlank()) {

‎src/java.naming/share/classes/com/sun/jndi/ldap/LdapDnsProviderService.java

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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,14 +25,11 @@
2525

2626
package com.sun.jndi.ldap;
2727

28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
3028
import java.util.*;
3129
import java.util.concurrent.locks.ReentrantLock;
3230
import javax.naming.NamingException;
3331
import javax.naming.ldap.spi.LdapDnsProvider;
3432
import javax.naming.ldap.spi.LdapDnsProviderResult;
35-
import sun.security.util.SecurityConstants;
3633

3734
/**
3835
* The {@code LdapDnsProviderService} is responsible for creating and providing
@@ -50,25 +47,10 @@ final class LdapDnsProviderService {
5047
/**
5148
* Creates a new instance of LdapDnsProviderService
5249
*/
53-
@SuppressWarnings("removal")
5450
private LdapDnsProviderService() {
55-
SecurityManager sm = System.getSecurityManager();
56-
if (sm == null) {
57-
providers = ServiceLoader.load(
58-
LdapDnsProvider.class,
59-
ClassLoader.getSystemClassLoader());
60-
} else {
61-
final PrivilegedAction<ServiceLoader<LdapDnsProvider>> pa =
62-
() -> ServiceLoader.load(
63-
LdapDnsProvider.class,
64-
ClassLoader.getSystemClassLoader());
65-
66-
providers = AccessController.doPrivileged(
67-
pa,
68-
null,
69-
new RuntimePermission("ldapDnsProvider"),
70-
SecurityConstants.GET_CLASSLOADER_PERMISSION);
71-
}
51+
providers = ServiceLoader.load(
52+
LdapDnsProvider.class,
53+
ClassLoader.getSystemClassLoader());
7254
}
7355

7456
/**

‎src/java.naming/share/classes/com/sun/jndi/ldap/LdapPoolManager.java

+18-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -34,8 +34,6 @@
3434
import javax.naming.ldap.Control;
3535
import javax.naming.NamingException;
3636
import javax.naming.CommunicationException;
37-
import java.security.AccessController;
38-
import java.security.PrivilegedAction;
3937

4038
import com.sun.jndi.ldap.pool.PoolCleaner;
4139
import com.sun.jndi.ldap.pool.Pool;
@@ -60,10 +58,10 @@ public final class LdapPoolManager {
6058
"com.sun.jndi.ldap.connect.pool.debug";
6159

6260
public static final boolean debug =
63-
"all".equalsIgnoreCase(getProperty(DEBUG, null));
61+
"all".equalsIgnoreCase(System.getProperty(DEBUG));
6462

6563
public static final boolean trace = debug ||
66-
"fine".equalsIgnoreCase(getProperty(DEBUG, null));
64+
"fine".equalsIgnoreCase(System.getProperty(DEBUG));
6765

6866
// ---------- System properties for connection pooling
6967

@@ -120,16 +118,16 @@ public final class LdapPoolManager {
120118
private static final Pool[] pools = new Pool[3];
121119

122120
static {
123-
maxSize = getInteger(MAX_POOL_SIZE, DEFAULT_MAX_POOL_SIZE);
121+
maxSize = Integer.getInteger(MAX_POOL_SIZE, DEFAULT_MAX_POOL_SIZE);
124122

125-
prefSize = getInteger(PREF_POOL_SIZE, DEFAULT_PREF_POOL_SIZE);
123+
prefSize = Integer.getInteger(PREF_POOL_SIZE, DEFAULT_PREF_POOL_SIZE);
126124

127-
initSize = getInteger(INIT_POOL_SIZE, DEFAULT_INIT_POOL_SIZE);
125+
initSize = Integer.getInteger(INIT_POOL_SIZE, DEFAULT_INIT_POOL_SIZE);
128126

129-
idleTimeout = getLong(POOL_TIMEOUT, DEFAULT_TIMEOUT);
127+
idleTimeout = Long.getLong(POOL_TIMEOUT, DEFAULT_TIMEOUT);
130128

131129
// Determine supported authentication mechanisms
132-
String str = getProperty(POOL_AUTH, DEFAULT_AUTH_MECHS);
130+
String str = System.getProperty(POOL_AUTH, DEFAULT_AUTH_MECHS);
133131
StringTokenizer parser = new StringTokenizer(str);
134132
int count = parser.countTokens();
135133
String mech;
@@ -147,7 +145,7 @@ public final class LdapPoolManager {
147145
}
148146

149147
// Determine supported protocols
150-
str= getProperty(POOL_PROTOCOL, DEFAULT_PROTOCOLS);
148+
str = System.getProperty(POOL_PROTOCOL, DEFAULT_PROTOCOLS);
151149
parser = new StringTokenizer(str);
152150
count = parser.countTokens();
153151
String proto;
@@ -171,20 +169,15 @@ public final class LdapPoolManager {
171169
}
172170
}
173171

174-
@SuppressWarnings("removal")
175172
private static void startCleanerThread() {
176173
// Create cleaner to expire idle connections
177-
PrivilegedAction<Void> pa = new PrivilegedAction<Void>() {
178-
public Void run() {
179-
Thread t = InnocuousThread.newSystemThread(
180-
"LDAP PoolCleaner",
181-
new PoolCleaner(idleTimeout, pools));
182-
assert t.getContextClassLoader() == null;
183-
t.setDaemon(true);
184-
t.start();
185-
return null;
186-
}};
187-
AccessController.doPrivileged(pa);
174+
Thread t = InnocuousThread.newSystemThread(
175+
"LDAP PoolCleaner",
176+
new PoolCleaner(idleTimeout, pools));
177+
assert t.getContextClassLoader() == null;
178+
t.setDaemon(true);
179+
t.start();
180+
188181
}
189182

190183
// Cannot instantiate one of these
@@ -252,7 +245,8 @@ static boolean isPoolingAllowed(String socketFactory, OutputStream trace,
252245
if ((socketFactory != null) &&
253246
!socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) {
254247
try {
255-
Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory);
248+
Class<?> socketFactoryClass = Class.forName(socketFactory, true,
249+
Thread.currentThread().getContextClassLoader());
256250
Class<?>[] interfaces = socketFactoryClass.getInterfaces();
257251
for (int i = 0; i < interfaces.length; i++) {
258252
if (interfaces[i].getCanonicalName().equals(COMPARATOR)) {
@@ -399,22 +393,4 @@ private static void d(String msg, String o) {
399393
System.err.println("LdapPoolManager: " + msg + o);
400394
}
401395
}
402-
403-
@SuppressWarnings("removal")
404-
private static final String getProperty(final String propName, final String defVal) {
405-
PrivilegedAction<String> pa = () -> System.getProperty(propName, defVal);
406-
return AccessController.doPrivileged(pa);
407-
}
408-
409-
@SuppressWarnings("removal")
410-
private static final int getInteger(final String propName, final int defVal) {
411-
PrivilegedAction<Integer> pa = () -> Integer.getInteger(propName, defVal);
412-
return AccessController.doPrivileged(pa);
413-
}
414-
415-
@SuppressWarnings("removal")
416-
private static final long getLong(final String propName, final long defVal) {
417-
PrivilegedAction<Long> pa = () -> Long.getLong(propName, defVal);
418-
return AccessController.doPrivileged(pa);
419-
}
420396
}

‎src/java.naming/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 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,10 +25,6 @@
2525

2626
package com.sun.jndi.ldap;
2727

28-
import java.security.AccessControlContext;
29-
import java.security.AccessController;
30-
import java.security.PrivilegedActionException;
31-
import java.security.PrivilegedExceptionAction;
3228
import java.util.Vector;
3329
import javax.naming.*;
3430
import javax.naming.directory.*;
@@ -45,9 +41,6 @@ final class LdapSearchEnumeration
4541
private Name startName; // prefix of names of search results
4642
private LdapCtx.SearchArgs searchArgs = null;
4743

48-
@SuppressWarnings("removal")
49-
private final AccessControlContext acc = AccessController.getContext();
50-
5144
LdapSearchEnumeration(LdapCtx homeCtx, LdapResult search_results,
5245
String starter, LdapCtx.SearchArgs args, Continuation cont)
5346
throws NamingException {
@@ -61,7 +54,6 @@ final class LdapSearchEnumeration
6154
searchArgs = args;
6255
}
6356

64-
@SuppressWarnings("removal")
6557
@Override
6658
protected SearchResult createItem(String dn, Attributes attrs,
6759
Vector<Control> respCtls)
@@ -121,12 +113,7 @@ protected SearchResult createItem(String dn, Attributes attrs,
121113
if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) {
122114
// Entry contains Java-object attributes (ser/ref object)
123115
// serialized object or object reference
124-
try {
125-
PrivilegedExceptionAction<Object> pea = () -> Obj.decodeObject(attrs);
126-
obj = AccessController.doPrivileged(pea, acc);
127-
} catch (PrivilegedActionException e) {
128-
throw (NamingException)e.getException();
129-
}
116+
obj = Obj.decodeObject(attrs);
130117
}
131118
if (obj == null) {
132119
obj = new LdapCtx(homeCtx, dn);

0 commit comments

Comments
 (0)
Please sign in to comment.