From 14879ad0a48bbeccb89ced609a0d5e6b6fb6f5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Mon, 5 Dec 2016 22:14:04 +0100 Subject: [PATCH] Fix NPE while generating the secret token for the GitLabPushTrigger (Fixes #447) --- .../dabsquared/gitlabjenkins/GitLabPushTrigger.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java index 2c9e073..ee14217 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java @@ -250,12 +250,6 @@ public class GitLabPushTrigger extends Trigger> { noteHookTriggerHandler.handle(job, hook, ciSkip, branchFilter, mergeRequestLabelFilter); } - private void generateSecretToken() { - byte[] random = new byte[16]; // 16x8=128bit worth of randomness, since we use md5 digest as the API token - RANDOM.nextBytes(random); - secretToken = Secret.fromString(Util.toHexString(random)); - } - private void initializeTriggerHandler() { mergeRequestHookTriggerHandler = newMergeRequestHookTriggerHandler(triggerOnMergeRequest, triggerOpenMergeRequestOnPush, skipWorkInProgressMergeRequest); noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnNoteRequest, noteRegex); @@ -403,9 +397,10 @@ public class GitLabPushTrigger extends Trigger> { } public void doGenerateSecretToken(@AncestorInPath final Job project, StaplerResponse response) { - GitLabPushTrigger trigger = getFromJob(project); - trigger.generateSecretToken(); - response.setHeader("script", "document.getElementById('secretToken').value='" + trigger.getSecretToken() + "'"); + byte[] random = new byte[16]; // 16x8=128bit worth of randomness, since we use md5 digest as the API token + RANDOM.nextBytes(random); + String secretToken = Util.toHexString(random); + response.setHeader("script", "document.getElementById('secretToken').value='" + secretToken + "'"); } } }