public class IdentityPasswordProvider extends java.lang.Object implements KeyPasswordProvider
KeyPasswordProvider
based on a CredentialsProvider
.Modifier and Type | Class and Description |
---|---|
protected static class |
IdentityPasswordProvider.State
A simple state object for repeated attempts to get a password for a
resource.
|
Modifier and Type | Field and Description |
---|---|
private int |
attempts
The number of times to ask successively for a password for a given
identity resource.
|
private java.util.Map<URIish,IdentityPasswordProvider.State> |
current
Counts per resource key.
|
private CredentialsProvider |
provider |
Constructor and Description |
---|
IdentityPasswordProvider(CredentialsProvider provider)
Creates a new
IdentityPasswordProvider to get the passphrase for
an encrypted identity. |
Modifier and Type | Method and Description |
---|---|
int |
getAttempts()
Gets the maximum number of attempts to get a passphrase that should be
attempted for one identity resource through this provider.
|
char[] |
getPassphrase(URIish uri,
int attempt)
Obtains a passphrase to use to decrypt an ecrypted private key.
|
protected char[] |
getPassword(URIish uri,
int attempt,
IdentityPasswordProvider.State state)
Retrieves a password to decrypt a private key.
|
private char[] |
getPassword(URIish uri,
java.lang.String message) |
protected boolean |
keyLoaded(URIish uri,
IdentityPasswordProvider.State state,
char[] password,
java.lang.Exception err)
Invoked to inform the password provider about the decoding result.
|
boolean |
keyLoaded(URIish uri,
int attempt,
java.lang.Exception error)
Invoked after a key has been loaded.
|
void |
setAttempts(int numberOfPasswordPrompts)
Define the maximum number of attempts to get a passphrase that should be
attempted for one identity resource through this provider.
|
private CredentialsProvider provider
private int attempts
private final java.util.Map<URIish,IdentityPasswordProvider.State> current
public IdentityPasswordProvider(CredentialsProvider provider)
IdentityPasswordProvider
to get the passphrase for
an encrypted identity.provider
- to usepublic void setAttempts(int numberOfPasswordPrompts)
KeyPasswordProvider
setAttempts
in interface KeyPasswordProvider
numberOfPasswordPrompts
- number of times to ask for a passphrase;
IllegalArgumentException
may be thrown if <= 0public int getAttempts()
KeyPasswordProvider
getAttempts
in interface KeyPasswordProvider
public char[] getPassphrase(URIish uri, int attempt) throws java.io.IOException
KeyPasswordProvider
null
or an empty array will skip this key. To cancel completely,
the operation should raise
CancellationException
.getPassphrase
in interface KeyPasswordProvider
uri
- identifying the key resource that is being attempted to be
loadedattempt
- the number of previous attempts to get a passphrase; >= 0java.io.IOException
- if no password can be obtainedprotected char[] getPassword(URIish uri, int attempt, @NonNull IdentityPasswordProvider.State state) throws java.io.IOException
uri
- identifying the resource to obtain a password forattempt
- number of previous attempts to get a passphrasestate
- encapsulating state information about attempts to get the
passwordnull
or the empty string if none
available.java.io.IOException
- if an error occursprivate char[] getPassword(URIish uri, java.lang.String message)
protected boolean keyLoaded(URIish uri, IdentityPasswordProvider.State state, char[] password, java.lang.Exception err) throws java.io.IOException, java.security.GeneralSecurityException
uri
- identifying the key resource the key was attempted to be
loaded fromstate
- associated with this keypassword
- the password that was attemptederr
- the attempt result - null
for successjava.io.IOException
java.security.GeneralSecurityException
public boolean keyLoaded(URIish uri, int attempt, java.lang.Exception error) throws java.io.IOException, java.security.GeneralSecurityException
KeyPasswordProvider
error
is lost unless it is attached to that exception.keyLoaded
in interface KeyPasswordProvider
uri
- identifying the key resource the key was attempted to be
loaded fromattempt
- the number of times KeyPasswordProvider.getPassphrase(URIish, int)
had
been called; zero indicates that uri
refers to a
non-encrypted keyerror
- null
if the key was loaded successfully; otherwise an
exception indicating why the key could not be loadedtrue
to re-try again; false
to re-raise the
error
exception; Ignored if the key was loaded
successfully, i.e., if error == null
.java.io.IOException
java.security.GeneralSecurityException