Skip to content

Commit b605c64

Browse files
committed
Switch to JSONObject for data blob
1 parent d80588e commit b605c64

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import jenkins.security.SlaveToMasterCallable;
2626
import jenkins.util.JenkinsJVM;
27+
import net.sf.json.JSONObject;
2728
import org.jenkinsci.plugins.workflow.support.concurrent.Timeout;
2829
import org.kohsuke.accmod.Restricted;
2930
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -350,8 +351,6 @@ private Object writeReplace() {
350351

351352
private static final class DelegatingGitHubAppCredentials extends BaseStandardCredentials implements StandardUsernamePasswordCredentials {
352353

353-
private static final String SEP = "%%%";
354-
355354
private final String appID;
356355
/**
357356
* An encrypted form of all data needed to refresh the token.
@@ -366,7 +365,12 @@ private static final class DelegatingGitHubAppCredentials extends BaseStandardCr
366365
super(onMaster.getScope(), onMaster.getId(), onMaster.getDescription());
367366
JenkinsJVM.checkJenkinsJVM();
368367
appID = onMaster.appID;
369-
tokenRefreshData = Secret.fromString(onMaster.appID + SEP + onMaster.privateKey.getPlainText() + SEP + onMaster.actualApiUri() + SEP + onMaster.owner).getEncryptedValue();
368+
JSONObject j = new JSONObject();
369+
j.put("appID", appID);
370+
j.put("privateKey", onMaster.privateKey.getPlainText());
371+
j.put("apiUri", onMaster.actualApiUri());
372+
j.put("owner", onMaster.owner);
373+
tokenRefreshData = Secret.fromString(j.toString()).getEncryptedValue();
370374

371375
// Check token is valid before sending it to the agent.
372376
// Ensuring the cached token is not stale before sending it to agents keeps agents from having to
@@ -445,15 +449,16 @@ private static final class GetToken extends SlaveToMasterCallable<AppInstallatio
445449
@Override
446450
public AppInstallationToken call() throws RuntimeException {
447451
JenkinsJVM.checkJenkinsJVM();
448-
String[] fields = Secret.fromString(data).getPlainText().split(SEP);
449-
LOGGER.log(Level.FINE, "Generating App Installation Token for app ID {0} for agent", fields[0]);
450-
AppInstallationToken token = generateAppInstallationToken(fields[0],
451-
fields[1],
452-
fields[2],
453-
fields[3]);
452+
JSONObject fields = JSONObject.fromObject(Secret.fromString(data).getPlainText());
453+
LOGGER.log(Level.FINE, "Generating App Installation Token for app ID {0} for agent", fields.get("appID"));
454+
AppInstallationToken token = generateAppInstallationToken(
455+
(String)fields.get("appID"),
456+
(String)fields.get("privateKey"),
457+
(String)fields.get("apiUri"),
458+
(String)fields.get("owner"));
454459
LOGGER.log(Level.FINER,
455460
"Retrieved GitHub App Installation Token for app ID {0} for agent",
456-
fields[0]);
461+
fields.get("appID"));
457462
return token;
458463
}
459464
}

0 commit comments

Comments
 (0)