Skip to content

Commit

Permalink
Merge pull request #8 from rinokadijk/master
Browse files Browse the repository at this point in the history
Fixed JENKINS-15882 - rebuild plugin should not store non-stored password parameter
  • Loading branch information
rsandell committed Jul 22, 2013
2 parents d7bc0e5 + 2102137 commit 50f9bf3
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,8 @@ work
.classpath
.project
.settings
### IntelliJ ###
*.iml
*.ipr
*.iws
.idea/
16 changes: 14 additions & 2 deletions src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Expand Up @@ -24,6 +24,7 @@
*/
package com.sonyericsson.rebuild;

import hudson.Extension;
import hudson.matrix.MatrixRun;
import hudson.model.*;
import net.sf.json.JSONArray;
Expand Down Expand Up @@ -55,8 +56,12 @@ public class RebuildAction implements Action {
private transient String p = "parameter";
private transient AbstractBuild<?, ?> build;
private transient ParametersDefinitionProperty pdp;

private static final String PARAMETERIZED_URL = "parameterized";

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

public RebuildAction() {
}

Expand Down Expand Up @@ -105,13 +110,21 @@ 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.
*
* @return currentProject.
*/
public AbstractProject getProject() {

if (build != null) {
return build.getProject();
}
Expand Down Expand Up @@ -293,7 +306,6 @@ public boolean isMatrixRun() {
* @return boolean
*/
public boolean isRebuildAvailable() {

AbstractProject project = getProject();
return project != null &&
project.hasPermission(AbstractProject.BUILD) &&
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/com/sonyericsson/rebuild/RebuildConfiguration.java
@@ -0,0 +1,69 @@
/*
* The MIT License
*
* Copyright 2013 Rino Kadijk.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.sonyericsson.rebuild;

import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* This class holds the configuration values for the rebuild action.
*/
public class RebuildConfiguration implements Describable {

public boolean rememberPasswordEnabled;

/**
* Constructs a new configuration object.
*
* @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 rememberPasswordEnabled) {
this.rememberPasswordEnabled = rememberPasswordEnabled;
}

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

@Override
public Descriptor getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(RebuildConfiguration.class);
}

/**
* True if the password field should be pre-filled.
*
* @return true if the password field should be pre-filled.
*/
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;
}
}
@@ -0,0 +1,35 @@
<!--
The MIT License
Copyright 2013 Rino Kadijk.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<f:textbox name="value" value="${it.value}" />
</div>
</f:entry>
</j:jelly>


Expand Up @@ -30,7 +30,10 @@ xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<f:password name="value" value="${it.value}" />
<j:choose>
<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>
</f:entry>
</j:jelly>
Expand Up @@ -46,6 +46,7 @@ THE SOFTWARE.

<j:set var="instance" value="${it}"/>
<j:set var="descriptor" value="${it.descriptor}"/>
<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
@@ -0,0 +1,13 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson"
xmlns:f="/lib/form">
<f:section title="Rebuild">
<f:entry title="Rebuild Configuration">
<table width="100%">
<f:entry title="Remember Password Enabled" field="rememberPasswordEnabled">
<f:checkbox default="true" checked="${descriptor.rebuildConfiguration.rememberPasswordEnabled}" />
</f:entry>
</table>
</f:entry>
</f:section>
</j:jelly>
@@ -0,0 +1,6 @@
<div>
If the remember password option is checked, the rebuild plugin will use the stored password parameter when a
rebuild is triggered. If the remember password option is unchecked, the user will be prompted to enter the
password every time a rebuild is triggered. This only applies for a parameterized build with parameters of
type password.
</div>

0 comments on commit 50f9bf3

Please sign in to comment.