public class IdentityPasswordProvider extends 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.
|
| Constructor and Description |
|---|
IdentityPasswordProvider(CredentialsProvider provider)
Creates a new
IdentityPasswordProvider to get the passphrase for
an encrypted identity. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
cancelAuthentication()
Cancels the authentication process.
|
int |
getAttempts()
Gets the maximum number of attempts to get a passphrase that should be
attempted for one identity resource through this provider.
|
protected CredentialsProvider |
getCredentialsProvider()
Retrieves the JGit
CredentialsProvider to use for user
interaction. |
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.
|
protected char[] |
getPassword(URIish uri,
String message)
Obtains the passphrase/password for an encrypted private key via the
configured CredentialsProvider. |
protected boolean |
keyLoaded(URIish uri,
IdentityPasswordProvider.State state,
char[] password,
Exception err)
Invoked to inform the password provider about the decoding result.
|
boolean |
keyLoaded(URIish uri,
int attempt,
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.
|
public IdentityPasswordProvider(CredentialsProvider provider)
IdentityPasswordProvider to get the passphrase for
an encrypted identity.provider - to usepublic void setAttempts(int numberOfPasswordPrompts)
KeyPasswordProvidersetAttempts in interface KeyPasswordProvidernumberOfPasswordPrompts - number of times to ask for a passphrase;
IllegalArgumentException may be thrown if <= 0public int getAttempts()
KeyPasswordProvidergetAttempts in interface KeyPasswordProviderpublic char[] getPassphrase(URIish uri, int attempt) throws IOException
KeyPasswordProvidernull or an empty array will skip this key. To cancel completely,
the operation should raise
CancellationException.getPassphrase in interface KeyPasswordProvideruri - identifying the key resource that is being attempted to be
loadedattempt - the number of previous attempts to get a passphrase; >= 0IOException - if no password can be obtainedprotected char[] getPassword(URIish uri, int attempt, @NonNull IdentityPasswordProvider.State state) throws 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.IOException - if an error occursprotected CredentialsProvider getCredentialsProvider()
CredentialsProvider to use for user
interaction.CredentialsProvider or null if none
configuredprotected char[] getPassword(URIish uri, String message)
configured CredentialsProvider.uri - identifying the resource to obtain a password formessage - optional message text to display; may be null or empty
if nonenull if no
CredentialsProvider is configured or none was enteredCancellationException - if the user canceled the operationprotected void cancelAuthentication()
getPassword(URIish, String) when the user interaction has been
canceled. If this throws a
CancellationException, the authentication
process is aborted; otherwise it may continue with the next configured
authentication mechanism, if any.
This default implementation always throws a
CancellationException.
CancellationException - alwaysprotected boolean keyLoaded(URIish uri, IdentityPasswordProvider.State state, char[] password, Exception err) throws IOException, 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 successIOExceptionGeneralSecurityExceptionpublic boolean keyLoaded(URIish uri, int attempt, Exception error) throws IOException, GeneralSecurityException
KeyPasswordProvidererror is lost unless it is attached to that exception.keyLoaded in interface KeyPasswordProvideruri - 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.IOExceptionGeneralSecurityExceptionCopyright © 2020 Eclipse JGit Project. All rights reserved.