Interface PasswordAgent
The PasswordAgent
provides access to the internal mechanisms of FirstSpirit which allow to encrypt and
decrypt password strings.
Although the FirstSpirit internal mechanisms are used, the encryption is not compatible to the password property
encryption used by the FirstSpirit server.
There are three possible ways to provide an encryption key. If more than one key is available, the key with the highest priority is used. The ordering from lowest to highest priority is as follows:
- Internal obfuscation key, always available
- Key file configured in
fs-server.conf
- Key environment variable configured in
fs-server.conf
Password string encryption is always available, even when it is not activated for internal password property
handling of the FirstSpirit server.
Reminder: If keys are removed or unavailable, all passwords encrypted with such a key are
not decryptable.
A password namespace string is part of the encryption process. This namespace can be a constant, for instance a class or module name or a random token. The namespace used for decrypting a password must be the same used for encrypting the password or decryption will not be successful. It is the responsibility of the API user to provide a namespace. Using a constant namespace is a viable option and not a security drawback.
- Since:
- 5.2.1904
-
Field Summary
Modifier and TypeFieldDescriptionstatic final SpecialistType<PasswordAgent>
The agent's technical type to be used to request the agent from aSpecialistsBroker
. -
Method Summary
Modifier and TypeMethodDescription@NotNull String
decryptPassword
(@NotNull String namespace, @NotNull String password) Decrypts a password.
This method uses the FirstSpirit internal password encryption mechanisms to perform the encryption.@NotNull String
encryptPassword
(@NotNull String namespace, @NotNull String password) Encrypts a password.
This method uses the FirstSpirit internal password encryption mechanisms to perform the encryption.boolean
isEncryptedPassword
(@Nullable String password) Indicates if the given string is an encrypted password.
The password string may benull
, in this casefalse
is returned.boolean
isHigherPriorityKeyAvailableForPassword
(@NotNull String password) Tests whether the encrypted password has been encrypted with a low priority key while a higher priority key is available on the FirstSpirit server in the meantime.boolean
Indicates if the password encryption is enabled for the FirstSpirit server.
Even if the password encryption for the FirstSpirit server is disabled (i.e. when this method returnsfalse
), it is possible to use theencryptPassword(String, String)
anddecryptPassword(String, String)
methods.
To enable the internal password encryption of the FirstSpirit server, please use thepassword.encryption.active
setting in thefs-server.conf
file.
-
Field Details
-
TYPE
The agent's technical type to be used to request the agent from aSpecialistsBroker
.- Since:
- 5.2.1904
-
-
Method Details
-
isPasswordEncryptionEnabled
boolean isPasswordEncryptionEnabled()Indicates if the password encryption is enabled for the FirstSpirit server.
Even if the password encryption for the FirstSpirit server is disabled (i.e. when this method returnsfalse
), it is possible to use theencryptPassword(String, String)
anddecryptPassword(String, String)
methods.
To enable the internal password encryption of the FirstSpirit server, please use thepassword.encryption.active
setting in thefs-server.conf
file.- Returns:
true
if the password encryption is enabled for the FirstSpirit server,false
otherwise.- Since:
- 5.2.1904
-
isEncryptedPassword
Indicates if the given string is an encrypted password.
The password string may benull
, in this casefalse
is returned. If the password string is identified as an encrypted password, it can be decrypted by calling thedecryptPassword(String, String)
method.
Note: This method does not decrypt or validate the encrypted password, only the string prefix is examined.- Parameters:
password
- The encrypted password ornull
.- Returns:
true
if the password string was identified as an encrypted password,false
otherwise.- Since:
- 5.2.1904
-
isHigherPriorityKeyAvailableForPassword
Tests whether the encrypted password has been encrypted with a low priority key while a higher priority key is available on the FirstSpirit server in the meantime. Returnstrue
if a higher priority key is available and re-encrypting the encrypted password by calling theencryptPassword(String, String)
method as well as updating the stored password string should be performed.
Note: This method does not decrypt or validate the encrypted password, only the used key is examined.- Parameters:
password
- The encrypted password, must not benull
.- Returns:
true
if the encrypted password should be re-encrypted and updated because a higher priority key is available,false
otherwise.- Throws:
NullPointerException
- If the password isnull
.IllegalArgumentException
- If the password is not an encrypted password.- Since:
- 5.2.1904
-
encryptPassword
@NotNull @NotNull String encryptPassword(@NotNull @NotNull String namespace, @NotNull @NotNull String password) Encrypts a password.
This method uses the FirstSpirit internal password encryption mechanisms to perform the encryption. It always returns an encrypted password even if the password encryption is disabled for the FirstSpirit server. If no other key is available on the FirstSpirit server, an internal obfuscation key is used.- Parameters:
namespace
- Choosable password namespace. The namespace is part of the encryption process, only passwords with the same namespace are compatible and decryptable. Must not benull
.password
- The clear text password, must not benull
.- Returns:
- The encrypted password.
- Throws:
NullPointerException
- If one of the parameters isnull
.- Since:
- 5.2.1904
-
decryptPassword
@NotNull @NotNull String decryptPassword(@NotNull @NotNull String namespace, @NotNull @NotNull String password) Decrypts a password.
This method uses the FirstSpirit internal password encryption mechanisms to perform the encryption. This method always returns a decrypted password even if the password encryption is disabled for the FirstSpirit server. If no other key is available on the FirstSpirit server, an internal obfuscation key is used.- Parameters:
namespace
- Choosable password namespace string. The namespace is part of the encryption process, only passwords with the same namespace are compatible and decryptable. Must not benull
.password
- The encrypted password, must not benull
.- Returns:
- The decrypted clear text password.
- Throws:
SecurityException
- If the encryption key is not (longer) available, the encrypted password was tampered with or the namespace is wrong.NullPointerException
- If one of the parameters isnull
.IllegalArgumentException
- If the password is not an encrypted password.- Since:
- 5.2.1904
-