Skip to content

Commit

Permalink
fix: Update to JDK21 - EXO-71474 - Meeds-io/MIPs#91 (#324)
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
  • Loading branch information
rdenarie authored May 22, 2024
1 parent 44b5495 commit ed8c0b0
Show file tree
Hide file tree
Showing 133 changed files with 1,912 additions and 4,967 deletions.
8 changes: 1 addition & 7 deletions exo.jcr.component.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} ${env.MAVEN_OPTS} --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED -Djava.net.preferIPv4Stack=true -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy ${debug.opts}</argLine>
<argLine>@{surefire.argLine} -Djava.net.preferIPv4Stack=true</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
Expand Down Expand Up @@ -1346,11 +1346,5 @@
</plugins>
</build>
</profile>
<profile>
<id>debug</id>
<properties>
<debug.opts>-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y</debug.opts>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.exoplatform.services.document.diff;

import org.exoplatform.commons.utils.PrivilegedSystemHelper;

/**
* Implements a differencing engine that works on arrays of {@link Object
* Object}.
Expand All @@ -41,7 +39,7 @@ public interface DiffService extends ToString
{

/** The standard line separator. */
public static final String NL = PrivilegedSystemHelper.getProperty("line.separator");
public static final String NL = System.getProperty("line.separator");

/** The line separator to use in RCS format output. */
public static final String RCS_EOL = "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@

import java.io.IOException;
import java.io.InputStream;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;

import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.document.DocumentReadException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
Expand Down Expand Up @@ -74,13 +72,7 @@ public String getContentAsText(final InputStream is) throws IOException, Documen
HWPFDocument doc;
try
{
doc = SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<HWPFDocument>()
{
public HWPFDocument run() throws Exception
{
return new HWPFDocument(is);
}
});
doc = new HWPFDocument(is);
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;

import javax.xml.parsers.ParserConfigurationException;
Expand All @@ -38,7 +36,6 @@
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.document.DocumentReadException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
Expand Down Expand Up @@ -130,73 +127,57 @@ public String getContentAsText(final InputStream is) throws IOException, Documen
{
return "";
}
SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
try
{

public Void run() throws Exception
OPCPackage container = OPCPackage.open(is);
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container);
XSSFReader xssfReader = new XSSFReader(container);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
MSXExcelSheetXMLHandler.SheetContentsHandler sheetExtractor = new SheetTextExtractor(builder);
int parsedTabs = 0;
while (iter.hasNext() && parsedTabs < MAX_TABS)
{
InputStream stream = null;
parsedTabs++;
try
{
OPCPackage container = OPCPackage.open(is);
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container);
XSSFReader xssfReader = new XSSFReader(container);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
MSXExcelSheetXMLHandler.SheetContentsHandler sheetExtractor = new SheetTextExtractor(builder);
int parsedTabs = 0;
while (iter.hasNext() && parsedTabs < MAX_TABS)
stream = iter.next();
builder.append('\n');
builder.append(iter.getSheetName());
builder.append('\n');
processSheet(sheetExtractor, strings, stream);
}
finally
{
if (stream != null)
{
InputStream stream = null;
parsedTabs++;
try
{
stream = iter.next();
builder.append('\n');
builder.append(iter.getSheetName());
builder.append('\n');
processSheet(sheetExtractor, strings, stream);
stream.close();
}
finally
catch (IOException e)
{
if (stream != null)
if (LOG.isTraceEnabled())
{
try
{
stream.close();
}
catch (IOException e)
{
if (LOG.isTraceEnabled())
{
LOG.trace("An exception occurred: " + e.getMessage());
}
}
LOG.trace("An exception occurred: " + e.getMessage());
}
}
}
}
catch (InvalidFormatException e)
{
throw new DocumentReadException("The format of the document to read is invalid.", e);
}
catch (SAXException e)
{
throw new DocumentReadException("Problem during the document parsing.", e);
}
catch (OpenXML4JException e)
{
throw new DocumentReadException("Problem during the document parsing.", e);
}
return null;
}
});
}
catch (PrivilegedActionException e)
{
if (e.getCause() instanceof DocumentReadException)
}
catch (InvalidFormatException e)
{
throw (DocumentReadException)e.getCause();
throw new DocumentReadException("The format of the document to read is invalid.", e);
}
catch (SAXException e)
{
throw new DocumentReadException("Problem during the document parsing.", e);
}
catch (OpenXML4JException e)
{
throw new DocumentReadException("Problem during the document parsing.", e);
}
throw new DocumentReadException("Problem during the document parsing.", e.getCause());
}
finally
{
Expand Down Expand Up @@ -280,14 +261,7 @@ public Properties getProperties(final InputStream is) throws IOException, Docume
{
try
{
OPCPackage container =
SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<OPCPackage>()
{
public OPCPackage run() throws Exception
{
return OPCPackage.open(is);
}
});
OPCPackage container = OPCPackage.open(is);
POIXMLProperties xmlProperties = new POIXMLProperties(container);
POIPropertiesReader reader = new POIPropertiesReader();
reader.readDCProperties(xmlProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Properties;

import org.apache.poi.ooxml.POIXMLProperties;
Expand All @@ -31,7 +28,6 @@
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.xmlbeans.XmlException;

import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.document.DocumentReadException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
Expand Down Expand Up @@ -83,38 +79,17 @@ public String getContentAsText(final InputStream is) throws IOException, Documen
XWPFDocument doc;
try
{
doc = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<XWPFDocument>()
{
public XWPFDocument run() throws Exception
{
return new XWPFDocument(is);
}
});
doc = new XWPFDocument(is);
}
catch (RuntimeException cause)
{
throw new DocumentReadException("Can not get the content: " + cause.getMessage(), cause);
}
catch (PrivilegedActionException pae)
{
Throwable cause = pae.getCause();
if (cause instanceof IOException)
{
throw (IOException)cause;
}
throw new DocumentReadException("Can not get the content: " + cause.getMessage(), cause);
}

final XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
try
{
text = SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
{
public String run()
{
return extractor.getText();
}
});
text = extractor.getText();
}
catch (Exception cause)
{
Expand Down Expand Up @@ -161,14 +136,7 @@ public Properties getProperties(final InputStream is) throws IOException, Docume
{
try
{
OPCPackage container =
SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<OPCPackage>()
{
public OPCPackage run() throws Exception
{
return OPCPackage.open(is);
}
});
OPCPackage container = OPCPackage.open(is);
POIXMLProperties xmlProperties = new POIXMLProperties(container);
POIPropertiesReader reader = new POIPropertiesReader();
reader.readDCProperties(xmlProperties);
Expand Down
Loading

0 comments on commit ed8c0b0

Please sign in to comment.