Skip to content

Commit

Permalink
8345223: Remove doPrivileged in java.base/unix/classes/sun/net and ja…
Browse files Browse the repository at this point in the history
…va.base/macosx/classes/java/net classes after JEP 486 integration
  • Loading branch information
dfuch committed Nov 28, 2024
1 parent 959fa4a commit bd74dd7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 75 deletions.
6 changes: 1 addition & 5 deletions src/java.base/macosx/classes/java/net/DefaultInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package java.net;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.io.IOException;

Expand Down Expand Up @@ -105,9 +103,7 @@ private static NetworkInterface chooseDefaultInterface() {
continue;

boolean ip4 = false, ip6 = false, isNonLinkLocal = false;
PrivilegedAction<Enumeration<InetAddress>> pa = ni::getInetAddresses;
@SuppressWarnings("removal")
Enumeration<InetAddress> addrs = AccessController.doPrivileged(pa);
Enumeration<InetAddress> addrs = ni.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();
if (!addr.isAnyLocalAddress()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ private ArrayList<String> resolvconf(String keyword,

// Load DNS configuration from OS

@SuppressWarnings("removal")
private void loadConfig() {
assert Thread.holdsLock(lock);

Expand All @@ -130,15 +129,9 @@ private void loadConfig() {
}

// get the name servers from /etc/resolv.conf
nameservers =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public ArrayList<String> run() {
// typically MAXNS is 3 but we've picked 5 here
// to allow for additional servers if required.
return resolvconf("nameserver", 1, 5);
} /* run */
});
// typically MAXNS is 3 but we've picked 5 here
// to allow for additional servers if required.
nameservers = resolvconf("nameserver", 1, 5);

// get the search list (or domain)
searchlist = getSearchList();
Expand All @@ -149,54 +142,19 @@ public ArrayList<String> run() {


// obtain search list or local domain

@SuppressWarnings("removal")
private ArrayList<String> getSearchList() {

ArrayList<String> sl;

// first try the search keyword in /etc/resolv.conf

sl = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public ArrayList<String> run() {
ArrayList<String> ll;

// first try search keyword (max 6 domains)
ll = resolvconf("search", 6, 1);
if (ll.size() > 0) {
return ll;
}

return null;

} /* run */

});
if (sl != null) {
return sl;
}
// first try search keyword (max 6 domains)
ArrayList<String> sl = resolvconf("search", 6, 1);
if (sl.size() > 0) return sl;

// No search keyword so use local domain

// try domain keyword in /etc/resolv.conf

sl = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public ArrayList<String> run() {
ArrayList<String> ll;

ll = resolvconf("domain", 1, 1);
if (ll.size() > 0) {
return ll;
}
return null;

} /* run */
});
if (sl != null) {
return sl;
}
sl = resolvconf("domain", 1, 1);
if (sl.size() > 0) return sl;

// no local domain so try fallback (RPC) domain or
// hostName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,22 @@
public final class NTLMAuthentication extends AuthenticationInfo {

private static final NTLMAuthenticationCallback NTLMAuthCallback =
NTLMAuthenticationCallback.getNTLMAuthenticationCallback();
NTLMAuthenticationCallback.getNTLMAuthenticationCallback();

private String hostname;
/* Domain to use if not specified by user */
private static final String defaultDomain;
/* Whether cache is enabled for NTLM */
private static final boolean ntlmCache;

static {
Properties props = GetPropertyAction.privilegedGetProperties();
defaultDomain = props.getProperty("http.auth.ntlm.domain", "");
String ntlmCacheProp = props.getProperty("jdk.ntlm.cache", "true");
ntlmCache = Boolean.parseBoolean(ntlmCacheProp);
}

public static boolean supportsTransparentAuth () {
public static boolean supportsTransparentAuth() {
return false;
}

Expand All @@ -101,23 +102,6 @@ public static boolean isTrustedSite(URL url) {
return false;
}

@SuppressWarnings("removal")
private void init0() {

hostname = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public String run() {
String localhost;
try {
localhost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
localhost = "localhost";
}
return localhost;
}
});
};

PasswordAuthentication pw;

Client client;
Expand Down Expand Up @@ -150,7 +134,11 @@ private void init (PasswordAuthentication pw) {
username = s.substring (i+1);
}
password = pw.getPassword();
init0();
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
hostname = "localhost";
}
try {
String version = GetPropertyAction.privilegedGetProperty("ntlm.version");
client = new Client(version, hostname, username, ntdomain, password);
Expand Down

0 comments on commit bd74dd7

Please sign in to comment.