Skip to content

Commit

Permalink
fix: Update to JDK21 - EXO-71474 - Meeds-io/MIPs#91
Browse files Browse the repository at this point in the history
Remove usage of SecurityManager as it is deprecated for removal in jdk21
Remove also usage of classes
- SecurityHelper
- PrivilegedSystemHelper
- PrivilegedFileHelper
- SecureList
- SecureSet
- SecureCollections

These classes are here only to use securityManager, and as it is removed, it is no more necessary

Resolves Meeds-io/MIPs#91
  • Loading branch information
rdenarie committed May 16, 2024
1 parent 8420ed0 commit 8c42501
Show file tree
Hide file tree
Showing 28 changed files with 103 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.File;
Expand Down Expand Up @@ -285,7 +283,7 @@ public final static char[] uuencode(byte[] data)
int line_len = 45; // line length, in octets

int sidx, didx;
char nl[] = PrivilegedSystemHelper.getProperty("line.separator", "\n").toCharArray(), dest[] =
char nl[] = System.getProperty("line.separator", "\n").toCharArray(), dest[] =
new char[(data.length + 2) / 3 * 4 + ((data.length + line_len - 1) / line_len) * (nl.length + 1)];

// split into lines, adding line-length and line terminator
Expand Down Expand Up @@ -416,7 +414,7 @@ public final static String quotedPrintableEncode(String str)
return null;

char map[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}, nl[] =
PrivilegedSystemHelper.getProperty("line.separator", "\n").toCharArray(), res[] =
System.getProperty("line.separator", "\n").toCharArray(), res[] =
new char[(int)(str.length() * 1.5)], src[] =
str.toCharArray();
char ch;
Expand Down Expand Up @@ -501,7 +499,7 @@ public final static String quotedPrintableDecode(String str) throws ParseExcepti
return null;

char res[] = new char[(int)(str.length() * 1.1)], src[] = str.toCharArray(), nl[] =
PrivilegedSystemHelper.getProperty("line.separator", "\n").toCharArray();
System.getProperty("line.separator", "\n").toCharArray();
int last = 0, didx = 0, slen = str.length();

for (int sidx = 0; sidx < slen;)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

Expand Down Expand Up @@ -213,7 +212,7 @@ private static String getCookieJarName()

try
{
file = PrivilegedSystemHelper.getProperty("HTTPClient.cookies.jar");
file = System.getProperty("HTTPClient.cookies.jar");
}
catch (Exception e)
{
Expand All @@ -227,19 +226,19 @@ private static String getCookieJarName()
{
// default to something reasonable

String os = PrivilegedSystemHelper.getProperty("os.name");
String os = System.getProperty("os.name");
if (os.equalsIgnoreCase("Windows 95") || os.equalsIgnoreCase("16-bit Windows")
|| os.equalsIgnoreCase("Windows"))
{
file = PrivilegedSystemHelper.getProperty("java.home") + File.separator + ".httpclient_cookies";
file = System.getProperty("java.home") + File.separator + ".httpclient_cookies";
}
else if (os.equalsIgnoreCase("Windows NT"))
{
file = PrivilegedSystemHelper.getProperty("user.home") + File.separator + ".httpclient_cookies";
file = System.getProperty("user.home") + File.separator + ".httpclient_cookies";
}
else if (os.equalsIgnoreCase("OS/2"))
{
file = PrivilegedSystemHelper.getProperty("user.home") + File.separator + ".httpclient_cookies";
file = System.getProperty("user.home") + File.separator + ".httpclient_cookies";
}
else if (os.equalsIgnoreCase("Mac OS") || os.equalsIgnoreCase("MacOS"))
{
Expand All @@ -248,7 +247,7 @@ else if (os.equalsIgnoreCase("Mac OS") || os.equalsIgnoreCase("MacOS"))
else
// it's probably U*IX or VMS
{
file = PrivilegedSystemHelper.getProperty("user.home") + File.separator + ".httpclient_cookies";
file = System.getProperty("user.home") + File.separator + ".httpclient_cookies";
}
}

Expand Down Expand Up @@ -671,7 +670,7 @@ class DefaultCookiePolicyHandler implements CookiePolicyHandler

try
{
list = PrivilegedSystemHelper.getProperty("HTTPClient.cookies.hosts.accept");
list = System.getProperty("HTTPClient.cookies.hosts.accept");
}
catch (Exception e)
{
Expand All @@ -683,7 +682,7 @@ class DefaultCookiePolicyHandler implements CookiePolicyHandler

try
{
list = PrivilegedSystemHelper.getProperty("HTTPClient.cookies.hosts.reject");
list = System.getProperty("HTTPClient.cookies.hosts.reject");
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

Expand Down Expand Up @@ -1518,7 +1517,7 @@ synchronized NVPair getInput(String l1, String l2, String l3, String scheme)
// prefill the user field with the username
try
{
user.setText(PrivilegedSystemHelper.getProperty("user.name", ""));
user.setText(System.getProperty("user.name", ""));
user_focus = false;
}
catch (SecurityException se)
Expand Down Expand Up @@ -1633,7 +1632,7 @@ public NVPair getUsernamePassword(AuthorizationInfo challenge, boolean forProxy)
*/
private static void echo(boolean on)
{
String os = PrivilegedSystemHelper.getProperty("os.name");
String os = System.getProperty("os.name");
String[] cmd = null;

if (os.equalsIgnoreCase("Windows 95") || os.equalsIgnoreCase("Windows NT"))
Expand Down Expand Up @@ -1670,7 +1669,7 @@ else if (os.equalsIgnoreCase("OpenVMS") || os.equalsIgnoreCase("VMS"))
*/
static boolean canUseCLPrompt()
{
String os = PrivilegedSystemHelper.getProperty("os.name");
String os = System.getProperty("os.name");

return (os.indexOf("Linux") >= 0 || os.indexOf("SunOS") >= 0 || os.indexOf("Solaris") >= 0
|| os.indexOf("BSD") >= 0 || os.indexOf("AIX") >= 0 || os.indexOf("HP-UX") >= 0 || os.indexOf("IRIX") >= 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.ClassLoading;
import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

import java.applet.Applet;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.FilterOutputStream;
Expand Down Expand Up @@ -317,7 +315,7 @@ public class HTTPConnection implements GlobalConstants, HTTPClientModuleConstant
try
// JDK 1.1 naming
{
String host = PrivilegedSystemHelper.getProperty("http.proxyHost");
String host = System.getProperty("http.proxyHost");
if (host == null)
throw new Exception(); // try JDK 1.0.x naming
int port = Integer.getInteger("http.proxyPort", -1).intValue();
Expand All @@ -336,7 +334,7 @@ public class HTTPConnection implements GlobalConstants, HTTPClientModuleConstant
{
if (Boolean.getBoolean("proxySet"))
{
String host = PrivilegedSystemHelper.getProperty("proxyHost");
String host = System.getProperty("proxyHost");
int port = Integer.getInteger("proxyPort", -1).intValue();

if (LOG.isDebugEnabled())
Expand All @@ -358,10 +356,10 @@ public class HTTPConnection implements GlobalConstants, HTTPClientModuleConstant
*/
try
{
String hosts = PrivilegedSystemHelper.getProperty("HTTPClient.nonProxyHosts");
String hosts = System.getProperty("HTTPClient.nonProxyHosts");
if (hosts == null)
{
hosts = PrivilegedSystemHelper.getProperty("http.nonProxyHosts");
hosts = System.getProperty("http.nonProxyHosts");
}

String[] list = Util.splitProperty(hosts);
Expand All @@ -383,7 +381,7 @@ public class HTTPConnection implements GlobalConstants, HTTPClientModuleConstant
*/
try
{
String host = PrivilegedSystemHelper.getProperty("HTTPClient.socksHost");
String host = System.getProperty("HTTPClient.socksHost");
if (host != null && host.length() > 0)
{
int port = Integer.getInteger("HTTPClient.socksPort", -1).intValue();
Expand Down Expand Up @@ -432,7 +430,7 @@ public class HTTPConnection implements GlobalConstants, HTTPClientModuleConstant
boolean in_applet = false;
try
{
modules = PrivilegedSystemHelper.getProperty("HTTPClient.Modules", modules);
modules = System.getProperty("HTTPClient.Modules", modules);
}
catch (SecurityException se)
{
Expand Down Expand Up @@ -562,8 +560,8 @@ public class HTTPConnection implements GlobalConstants, HTTPClientModuleConstant
*/
try
{
if (PrivilegedSystemHelper.getProperty("os.name").indexOf("Windows") >= 0
&& PrivilegedSystemHelper.getProperty("java.version").startsWith("1.1"))
if (System.getProperty("os.name").indexOf("Windows") >= 0
&& System.getProperty("java.version").startsWith("1.1"))
{
haveMSLargeWritesBug = true;
}
Expand Down Expand Up @@ -611,15 +609,6 @@ public class HTTPConnection implements GlobalConstants, HTTPClientModuleConstant

// Constructors

/**
* Constructs a connection to the host from where the applet was loaded. Note
* that current security policies only let applets connect home.
* @param applet the current applet
*/
public HTTPConnection(Applet applet) throws ProtocolNotSuppException
{
this(applet.getCodeBase().getProtocol(), applet.getCodeBase().getHost(), applet.getCodeBase().getPort());
}

/**
* Constructs a connection to the specified host on port 80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

Expand Down Expand Up @@ -662,7 +661,7 @@ public String toString()
}
}

String nl = PrivilegedSystemHelper.getProperty("line.separator", "\n");
String nl = System.getProperty("line.separator", "\n");

StringBuffer str = new StringBuffer(Version);
str.append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.ClassLoading;
import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

Expand Down Expand Up @@ -179,7 +178,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection
// Set the User-Agent if the http.agent property is set
try
{
String agent = PrivilegedSystemHelper.getProperty("http.agent");
String agent = System.getProperty("http.agent");
if (agent != null)
setDefaultRequestProperty("User-Agent", agent);
}
Expand Down Expand Up @@ -214,7 +213,7 @@ public HttpURLConnection(URL url) throws ProtocolNotSuppException, IOException
// first read proxy properties and set
try
{
String hosts = PrivilegedSystemHelper.getProperty("http.nonProxyHosts", "");
String hosts = System.getProperty("http.nonProxyHosts", "");
if (!hosts.equalsIgnoreCase(non_proxy_hosts))
{
connections.clear();
Expand All @@ -238,7 +237,7 @@ public HttpURLConnection(URL url) throws ProtocolNotSuppException, IOException

try
{
String host = PrivilegedSystemHelper.getProperty("http.proxyHost", "");
String host = System.getProperty("http.proxyHost", "");
int port = Integer.getInteger("http.proxyPort", -1).intValue();
if (!host.equalsIgnoreCase(proxy_host) || port != proxy_port)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -106,7 +105,7 @@ public class Log
/** All the facilities - for use in <code>setLogging</code> (-1) */
public static final int ALL = ~0;

private static final String NL = PrivilegedSystemHelper.getProperty("line.separator");
private static final String NL = System.getProperty("line.separator");

private static final long TZ_OFF;

Expand All @@ -125,7 +124,7 @@ public class Log

try
{
String file = PrivilegedSystemHelper.getProperty("HTTPClient.log.file");
String file = System.getProperty("HTTPClient.log.file");
if (file != null)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
*/

package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

Expand Down Expand Up @@ -293,7 +291,7 @@ private void v4ProtExchg(InputStream inp, OutputStream out, String host, int por
String user_str;
try
{
user_str = PrivilegedSystemHelper.getProperty("user.name", "");
user_str = System.getProperty("user.name", "");
}
catch (SecurityException se)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

package org.exoplatform.common.http.client;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.BitSet;
Expand Down Expand Up @@ -1783,7 +1781,7 @@ public static void main(String args[]) throws Exception
System.err.println("*** Tests finished successfuly"); //NOSONAR
}

private static final String nl = PrivilegedSystemHelper.getProperty("line.separator");
private static final String nl = System.getProperty("line.separator");

private static void testParser(URI base, String relURI, String result) throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.exoplatform.ws.frameworks.json.impl;

import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.ws.frameworks.json.JsonGenerator;
import org.exoplatform.ws.frameworks.json.impl.JsonUtils.Types;
import org.exoplatform.ws.frameworks.json.value.JsonValue;
Expand All @@ -34,7 +33,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -386,13 +384,7 @@ private static Set<String> getTransientFields(final Class<?> clazz)
{
Set<String> set = new HashSet<String>();

Field[] fields = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Field[]>()
{
public Field[] run()
{
return clazz.getDeclaredFields();
}
});
Field[] fields = clazz.getDeclaredFields();

for (Field f : fields)
{
Expand Down
Loading

0 comments on commit 8c42501

Please sign in to comment.