Package org.eclipse.jgit.transport.sshd
Class IdentityPasswordProvider
java.lang.Object
org.eclipse.jgit.transport.sshd.IdentityPasswordProvider
- All Implemented Interfaces:
KeyPasswordProvider
A
KeyPasswordProvider
based on a CredentialsProvider
.- Since:
- 5.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A simple state object for repeated attempts to get a password for a resource. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
The number of times to ask successively for a password for a given identity resource.private final Map<URIish,
IdentityPasswordProvider.State> Counts per resource key.private CredentialsProvider
-
Constructor Summary
ConstructorsConstructorDescriptionIdentityPasswordProvider
(CredentialsProvider provider) Creates a newIdentityPasswordProvider
to get the passphrase for an encrypted identity. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Cancels the authentication process.int
Gets the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.protected CredentialsProvider
Retrieves the JGitCredentialsProvider
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 theconfigured CredentialsProvider
.boolean
Invoked after a key has been loaded.protected boolean
keyLoaded
(URIish uri, IdentityPasswordProvider.State state, char[] password, Exception err) Invoked to inform the password provider about the decoding result.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.
-
Field Details
-
provider
-
attempts
private int attemptsThe number of times to ask successively for a password for a given identity resource. -
current
Counts per resource key.
-
-
Constructor Details
-
IdentityPasswordProvider
Creates a newIdentityPasswordProvider
to get the passphrase for an encrypted identity.- Parameters:
provider
- to use
-
-
Method Details
-
setAttempts
public void setAttempts(int numberOfPasswordPrompts) Description copied from interface:KeyPasswordProvider
Define the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.- Specified by:
setAttempts
in interfaceKeyPasswordProvider
- Parameters:
numberOfPasswordPrompts
- number of times to ask for a passphrase;IllegalArgumentException
may be thrown if <= 0
-
getAttempts
public int getAttempts()Description copied from interface:KeyPasswordProvider
Gets the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider. The default return 1.- Specified by:
getAttempts
in interfaceKeyPasswordProvider
- Returns:
- the number of times to ask for a passphrase; should be >= 1.
-
getPassphrase
Description copied from interface:KeyPasswordProvider
Obtains a passphrase to use to decrypt an ecrypted private key. Returningnull
or an empty array will skip this key. To cancel completely, the operation should raiseCancellationException
.- Specified by:
getPassphrase
in interfaceKeyPasswordProvider
- Parameters:
uri
- identifying the key resource that is being attempted to be loadedattempt
- the number of previous attempts to get a passphrase; >= 0- Returns:
- the passphrase
- Throws:
IOException
- if no password can be obtained
-
getPassword
protected char[] getPassword(URIish uri, int attempt, @NonNull IdentityPasswordProvider.State state) throws IOException Retrieves a password to decrypt a private key.- Parameters:
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 password- Returns:
- the password, or
null
or the empty string if none available. - Throws:
IOException
- if an error occurs
-
getCredentialsProvider
Retrieves the JGitCredentialsProvider
to use for user interaction.- Returns:
- the
CredentialsProvider
ornull
if none configured - Since:
- 5.10
-
getPassword
Obtains the passphrase/password for an encrypted private key via theconfigured CredentialsProvider
.- Parameters:
uri
- identifying the resource to obtain a password formessage
- optional message text to display; may benull
or empty if none- Returns:
- the password entered, or
null
if noCredentialsProvider
is configured or none was entered - Throws:
CancellationException
- if the user canceled the operation- Since:
- 5.10
-
cancelAuthentication
protected void cancelAuthentication()Cancels the authentication process. Called bygetPassword(URIish, String)
when the user interaction has been canceled. If this throws aCancellationException
, the authentication process is aborted; otherwise it may continue with the next configured authentication mechanism, if any.This default implementation always throws a
CancellationException
.- Throws:
CancellationException
- always- Since:
- 5.10
-
keyLoaded
protected boolean keyLoaded(URIish uri, IdentityPasswordProvider.State state, char[] password, Exception err) throws IOException, GeneralSecurityException Invoked to inform the password provider about the decoding result.- Parameters:
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 success- Returns:
- how to proceed in case of error
- Throws:
IOException
GeneralSecurityException
-
keyLoaded
public boolean keyLoaded(URIish uri, int attempt, Exception error) throws IOException, GeneralSecurityException Description copied from interface:KeyPasswordProvider
Invoked after a key has been loaded. If this raises an exception, the originalerror
is lost unless it is attached to that exception.- Specified by:
keyLoaded
in interfaceKeyPasswordProvider
- Parameters:
uri
- identifying the key resource the key was attempted to be loaded fromattempt
- the number of timesKeyPasswordProvider.getPassphrase(URIish, int)
had been called; zero indicates thaturi
refers to a non-encrypted keyerror
-null
if the key was loaded successfully; otherwise an exception indicating why the key could not be loaded- Returns:
true
to re-try again;false
to re-raise theerror
exception; Ignored if the key was loaded successfully, i.e., iferror == null
.- Throws:
IOException
GeneralSecurityException
-