mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 02:26:18 +00:00
[FIXED JENKINS-4000] , [FIXED JENKINS-4002] encrypt proxy password
Proxy password is encrypted in xml config file, and in the UI
This commit is contained in:
1 parent
78c709e913
commit
c4d9fe8e07
2 files changed
+30
-6
No files matched your search
@@ -27,6 +27,7 @@ import hudson.model.Hudson;
|
||||
import hudson.model.Saveable;
|
||||
import hudson.model.listeners.SaveableListener;
|
||||
import hudson.util.Scrambler;
|
||||
import hudson.util.Secret;
|
||||
import hudson.util.XStream2;
|
||||
|
||||
import java.io.File;
|
||||
@@ -59,10 +60,17 @@ public final class ProxyConfiguration implements Saveable {
|
||||
public final int port;
|
||||
|
||||
/**
|
||||
* Possibly null proxy user name and password.
|
||||
* Password is base64 scrambled since this is persisted to disk.
|
||||
* Possibly null proxy user name.
|
||||
*/
|
||||
private final String userName,password;
|
||||
private final String userName;
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* encrypted password
|
||||
*/
|
||||
private Secret secretPassword;
|
||||
|
||||
public ProxyConfiguration(String name, int port) {
|
||||
this(name,port,null,null);
|
||||
@@ -72,15 +80,24 @@ public final class ProxyConfiguration implements Saveable {
|
||||
this.name = name;
|
||||
this.port = port;
|
||||
this.userName = userName;
|
||||
this.password = Scrambler.scramble(password);
|
||||
this.secretPassword = Secret.fromString(password);
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
// This method is public, if it was public only for jelly, then should make it private (or inline contents)
|
||||
// Have left public, as can't tell if anyone else is using from plugins
|
||||
/**
|
||||
* @return the password in plain text
|
||||
*/
|
||||
public String getPassword() {
|
||||
return Scrambler.descramble(password);
|
||||
return Secret.toString(secretPassword);
|
||||
}
|
||||
|
||||
public String getEncryptedPassword() {
|
||||
return (secretPassword == null) ? null : secretPassword.getEncryptedValue();
|
||||
}
|
||||
|
||||
public Proxy createProxy() {
|
||||
@@ -94,6 +111,13 @@ public final class ProxyConfiguration implements Saveable {
|
||||
SaveableListener.fireOnChange(this, config);
|
||||
}
|
||||
|
||||
public Object readResolve() {
|
||||
if (secretPassword == null)
|
||||
secretPassword = Secret.fromString(Scrambler.descramble(password));
|
||||
password = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static XmlFile getXmlFile() {
|
||||
return new XmlFile(XSTREAM, new File(Hudson.getInstance().getRootDir(), "proxy.xml"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user