Skip to content

Commit ed16d12

Browse files
committed
Avoid classloader manipulation when installing a new plugin
1 parent d3b3436 commit ed16d12

File tree

3 files changed

+9
-55
lines changed

3 files changed

+9
-55
lines changed

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/system/plugin/PluginUploader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public PluginUploader(PluginsPanel pluginsPanel) {
3232
setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
3333
setTitle(I18N.message("uploadplugin"));
3434
setWidth(430);
35-
setHeight(130);
35+
setHeight(170);
3636
setCanDragResize(true);
3737
setIsModal(true);
3838
setShowModalMask(true);
@@ -42,7 +42,7 @@ public PluginUploader(PluginsPanel pluginsPanel) {
4242
submitButton.addClickHandler(event -> onSubmit());
4343

4444
VLayout layout = new VLayout();
45-
layout.setMembersMargin(5);
45+
layout.setMembersMargin(1);
4646
layout.setMargin(2);
4747

4848
uploader = new Upload(submitButton);

logicaldoc-util/src/main/java/com/logicaldoc/util/io/FileUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,10 @@ public static void replaceInFile(String sourcePath, String token, String newValu
563563
* @throws IOException if the copy resulted in an error
564564
*/
565565
public static void copyFile(File source, File target) throws IOException {
566-
try (FileChannel in = new FileInputStream(source).getChannel();
567-
FileChannel out = new FileOutputStream(target).getChannel();) {
566+
try (FileInputStream fis = new FileInputStream(source);
567+
FileChannel in = fis.getChannel();
568+
FileOutputStream fos = new FileOutputStream(target);
569+
FileChannel out = fos.getChannel();) {
568570

569571
ByteBuffer buffer = ByteBuffer.allocateDirect(BUFF_SIZE);
570572
while (in.read(buffer) != -1) {

logicaldoc-webapp/src/main/java/com/logicaldoc/web/service/SystemServiceImpl.java

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import java.io.IOException;
55
import java.io.InputStream;
66
import java.lang.reflect.InvocationTargetException;
7-
import java.lang.reflect.Method;
8-
import java.net.MalformedURLException;
9-
import java.net.URL;
10-
import java.net.URLClassLoader;
117
import java.sql.ResultSet;
128
import java.sql.SQLException;
139
import java.sql.Timestamp;
@@ -71,7 +67,6 @@
7167
import com.logicaldoc.util.config.ContextProperties;
7268
import com.logicaldoc.util.config.LogConfigurator;
7369
import com.logicaldoc.util.config.PluginDescriptorConfigurator;
74-
import com.logicaldoc.util.exec.Exec;
7570
import com.logicaldoc.util.io.FileUtil;
7671
import com.logicaldoc.util.io.ZipUtil;
7772
import com.logicaldoc.util.plugin.LogicalDOCPlugin;
@@ -603,7 +598,7 @@ public List<GUIHistory> search(Long userId, Date from, Date till, int maxResult,
603598
query.append(" union ");
604599
query.append(
605600
"select A.ld_username, A.ld_event, A.ld_date, A.ld_filename, A.ld_folderid, A.ld_path, A.ld_sessionid, A.ld_docid, A.ld_userid, A.ld_ip as ip, A.ld_userlogin, A.ld_comment, A.ld_reason, A.ld_device, A.ld_geolocation, A.ld_keylabel from TABLE A where A.ld_tenantid = "
606-
.replace("TABLE", table).replace("A", tableAlias) + session.getTenantId());
601+
.replace("TABLE", table).replace("A", tableAlias) + session.getTenantId());
607602
appendUserCondition(tableAlias, userId, query);
608603
appendSessionCondition(tableAlias, historySid, query);
609604
appendDatesCondition(tableAlias, from, till, query);
@@ -820,18 +815,6 @@ public void uninstallPlugin(String pluginId) throws ServerException {
820815
// Nothing to do
821816
}
822817

823-
try {
824-
if (pluginJarFile.exists()) {
825-
if (new Exec().isWindows())
826-
Runtime.getRuntime().exec(
827-
new String[] { "cmd.exe", "/c", "del /F /Q \"" + pluginJarFile.getAbsolutePath() + "\"" });
828-
else
829-
Runtime.getRuntime().exec(new String[] { "rm", "-rf", pluginJarFile.getAbsolutePath() });
830-
}
831-
} catch (IOException e) {
832-
throwServerException(session, log, e);
833-
}
834-
835818
if (pluginJarFile.exists())
836819
throw new ServerException("Cannot remove plugin file " + pluginJarFile.getAbsolutePath()
837820
+ ". Please stop the application and delete that file manually.");
@@ -940,21 +923,6 @@ public void installPlugin() throws ServerException {
940923
log.info("Deleted existing plugin home {}", pluginHome.getAbsolutePath());
941924
}
942925

943-
File libFolder = new File(new File(rootFolder, "WEB-INF"), "lib");
944-
File pluginJarFile = new File(libFolder, pluginJar);
945-
946-
/*
947-
* Append the plugin jar in the classpath
948-
*/
949-
appendPluginJarInClasspath(pluginJarFile);
950-
951-
/*
952-
* Initialize the plugin
953-
*/
954-
PluginRegistry pluginRegistry = PluginRegistry.getInstance();
955-
pluginRegistry.init(libFolder.getAbsolutePath());
956-
initializePlugin(pluginId);
957-
958926
/*
959927
* Copy the plugin archive as .installed so it will be maintained
960928
* over the updates
@@ -963,30 +931,14 @@ public void installPlugin() throws ServerException {
963931
File targetFile = new File(pluginsDir, pluginId + "-" + pluginVersion + "-plugin.zip.installed");
964932
log.info("Copying plugin package {} into {}", pluginPackage.getName(), targetFile.getAbsolutePath());
965933
FileUtil.copyFile(pluginPackage, targetFile);
966-
967-
if (pluginRegistry.isRestartRequired())
968-
ApplicationListener.restartRequired();
969-
} catch (ServerException | IOException | NoSuchMethodException | IllegalArgumentException
970-
| InvocationTargetException | PluginException e) {
934+
ApplicationListener.restartRequired();
935+
} catch (ServerException | IOException | IllegalArgumentException e) {
971936
throwServerException(session, log, e);
972937
} finally {
973938
UploadServlet.cleanUploads(session.getSid());
974939
}
975940
}
976941

977-
private void appendPluginJarInClasspath(File pluginJarFile)
978-
throws NoSuchMethodException, InvocationTargetException, MalformedURLException {
979-
final ClassLoader sysloader = this.getClass().getClassLoader();
980-
final Class<URLClassLoader> sysclass = URLClassLoader.class;
981-
final Method method = sysclass.getDeclaredMethod("addURL", URL.class);
982-
983-
try {
984-
method.invoke(sysloader, pluginJarFile.toURI().toURL());
985-
} catch (IllegalAccessException iae) {
986-
log.warn(iae.getMessage(), iae);
987-
}
988-
}
989-
990942
@Override
991943
public List<GUIValue> getPlugins() throws ServerException {
992944
validateSession();

0 commit comments

Comments
 (0)