Skip to content

Commit

Permalink
JENKINS-15882 - rebuild plugin should not store non-stored password p…
Browse files Browse the repository at this point in the history
…arameter

- fixed review comment
  • Loading branch information
rinokadijk committed Apr 28, 2013
1 parent 16dd397 commit 6678b8e
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 85 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,8 @@ work
.classpath
.project
.settings
### IntelliJ ###
*.iml
*.ipr
*.iws
.idea/
81 changes: 13 additions & 68 deletions src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Expand Up @@ -27,10 +27,6 @@
import hudson.Extension;
import hudson.matrix.MatrixRun;
import hudson.model.*;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
import hudson.tasks.Publisher;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.Stapler;
Expand All @@ -48,7 +44,7 @@
*
* @author Shemeer S;
*/
public class RebuildAction extends Notifier implements Action {
public class RebuildAction implements Action {

private static final String SVN_TAG_PARAM_CLASS = "hudson.scm.listtagsparameter.ListSubversionTagsParameterValue";
/*
Expand All @@ -63,6 +59,9 @@ public class RebuildAction extends Notifier implements Action {

private static final String PARAMETERIZED_URL = "parameterized";

@Extension
public static final RebuildDescriptor DESCRIPTOR = new RebuildDescriptor();

public RebuildAction() {
}

Expand Down Expand Up @@ -111,6 +110,15 @@ public String getRebuildurl() {
return rebuildurl;
}

/**
* True if the password fields should be pre-filled.
*
* @return True if the password fields should be pre-filled.
*/
public boolean isRememberPasswordEnabled() {
return DESCRIPTOR.getRebuildConfiguration().rememberPasswordEnabled;
}

/**
* Method will return current project.
*
Expand Down Expand Up @@ -376,67 +384,4 @@ private ParameterValue cloneParameter(ParameterValue oldValue, String newValue)
}
throw new IllegalArgumentException("Unrecognized parameter type: " + oldValue.getClass());
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}

@Override
public BuildStepDescriptor getDescriptor() {
return super.getDescriptor();
}

@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
private final RebuildConfiguration rebuildConfiguration = new RebuildConfiguration(Boolean.TRUE);

/**
* Constructs a new Descriptor implementation.
*/
public DescriptorImpl() {
super(RebuildAction.class);
load();
}

@Override
public String getDisplayName() {
return "Rebuild";
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws Descriptor.FormException {
this.rebuildConfiguration.rememberPassword = Boolean.valueOf(formData.getString("rememberPassword"));
save();
return true;
}

@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new RebuildAction();
}

/**
* Gets the configuration object.
*
* @return the configuration object.
*/
public RebuildConfiguration getRebuildConfiguration() {
return rebuildConfiguration;
}

/**
* Gets the remember password option from the configuration object.
*
* @return true if the password field should be pre-filled.
*/
public boolean getRememberPassword() {
return rebuildConfiguration.getRememberPassword();
}
}
}
26 changes: 13 additions & 13 deletions src/main/java/com/sonyericsson/rebuild/RebuildConfiguration.java
Expand Up @@ -33,17 +33,24 @@
*/
public class RebuildConfiguration implements Describable {

public boolean rememberPassword;
public boolean rememberPasswordEnabled;

/**
* Constructs a new configuration object.
*
* @param rememberPassword indicates whether the password field should be pre-filled or empty when rebuilding
* @param rememberPasswordEnabled indicates whether the password field should be pre-filled or empty when rebuilding
* a job with a password parameter.
*/
@DataBoundConstructor
public RebuildConfiguration(boolean rememberPassword) {
this.rememberPassword = rememberPassword;
public RebuildConfiguration(boolean rememberPasswordEnabled) {
this.rememberPasswordEnabled = rememberPasswordEnabled;
}

@Override
public String toString() {
return "RebuildConfiguration{" +
"rememberPasswordEnabled=" + rememberPasswordEnabled +
'}';
}

@Override
Expand All @@ -56,14 +63,7 @@ public Descriptor getDescriptor() {
*
* @return true if the password field should be pre-filled.
*/
public boolean getRememberPassword() {
return rememberPassword;
}

@Override
public String toString() {
return "RebuildConfiguration{" +
"rememberPassword=" + rememberPassword +
'}';
public boolean getRememberPasswordEnabled() {
return rememberPasswordEnabled;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/sonyericsson/rebuild/RebuildDescriptor.java
@@ -0,0 +1,40 @@
package com.sonyericsson.rebuild;

import jenkins.model.GlobalConfiguration;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

/**
* This class holds the configuration values for the rebuild action.
*/
public final class RebuildDescriptor extends GlobalConfiguration {
private final RebuildConfiguration rebuildConfiguration = new RebuildConfiguration(Boolean.TRUE);

/**
* Constructs a new Descriptor implementation.
*/
public RebuildDescriptor() {
load();
}

@Override
public String getDisplayName() {
return "Rebuild";
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
this.rebuildConfiguration.rememberPasswordEnabled = Boolean.valueOf(formData.getString("rememberPasswordEnabled"));
save();
return true;
}

/**
* Gets the configuration object.
*
* @return the configuration object.
*/
public RebuildConfiguration getRebuildConfiguration() {
return rebuildConfiguration;
}
}
Expand Up @@ -31,7 +31,7 @@ xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<j:choose>
<j:when test="${rememberPassword}"><f:password name="value" value="${it.value}"/></j:when>
<j:when test="${rememberPasswordEnabled}"><f:password name="value" value="${it.value}"/></j:when>
<j:otherwise><f:password name="value" value="" /></j:otherwise>
</j:choose>
</div>
Expand Down
Expand Up @@ -46,7 +46,7 @@ THE SOFTWARE.

<j:set var="instance" value="${it}"/>
<j:set var="descriptor" value="${it.descriptor}"/>
<j:set var="rememberPassword" value="${it.descriptor.rebuildConfiguration.rememberPassword}" scope="parent"/>
<j:set var="rememberPasswordEnabled" value="${it.DESCRIPTOR.rebuildConfiguration.rememberPasswordEnabled}" scope="parent"/>
<j:set var="build" value="${request.findAncestorObject(buildClass)}" />
<j:set var="paramAction" value="${build.getAction(parmactionClass)}" />
<f:form method="post" action="configSubmit" name="config">
Expand Down
Expand Up @@ -4,8 +4,8 @@
<f:section title="Rebuild">
<f:entry title="Rebuild Configuration">
<table width="100%">
<f:entry title="Remember Password" field="rememberPassword">
<f:checkbox default="true"/>
<f:entry title="Remember Password Enabled" field="rememberPasswordEnabled">
<f:checkbox default="true" checked="${descriptor.rebuildConfiguration.rememberPasswordEnabled}" />
</f:entry>
</table>
</f:entry>
Expand Down

0 comments on commit 6678b8e

Please sign in to comment.