public final class GuardedString extends Object
java.lang.String
. That is, anything represented as
a String
is kept in memory as a clear text password and stays in
memory at least until it is garbage collected.
The GuardedString class alleviates this problem by storing the characters in memory in an encrypted form. The encryption key will be a randomly-generated key.
In their serialized form, GuardedString will be encrypted using a known default key. This is to provide a minimum level of protection regardless of the transport. For communications with the Remote Connector Framework it is recommended that deployments enable SSL for true encryption.
Applications may also wish to persist GuardedStrings. In the case of Identity Manager, it should convert GuardedStrings to EncryptedData so that they can be stored and managed using the Manage Encryption features of Identity Manager. Other applications may wish to serialize APIConfiguration as a whole. These applications are responsible for encrypting the APIConfiguration blob for an additional layer of security (beyond the basic default key encryption provided by GuardedString).
Modifier and Type | Class and Description |
---|---|
static interface |
GuardedString.Accessor
Callback interface for those times that it is necessary to access the
clear text of the secure string.
|
Constructor and Description |
---|
GuardedString()
Creates an empty secure string
|
GuardedString(char[] clearChars)
Initialized the GuardedString from the given clear characters.
|
Modifier and Type | Method and Description |
---|---|
void |
access(GuardedString.Accessor accessor)
Provides access to the clear-text value of the string in a controlled
fashion.
|
void |
appendChar(char c)
Appends a single clear-text character to the secure string.
|
GuardedString |
copy()
Create a copy of the string.
|
void |
dispose()
Clears the in-memory representation of the string.
|
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
isReadOnly()
Returns true if this string has been marked read-only.
|
void |
makeReadOnly()
Mark this string as read-only.
|
boolean |
verifyBase64SHA1Hash(String hash)
Verifies that this base-64 encoded SHA1 hash of this string matches the
given value.
|
public GuardedString()
public GuardedString(char[] clearChars)
clearChars
- The clear-text characterspublic void access(GuardedString.Accessor accessor)
NOTE: Callers are encouraged to use
verifyBase64SHA1Hash(String)
where possible if the intended use
is merely to verify the contents of the string match an expected hash
value.
accessor
- Accessor callback.IllegalStateException
- If the string has been disposedpublic void appendChar(char c)
c
- The character to append.IllegalStateException
- If the string is read-onlyIllegalStateException
- If the string has been disposedpublic void dispose()
public boolean isReadOnly()
IllegalStateException
- If the string has been disposedpublic void makeReadOnly()
IllegalStateException
- If the string has been disposedpublic GuardedString copy()
IllegalStateException
- If the string has been disposedpublic boolean verifyBase64SHA1Hash(String hash)
hash
- The hash to verify against.IllegalStateException
- If the string has been disposedCopyright © 2019. All rights reserved.