diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java
index b60c16a809..649365a5f1 100644
--- a/core/src/main/java/hudson/Functions.java
+++ b/core/src/main/java/hudson/Functions.java
@@ -66,6 +66,7 @@ import hudson.util.Area;
import hudson.util.Iterators;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
+import hudson.util.Secret;
import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyTagException;
@@ -1234,6 +1235,15 @@ public class Functions {
}
}
}
+
+ /**
+ * Used by <f:password/> so that we send an encrypted value to the client.
+ */
+ public String getPasswordValue(Object o) {
+ if (o==null) return null;
+ if (o instanceof Secret) return ((Secret)o).getEncryptedValue();
+ return o.toString();
+ }
private static final Pattern SCHEME = Pattern.compile("[a-z]+://.+");
diff --git a/core/src/main/resources/lib/form/password.jelly b/core/src/main/resources/lib/form/password.jelly
index fd2a7803f6..b0f71fde18 100644
--- a/core/src/main/resources/lib/form/password.jelly
+++ b/core/src/main/resources/lib/form/password.jelly
@@ -55,7 +55,7 @@ THE SOFTWARE.
diff --git a/test/src/test/java/lib/form/PasswordTest.java b/test/src/test/java/lib/form/PasswordTest.java
new file mode 100644
index 0000000000..522f66c8c3
--- /dev/null
+++ b/test/src/test/java/lib/form/PasswordTest.java
@@ -0,0 +1,58 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2004-2010, InfraDNA, Inc.
+ *
+ * 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 lib.form;
+
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import hudson.Extension;
+import hudson.model.Describable;
+import hudson.model.Descriptor;
+import hudson.util.Secret;
+import org.jvnet.hudson.test.HudsonTestCase;
+
+/**
+ * @author Kohsuke Kawaguchi
+ */
+public class PasswordTest extends HudsonTestCase implements Describable {
+ public Secret secret;
+
+ public void test1() throws Exception {
+ secret = Secret.fromString("secret");
+ HtmlPage p = createWebClient().goTo("self/test1");
+ String value = ((HtmlInput)p.getElementById("password")).getValueAttribute();
+ assertFalse("password shouldn't be plain text",value.equals("secret"));
+ assertEquals("secret",Secret.fromString(value).getPlainText());
+ }
+
+ public DescriptorImpl getDescriptor() {
+ return hudson.getDescriptorByType(DescriptorImpl.class);
+ }
+
+ @Extension
+ public static final class DescriptorImpl extends Descriptor {
+ public String getDisplayName() {
+ return null;
+ }
+ }
+}
diff --git a/test/src/test/resources/lib/form/PasswordTest/test1.jelly b/test/src/test/resources/lib/form/PasswordTest/test1.jelly
new file mode 100644
index 0000000000..bdd2cc0ca4
--- /dev/null
+++ b/test/src/test/resources/lib/form/PasswordTest/test1.jelly
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+