Skip to content

Commit d2bb0da

Browse files
committed
- fixed the jenkins comments
1 parent 10a6862 commit d2bb0da

File tree

6 files changed

+49
-68
lines changed

6 files changed

+49
-68
lines changed

src/main/java/io/jenkins/plugins/vigilnz/build/SecurityCheckBuilder.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,22 @@
2929
import java.util.List;
3030

3131
// This file for Jenkins FreeStyle Job Method
32-
@SuppressWarnings("lgtm[jenkins/password-in-field]")
3332
public class SecurityCheckBuilder extends Builder {
3433

35-
/**
36-
* Credential ID (not sensitive - just an identifier to look up the actual credential).
37-
* The actual token is stored securely in TokenCredentials using Secret.
38-
*/
39-
private final String token;
34+
/** Credential ID (identifier to look up the actual credential, not sensitive) */
35+
private final String credentialsId;
4036
private String targetFile; // Optional parameter
4137
private boolean cveScan;
4238
private boolean sastScan;
4339
private boolean sbomScan;
4440

4541
@DataBoundConstructor
46-
public SecurityCheckBuilder(String token) {
47-
this.token = token;
42+
public SecurityCheckBuilder(String credentialsId) {
43+
this.credentialsId = credentialsId;
4844
}
4945

50-
public String getToken() {
51-
return token;
46+
public String getCredentialsId() {
47+
return credentialsId;
5248
}
5349

5450
public String getTargetFile() {
@@ -111,18 +107,23 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
111107
return false;
112108
}
113109

110+
// Validate credentials ID is provided
111+
if (credentialsId == null || credentialsId.trim().isEmpty()) {
112+
listener.error("Error: Credentials ID is required. Please select a credential in the build step configuration.");
113+
return false;
114+
}
115+
114116
// Look up the actual TokenCredentials object
115117
TokenCredentials creds = CredentialsProvider.findCredentialById(
116-
token,
118+
credentialsId,
117119
TokenCredentials.class,
118120
build
119121
);
120122

121123
if (creds == null) {
122-
listener.error("Error: Vigilnz Token credential not found");
124+
listener.error("Error: Vigilnz Token credential not found with ID: " + credentialsId);
123125
return false;
124126
}
125-
126127
// Get the actual token value from the credential
127128
String tokenText = creds.getToken().getPlainText();
128129

@@ -157,7 +158,7 @@ public String getDisplayName() {
157158
}
158159

159160
@POST
160-
public ListBoxModel doFillTokenItems(@AncestorInPath Item project) {
161+
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project) {
161162
// Security: Check if user has permission to configure this project
162163
if (project == null || !project.hasPermission(Item.CONFIGURE)) {
163164
return new ListBoxModel(); // Return empty list if no permission
@@ -187,7 +188,7 @@ public boolean isApplicable(Class jobType) {
187188
}
188189

189190
@POST
190-
public FormValidation doCheckToken(@AncestorInPath Item project, @QueryParameter Secret token) {
191+
public FormValidation doCheckCredentialsId(@AncestorInPath Item project, @QueryParameter String credentialsId) {
191192
// Security: Check if user has permission to configure this project
192193
if (project != null && !project.hasPermission(Item.CONFIGURE)) {
193194
return FormValidation.error("No permission to configure this project");
@@ -197,8 +198,8 @@ public FormValidation doCheckToken(@AncestorInPath Item project, @QueryParameter
197198
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
198199
}
199200

200-
if (token == null || Secret.toString(token).isEmpty()) {
201-
return FormValidation.error("Token is required");
201+
if (credentialsId == null || credentialsId.trim().isEmpty()) {
202+
return FormValidation.error("Credentials selection is required");
202203
}
203204
return FormValidation.ok();
204205
}

src/main/java/io/jenkins/plugins/vigilnz/credentials/TokenCredentials.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,10 @@
1717
@SuppressWarnings("lgtm[jenkins/password-in-field]")
1818
public class TokenCredentials extends BaseStandardCredentials {
1919

20-
/**
21-
* API token - stored securely using Jenkins Secret (encrypted when serialized).
22-
* This field uses Secret type which automatically encrypts the value on disk.
23-
*/
2420
private final Secret token;
25-
26-
/**
27-
* Credential identifier (not sensitive - just a label/ID, not a password).
28-
* This is a user-friendly identifier, not sensitive data.
29-
*/
21+
3022
private final String tokenId;
31-
32-
/**
33-
* Credential description (not sensitive - just metadata, not a password).
34-
* This is descriptive text, not sensitive data.
35-
*/
23+
3624
private final String tokenDescription;
3725

3826
@DataBoundConstructor
@@ -97,7 +85,7 @@ public FormValidation doCheckToken(@AncestorInPath Item item, @QueryParameter St
9785
// Global credential creation/editing requires admin permission
9886
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
9987
}
100-
88+
10189
if (token == null || token.trim().isEmpty()) {
10290
return FormValidation.error("Field is required");
10391
}
@@ -116,7 +104,7 @@ public FormValidation doCheckTokenId(@AncestorInPath Item item, @QueryParameter
116104
// Global credential creation/editing requires admin permission
117105
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
118106
}
119-
107+
120108
if (tokenId != null && !tokenId.trim().isEmpty()) {
121109
// Check for spaces
122110
if (tokenId.contains(" ")) {

src/main/java/io/jenkins/plugins/vigilnz/models/AuthResponse.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
11
package io.jenkins.plugins.vigilnz.models;
22

3-
/**
4-
* Authentication response model.
5-
* NOTE: This class is NOT serialized to disk - it's only used in-memory during API calls.
6-
* Tokens are cleared from memory after use and never persisted.
7-
* This class does NOT implement Serializable, so fields are never written to disk.
8-
*
9-
* Security: All token fields are in-memory only and never persisted to disk.
10-
*/
11-
@SuppressWarnings("lgtm[jenkins/password-in-field]")
123
public class AuthResponse {
134

14-
/**
15-
* Access token - sensitive but only in-memory, never persisted.
16-
* This class does not implement Serializable, so this field is never written to disk.
17-
*/
5+
@SuppressWarnings("lgtm[jenkins/plaintext-storage]")
186
private final String accessToken;
19-
20-
/**
21-
* Refresh token - sensitive but only in-memory, never persisted.
22-
* This class does not implement Serializable, so this field is never written to disk.
23-
*/
7+
8+
@SuppressWarnings("lgtm[jenkins/plaintext-storage]")
249
private final String refreshToken;
25-
10+
11+
@SuppressWarnings("lgtm[jenkins/plaintext-storage]")
2612
private final long expiresIn;
27-
28-
/**
29-
* Token type (e.g., "Bearer") - not sensitive, just metadata.
30-
* This is just a string like "Bearer", not sensitive data.
31-
*/
13+
14+
@SuppressWarnings("lgtm[jenkins/plaintext-storage]")
3215
private final String tokenType;
3316

3417
public AuthResponse(String accessToken, String refreshToken, long expiresIn, String tokenType) {

src/main/java/io/jenkins/plugins/vigilnz/pipeline/PipelineStep.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@
1515

1616
/**
1717
* Pipeline step for Vigilnz security scans.
18-
* Security: The 'token' field stores only a credential ID (identifier), not the actual token value.
18+
* Security: The 'credentialsId' field stores only a credential ID (identifier), not the actual token value.
1919
* The actual token is stored securely in TokenCredentials using Secret.
2020
*/
21-
@SuppressWarnings("lgtm[jenkins/password-in-field]")
2221
public class PipelineStep extends Step {
2322

2423
/**
2524
* Credential ID (not sensitive - just an identifier to look up the actual credential).
2625
* The actual token is stored securely in TokenCredentials using Secret.
2726
*/
28-
private final String token;
27+
private final String credentialsId;
2928
private final List<String> scanTypes;
3029
private String targetFile; // Optional parameter
3130

3231
@DataBoundConstructor
33-
public PipelineStep(String token, List<String> scanTypes) {
34-
this.token = token;
32+
public PipelineStep(String credentialsId, List<String> scanTypes) {
33+
this.credentialsId = credentialsId;
3534
this.scanTypes = scanTypes != null ? scanTypes : List.of();
3635
}
3736

@@ -40,8 +39,8 @@ public void setTargetFile(String targetFile) {
4039
this.targetFile = targetFile;
4140
}
4241

43-
public String getToken() {
44-
return token;
42+
public String getCredentialsId() {
43+
return credentialsId;
4544
}
4645

4746
public String getTargetFile() {

src/main/java/io/jenkins/plugins/vigilnz/pipeline/PipelineStepExecution.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,19 @@ public boolean start() throws Exception {
7676

7777
TaskListener listener = getContext().get(TaskListener.class);
7878
Run<?, ?> run = getContext().get(Run.class);
79+
80+
String credentialsId = step.getCredentialsId();
81+
82+
// Validate credentials ID is provided
83+
if (credentialsId == null || credentialsId.trim().isEmpty()) {
84+
listener.error("Error: Credentials ID is required. Please provide a credential ID in the pipeline step.");
85+
getContext().onFailure(new AbortException("Credentials ID is required"));
86+
return false;
87+
}
88+
7989
TokenCredentials creds =
8090
CredentialsProvider.findCredentialById(
81-
step.getToken(),
91+
credentialsId,
8292
TokenCredentials.class,
8393
run
8494
);
@@ -119,8 +129,8 @@ public boolean start() throws Exception {
119129
}
120130

121131
} else {
122-
listener.getLogger().println("No Vigilnz Token credential found");
123-
getContext().onFailure(new AbortException("No Vigilnz Token credential found"));
132+
listener.error("Error: Vigilnz Token credential not found with ID: " + credentialsId);
133+
getContext().onFailure(new AbortException("No Vigilnz Token credential found with ID: " + credentialsId));
124134
return false;
125135
}
126136

src/main/resources/io/jenkins/plugins/vigilnz/build/SecurityCheckBuilder/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:c="/lib/credentials">
33

4-
<f:entry title="Token" field="token">
4+
<f:entry title="Credentials" field="credentialsId">
55
<c:select/>
66
</f:entry>
77

0 commit comments

Comments
 (0)