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)
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 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; >= 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 successIOException
GeneralSecurityException
public boolean keyLoaded(URIish uri, int attempt, Exception error) throws IOException, 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
.IOException
GeneralSecurityException
Copyright © 2021 Eclipse JGit Project. All rights reserved.