Skip to content

Commit

Permalink
Merge pull request #6 from basil/deduplicate
Browse files Browse the repository at this point in the history
Use Stapler file upload
  • Loading branch information
miniOrangeDev authored Jun 19, 2024
2 parents cb7f615 + 00cf6d0 commit 7c57665
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/main/java/org/miniorange/saml/MoPluginConfigView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<FileItem> 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);
Expand Down

0 comments on commit 7c57665

Please sign in to comment.