From 00cf6d0fe231acd12e4fdf3583936a074d0aceb8 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Mon, 13 May 2024 17:59:59 -0700 Subject: [PATCH] Use Stapler file upload --- src/main/java/org/miniorange/saml/MoPluginConfigView.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/org/miniorange/saml/MoPluginConfigView.java b/src/main/java/org/miniorange/saml/MoPluginConfigView.java index b20bfaa..acf4775 100644 --- a/src/main/java/org/miniorange/saml/MoPluginConfigView.java +++ b/src/main/java/org/miniorange/saml/MoPluginConfigView.java @@ -11,8 +11,6 @@ import net.sf.json.JSONObject; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.IOUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -24,7 +22,6 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.List; import java.util.logging.Logger; import static jenkins.model.Jenkins.get; @@ -126,10 +123,7 @@ public void doDownload(StaplerRequest req, StaplerResponse rsp) throws IOExcepti public void doUploadSamlConfigJson(StaplerRequest req, StaplerResponse rsp) throws IOException, FileUploadException, ServletException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); try { - File tmpDir = Files.createTempDirectory("uploadDir").toFile(); - ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, tmpDir)); - List items = upload.parseRequest(req); - FileItem fileItem = items.get(0); + FileItem fileItem = req.getFileItem("my.key"); String fileContent = fileItem.getString(); JSONObject json = JSONObject.fromObject(fileContent); MoSAMLAddIdp.DESCRIPTOR.doRealmSubmit(req, rsp, json);