Skip to content

Commit

Permalink
[SECURITY-1575] Save privateToken to Secret field instead of String f…
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Sep 18, 2019
1 parent f4c28e3 commit 1a64595
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -64,14 +65,14 @@ public String getRepositoryUrl(){

private Project getProject() {
DescriptorImpl descriptor = getDescriptor();
GitlabApi api = new GitlabApi(descriptor.getEndpointUrl(), descriptor.getPrivateToken());
GitlabApi api = new GitlabApi(descriptor.getEndpointUrl(), descriptor.getPrivateToken().getPlainText());
return api.getCachedProject(getRepositoryName());
}

@Extension
public static final class DescriptorImpl extends JobPropertyDescriptor
{
private String privateToken;
private Secret privateToken;
private String endpointUrl;

public DescriptorImpl(){
Expand Down Expand Up @@ -100,15 +101,15 @@ public GitlabLogoProperty newInstance(StaplerRequest req, JSONObject formData) t
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
// To persist global configuration information,
// set that to properties and call save().
privateToken = formData.getString("privateToken");
privateToken = Secret.fromString(formData.getString("privateToken"));
endpointUrl = formData.getString("endpointUrl");
// ^Can also use req.bindJSON(this, formData);
// (easier when there are many fields; need set* methods for this, like setUseFrench)
save();
return super.configure(req, formData);
}

public String getPrivateToken() {
public Secret getPrivateToken() {
return privateToken;
}

Expand Down

0 comments on commit 1a64595

Please sign in to comment.