Package hudson.util
Class Secret
- java.lang.Object
-
- hudson.util.Secret
-
- All Implemented Interfaces:
Serializable
public final class Secret extends Object implements Serializable
GlorifiedStringthat uses encryption in the persisted form, to avoid accidental exposure of a secret.This is not meant as a protection against code running in the same VM, nor against an attacker who has local file system access on Jenkins master.
Secrets can correctly read-in plain text password, so this allows the existing String field to be updated toSecret.- Author:
- Kohsuke Kawaguchi
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSecret.ConverterImpl
-
Field Summary
Fields Modifier and Type Field Description static booleanAUTO_ENCRYPT_PASSWORD_CONTROLstatic booleanBLANK_NONSECRET_PASSWORD_FIELDS_WITHOUT_ITEM_CONFIGUREstatic PatternENCRYPTED_VALUE_PATTERNPattern matching a possible output ofgetEncryptedValue()Basically, any Base64-encoded value optionally wrapped by{}.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Secretdecrypt(String data)Reverse operation ofgetEncryptedValue().booleanequals(Object that)static SecretfromString(String data)Attempts to treat the given string first as a cipher text, and if it doesn't work, treat the given string as the unencrypted secret value.static CiphergetCipher(String algorithm)Workaround for JENKINS-6459 / GLASSFISH-11862 This method uses specific provider selected via hudson.util.Secret.provider system property to provide a workaround for the above bug where default provide gives an unusable instance.StringgetEncryptedValue()Encryptsvalueand returns it in an encoded printable form.StringgetPlainText()Obtains the plain text password.inthashCode()StringtoString()Deprecated.as of 1.356 UsetoString(Secret)to avoid NPE in case Secret is null.static StringtoString(Secret s)Works just liketoString()but avoids NPE when the secret is null.
-
-
-
Field Detail
-
ENCRYPTED_VALUE_PATTERN
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static final Pattern ENCRYPTED_VALUE_PATTERN
Pattern matching a possible output ofgetEncryptedValue()Basically, any Base64-encoded value optionally wrapped by{}. You must then calldecrypt(String)to eliminate false positives.- See Also:
ENCRYPTED_VALUE_PATTERN
-
AUTO_ENCRYPT_PASSWORD_CONTROL
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static final boolean AUTO_ENCRYPT_PASSWORD_CONTROL
-
BLANK_NONSECRET_PASSWORD_FIELDS_WITHOUT_ITEM_CONFIGURE
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean BLANK_NONSECRET_PASSWORD_FIELDS_WITHOUT_ITEM_CONFIGURE
-
-
Method Detail
-
toString
@Deprecated public String toString()
Deprecated.as of 1.356 UsetoString(Secret)to avoid NPE in case Secret is null. Or if you really know what you are doing, use thegetPlainText()method.Obtains the secret in a plain text.- Overrides:
toStringin classObject- See Also:
getEncryptedValue()
-
getPlainText
@NonNull public String getPlainText()
Obtains the plain text password. Before using this method, ask yourself if you'd be better off usingtoString(Secret)to avoid NPE.
-
getEncryptedValue
public String getEncryptedValue()
Encryptsvalueand returns it in an encoded printable form.- See Also:
toString()
-
decrypt
@CheckForNull public static Secret decrypt(@CheckForNull String data)
Reverse operation ofgetEncryptedValue(). Returns null if the given cipher text was invalid.
-
getCipher
public static Cipher getCipher(String algorithm) throws GeneralSecurityException
Workaround for JENKINS-6459 / GLASSFISH-11862 This method uses specific provider selected via hudson.util.Secret.provider system property to provide a workaround for the above bug where default provide gives an unusable instance. (Glassfish Enterprise users should set value of this property to "SunJCE")- Throws:
GeneralSecurityException
-
fromString
@NonNull public static Secret fromString(@CheckForNull String data)
Attempts to treat the given string first as a cipher text, and if it doesn't work, treat the given string as the unencrypted secret value.Useful for recovering a value from a form field.
-
toString
@NonNull public static String toString(@CheckForNull Secret s)
Works just liketoString()but avoids NPE when the secret is null. To be consistent withfromString(String), this method doesn't distinguish empty password and null password.
-
-