Skip to content

Commit

Permalink
[FIXED JENKINS-44171] Editing the "description" field of a global cre…
Browse files Browse the repository at this point in the history
…dential deletes the "usage" history.

- Side-effect, all existing usage tracking will now be lost
  • Loading branch information
stephenc committed Jul 20, 2017
1 parent 8d4352e commit 3817b35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Expand Up @@ -52,7 +52,6 @@
import hudson.model.ParametersAction;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.User;
import hudson.model.queue.Tasks;
import hudson.security.ACL;
Expand Down Expand Up @@ -102,7 +101,7 @@
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;

import static com.cloudbees.plugins.credentials.CredentialsStoreAction.SECRETS_REDACTED;
import static com.cloudbees.plugins.credentials.CredentialsStoreAction.FINGERPRINT_XML;

/**
* An extension point for providing {@link Credentials}.
Expand Down Expand Up @@ -1371,7 +1370,7 @@ public static Fingerprint getFingerprintOf(@NonNull Credentials c) throws IOExce
MessageDigest md5 = MessageDigest.getInstance("MD5");
DigestOutputStream out = new DigestOutputStream(new NullOutputStream(), md5);
try {
SECRETS_REDACTED.toXML(c, new OutputStreamWriter(out, Charset.forName("UTF-8")));
FINGERPRINT_XML.toXML(c, new OutputStreamWriter(out, Charset.forName("UTF-8")));
} finally {
IOUtils.closeQuietly(out);
}
Expand All @@ -1397,7 +1396,7 @@ public static Fingerprint getOrCreateFingerprintOf(@NonNull Credentials c) throw
MessageDigest md5 = MessageDigest.getInstance("MD5");
DigestOutputStream out = new DigestOutputStream(new NullOutputStream(), md5);
try {
SECRETS_REDACTED.toXML(c, new OutputStreamWriter(out, Charset.forName("UTF-8")));
FINGERPRINT_XML.toXML(c, new OutputStreamWriter(out, Charset.forName("UTF-8")));
} finally {
IOUtils.closeQuietly(out);
}
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.domains.DomainSpecification;
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
Expand Down Expand Up @@ -133,9 +134,16 @@ public abstract class CredentialsStoreAction
*/
public static final XStream2 SECRETS_REDACTED;

/**
* An {@link XStream2} that replaces {@link Secret} instances with {@literal REDACTED} and omits fields that
* should be excluded from credentials fingerprinting.
*
* @since 2.1.15
*/
public static final XStream2 FINGERPRINT_XML;

static {
SECRETS_REDACTED = new XStream2();
SECRETS_REDACTED.registerConverter(new Converter() {
Converter converter = new Converter() {
/**
* {@inheritDoc}
*/
Expand All @@ -157,7 +165,13 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC
public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
return null;
}
});
};
SECRETS_REDACTED = new XStream2();
SECRETS_REDACTED.registerConverter(converter);
FINGERPRINT_XML = new XStream2();
FINGERPRINT_XML.omitField(BaseStandardCredentials.class, "description");
FINGERPRINT_XML.omitField(StandardCredentials.class, "description");
FINGERPRINT_XML.registerConverter(converter);
}

/**
Expand Down

0 comments on commit 3817b35

Please sign in to comment.