Skip to content

Commit

Permalink
Scramble password
Browse files Browse the repository at this point in the history
  • Loading branch information
ohtake committed Jun 10, 2012
1 parent 95ddcb6 commit 400602b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.deploy;

import hudson.util.Scrambler;
import org.codehaus.cargo.container.property.RemotePropertySet;

/**
Expand All @@ -8,15 +9,27 @@
public abstract class PasswordProtectedAdapterCargo extends DefaultCargoContainerAdapterImpl {
@Property(RemotePropertySet.USERNAME)
public final String userName;
private final String password;
@Deprecated // backward compatibility
private String password;
private String passwordScrambled;

public PasswordProtectedAdapterCargo(String userName, String password) {
this.password = password;
this.password = null;
this.passwordScrambled = Scrambler.scramble(password);
this.userName = userName;
}

@Property(RemotePropertySet.PASSWORD)
public String getPassword() {
return password;
return Scrambler.descramble(passwordScrambled);
}

private Object readResolve() {
// backward compatibility
if(passwordScrambled == null && password != null){
passwordScrambled = Scrambler.scramble(password);
password = null;
}
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package hudson.plugins.deploy;

import hudson.util.XStream2;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.matchers.JUnitMatchers;

public class PasswordProtectedAdapterCargoTest {
@Test
public void testDeserializeOldPlainPassword () {
String plainPassword = "plain-password";
String oldXml = "<hudson.plugins.deploy.glassfish.GlassFish3xAdapter><userName>manager</userName><password>"
+ plainPassword + "</password><home>/</home><hostname></hostname></hudson.plugins.deploy.glassfish.GlassFish3xAdapter>";
XStream2 xs = new XStream2();

PasswordProtectedAdapterCargo adapter = (PasswordProtectedAdapterCargo)xs.fromXML(oldXml);
Assert.assertEquals(plainPassword, adapter.getPassword());

String newXml = xs.toXML(adapter);
Assert.assertThat("Password should be scrambled", newXml, CoreMatchers.not(JUnitMatchers.containsString(plainPassword)));
}
}

0 comments on commit 400602b

Please sign in to comment.