From 0a31917c25282383bda2837f3429e656d5c98932 Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Tue, 3 Oct 2023 16:18:42 -0400 Subject: [PATCH] Use Descriptor.bindJSON to support complex describable fields in custom credentials --- .../plugins/credentials/CredentialsSelectHelper.java | 2 +- .../cloudbees/plugins/credentials/CredentialsStoreAction.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cloudbees/plugins/credentials/CredentialsSelectHelper.java b/src/main/java/com/cloudbees/plugins/credentials/CredentialsSelectHelper.java index 127beb026..cb9694d3c 100644 --- a/src/main/java/com/cloudbees/plugins/credentials/CredentialsSelectHelper.java +++ b/src/main/java/com/cloudbees/plugins/credentials/CredentialsSelectHelper.java @@ -611,7 +611,7 @@ public void doAddCredentials(StaplerRequest req, StaplerResponse rsp) throws IOE .generateResponse(req, rsp, null); } store.checkPermission(CredentialsStoreAction.CREATE); - Credentials credentials = req.bindJSON(Credentials.class, data.getJSONObject("credentials")); + Credentials credentials = Descriptor.bindJSON(req, Credentials.class, data.getJSONObject("credentials")); store.addCredentials(wrapper.getDomain(), credentials); FormApply.applyResponse("window.credentials.refreshAll();").generateResponse(req, rsp, null); } diff --git a/src/main/java/com/cloudbees/plugins/credentials/CredentialsStoreAction.java b/src/main/java/com/cloudbees/plugins/credentials/CredentialsStoreAction.java index d4d71c560..b752bfe21 100644 --- a/src/main/java/com/cloudbees/plugins/credentials/CredentialsStoreAction.java +++ b/src/main/java/com/cloudbees/plugins/credentials/CredentialsStoreAction.java @@ -811,7 +811,7 @@ public HttpResponse doCreateCredentials(StaplerRequest req) throws ServletExcept } } else { JSONObject data = req.getSubmittedForm(); - Credentials credentials = req.bindJSON(Credentials.class, data.getJSONObject("credentials")); + Credentials credentials = Descriptor.bindJSON(req, Credentials.class, data.getJSONObject("credentials")); getStore().addCredentials(domain, credentials); return HttpResponses.redirectTo("../../domain/" + getUrlName()); } @@ -1394,7 +1394,7 @@ public HttpResponse doDoMove(StaplerRequest req, @QueryParameter String destinat public HttpResponse doUpdateSubmit(StaplerRequest req) throws ServletException, IOException { getStore().checkPermission(UPDATE); JSONObject data = req.getSubmittedForm(); - Credentials credentials = req.bindJSON(Credentials.class, data); + Credentials credentials = Descriptor.bindJSON(req, Credentials.class, data); if (!getStore().updateCredentials(this.domain.domain, this.credentials, credentials)) { return HttpResponses.redirectTo("concurrentModification"); }