diff --git a/core/src/main/java/hudson/util/Secret.java b/core/src/main/java/hudson/util/Secret.java index 81ca5914b6..d4c55449f8 100644 --- a/core/src/main/java/hudson/util/Secret.java +++ b/core/src/main/java/hudson/util/Secret.java @@ -45,6 +45,10 @@ import java.security.GeneralSecurityException; * Note that since the cryptography relies on {@link Hudson#getSecretKey()}, this is not meant as a protection * against code running in the same VM, nor against an attacker who has local file system access. * + *
+ * {@link Secret}s can correctly read-in plain text password, so this allows the existing
+ * String field to be updated to {@link Secret}.
+ *
* @author Kohsuke Kawaguchi
*/
public final class Secret {
@@ -155,7 +159,7 @@ public final class Secret {
}
public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
- return Secret.decrypt(reader.getValue());
+ return fromString(reader.getValue());
}
}
diff --git a/core/src/test/java/hudson/util/SecretTest.java b/core/src/test/java/hudson/util/SecretTest.java
index 3f1d7a950d..ef52bf6d61 100644
--- a/core/src/test/java/hudson/util/SecretTest.java
+++ b/core/src/test/java/hudson/util/SecretTest.java
@@ -71,4 +71,19 @@ public class SecretTest extends TestCase {
Object o = Hudson.XSTREAM.fromXML(xml);
assertEquals(o,s);
}
+
+ public static class Foo {
+ Secret password;
+ }
+
+ /**
+ * Makes sure the serialization form is backward compatible with String.
+ */
+ public void testCompatibilityFromString() {
+ String tagName = Foo.class.getName().replace("$","-");
+ String xml = "<"+tagName+">