Package org.eclipse.jgit.transport.sshd
Class IdentityPasswordProvider
- java.lang.Object
-
- org.eclipse.jgit.transport.sshd.IdentityPasswordProvider
-
- All Implemented Interfaces:
KeyPasswordProvider
public class IdentityPasswordProvider extends java.lang.Object implements KeyPasswordProvider
AKeyPasswordProviderbased on aCredentialsProvider.- Since:
- 5.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classIdentityPasswordProvider.StateA simple state object for repeated attempts to get a password for a resource.
-
Field Summary
Fields Modifier and Type Field Description private intattemptsThe number of times to ask successively for a password for a given identity resource.private java.util.Map<URIish,IdentityPasswordProvider.State>currentCounts per resource key.private CredentialsProviderprovider
-
Constructor Summary
Constructors Constructor Description IdentityPasswordProvider(CredentialsProvider provider)Creates a newIdentityPasswordProviderto get the passphrase for an encrypted identity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancelAuthentication()Cancels the authentication process.intgetAttempts()Gets the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.protected CredentialsProvidergetCredentialsProvider()Retrieves the JGitCredentialsProviderto 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, java.lang.String message)Obtains the passphrase/password for an encrypted private key via theconfigured CredentialsProvider.booleankeyLoaded(URIish uri, int attempt, java.lang.Exception error)Invoked after a key has been loaded.protected booleankeyLoaded(URIish uri, IdentityPasswordProvider.State state, char[] password, java.lang.Exception err)Invoked to inform the password provider about the decoding result.voidsetAttempts(int numberOfPasswordPrompts)Define the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.
-
-
-
Field Detail
-
provider
private CredentialsProvider provider
-
attempts
private int attempts
The number of times to ask successively for a password for a given identity resource.
-
current
private final java.util.Map<URIish,IdentityPasswordProvider.State> current
Counts per resource key.
-
-
Constructor Detail
-
IdentityPasswordProvider
public IdentityPasswordProvider(CredentialsProvider provider)
Creates a newIdentityPasswordProviderto get the passphrase for an encrypted identity.- Parameters:
provider- to use
-
-
Method Detail
-
setAttempts
public void setAttempts(int numberOfPasswordPrompts)
Description copied from interface:KeyPasswordProviderDefine the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.- Specified by:
setAttemptsin interfaceKeyPasswordProvider- Parameters:
numberOfPasswordPrompts- number of times to ask for a passphrase;IllegalArgumentExceptionmay be thrown if <= 0
-
getAttempts
public int getAttempts()
Description copied from interface:KeyPasswordProviderGets 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:
getAttemptsin interfaceKeyPasswordProvider- Returns:
- the number of times to ask for a passphrase; should be >= 1.
-
getPassphrase
public char[] getPassphrase(URIish uri, int attempt) throws java.io.IOException
Description copied from interface:KeyPasswordProviderObtains a passphrase to use to decrypt an ecrypted private key. Returningnullor an empty array will skip this key. To cancel completely, the operation should raiseCancellationException.- Specified by:
getPassphrasein 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:
java.io.IOException- if no password can be obtained
-
getPassword
protected char[] getPassword(URIish uri, int attempt, @NonNull IdentityPasswordProvider.State state) throws java.io.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
nullor the empty string if none available. - Throws:
java.io.IOException- if an error occurs
-
getCredentialsProvider
protected CredentialsProvider getCredentialsProvider()
Retrieves the JGitCredentialsProviderto use for user interaction.- Returns:
- the
CredentialsProviderornullif none configured - Since:
- 5.10
-
getPassword
protected char[] getPassword(URIish uri, java.lang.String message)
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 benullor empty if none- Returns:
- the password entered, or
nullif noCredentialsProvideris configured or none was entered - Throws:
java.util.concurrent.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:
java.util.concurrent.CancellationException- always- Since:
- 5.10
-
keyLoaded
protected boolean keyLoaded(URIish uri, IdentityPasswordProvider.State state, char[] password, java.lang.Exception err) throws java.io.IOException, java.security.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 -nullfor success- Returns:
- how to proceed in case of error
- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
keyLoaded
public boolean keyLoaded(URIish uri, int attempt, java.lang.Exception error) throws java.io.IOException, java.security.GeneralSecurityException
Description copied from interface:KeyPasswordProviderInvoked after a key has been loaded. If this raises an exception, the originalerroris lost unless it is attached to that exception.- Specified by:
keyLoadedin 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 thaturirefers to a non-encrypted keyerror-nullif the key was loaded successfully; otherwise an exception indicating why the key could not be loaded- Returns:
trueto re-try again;falseto re-raise theerrorexception; Ignored if the key was loaded successfully, i.e., iferror == null.- Throws:
java.io.IOExceptionjava.security.GeneralSecurityException
-
-