Top Description Inners Fields Constructors Methods
org.eclipse.jgit.transport.sshd

public Class IdentityPasswordProvider

extends Object
implements KeyPasswordProvider
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.transport.sshd.KeyPasswordProvider
Static Imports
java.text.MessageFormat.format

A KeyPasswordProvider based on a CredentialsProvider.
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
IdentityPasswordProvider.State

A simple state object for repeated attempts to get a password for a resource.

Field Summary

Modifier and TypeField and Description
private int
attempts

The number of times to ask successively for a password for a given identity resource.

private final Map<URIish, IdentityPasswordProvider.State>
current

Counts per resource key.

private CredentialsProvider

Constructor Summary

AccessConstructor and Description
public
IdentityPasswordProvider(CredentialsProvider
to use
provider
)

Creates a new IdentityPasswordProvider to get the passphrase for an encrypted identity.

Method Summary

Modifier and TypeMethod and Description
protected void
cancelAuthentication()

Cancels the authentication process.

public int
getAttempts()

Overrides default org.eclipse.jgit.transport.sshd.KeyPasswordProvider.getAttempts.

Gets the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.

protected CredentialsProvider

Returns:

the CredentialsProvider or null if none configured
getCredentialsProvider
()

Retrieves the JGit CredentialsProvider to use for user interaction.

public char[]
getPassphrase(URIish
identifying the key resource that is being attempted to be loaded
uri
,
int
the number of previous attempts to get a passphrase; >= 0
attempt
)

Implements org.eclipse.jgit.transport.sshd.KeyPasswordProvider.getPassphrase.

Obtains a passphrase to use to decrypt an ecrypted private key.

protected char[]

Returns:

the password, or null or the empty string if none available.
getPassword
(URIish
identifying the resource to obtain a password for
uri
,
int
number of previous attempts to get a passphrase
attempt
,
IdentityPasswordProvider.State
encapsulating state information about attempts to get the password
state
)

Retrieves a password to decrypt a private key.

protected char[]

Returns:

the password entered, or null if no CredentialsProvider is configured or none was entered
getPassword
(URIish
identifying the resource to obtain a password for
uri
,
String
optional message text to display; may be null or empty if none
message
)

Obtains the passphrase/password for an encrypted private key via the configured CredentialsProvider.

protected boolean

Returns:

how to proceed in case of error
keyLoaded
(URIish
identifying the key resource the key was attempted to be loaded from
uri
,
IdentityPasswordProvider.State
associated with this key
state
,
char[]
the password that was attempted
password
,
Exception
the attempt result - null for success
err
)

Invoked to inform the password provider about the decoding result.

public boolean
keyLoaded(URIish
identifying the key resource the key was attempted to be loaded from
uri
,
int
the number of times getPassphrase(URIish, int) had been called; zero indicates that uri refers to a non-encrypted key
attempt
,
Exception
null if the key was loaded successfully; otherwise an exception indicating why the key could not be loaded
error
)

Implements org.eclipse.jgit.transport.sshd.KeyPasswordProvider.keyLoaded.

Invoked after a key has been loaded.

public void
setAttempts(int
number of times to ask for a passphrase; IllegalArgumentException may be thrown if <= 0
numberOfPasswordPrompts
)

Implements org.eclipse.jgit.transport.sshd.KeyPasswordProvider.setAttempts.

Define the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attemptsback to summary
private int attempts

The number of times to ask successively for a password for a given identity resource.

currentback to summary
private final Map<URIish, IdentityPasswordProvider.State> current

Counts per resource key.

providerback to summary
private CredentialsProvider provider

Constructor Detail

IdentityPasswordProviderback to summary
public IdentityPasswordProvider(CredentialsProvider provider)

Creates a new IdentityPasswordProvider to get the passphrase for an encrypted identity.

Parameters
provider:CredentialsProvider

to use

Method Detail

cancelAuthenticationback to summary
protected void cancelAuthentication()

Cancels the authentication process. Called by getPassword(URIish, String) when the user interaction has been canceled. If this throws a java.util.concurrent.CancellationException, the authentication process is aborted; otherwise it may continue with the next configured authentication mechanism, if any.

This default implementation always throws a java.util.concurrent.CancellationException.

Exceptions
CancellationException:
always
Since
5.10
getAttemptsback to summary
public int getAttempts()

Overrides default org.eclipse.jgit.transport.sshd.KeyPasswordProvider.getAttempts.

Doc from org.eclipse.jgit.transport.sshd.KeyPasswordProvider.getAttempts.

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.

Returns:int

the number of times to ask for a passphrase; should be >= 1.

Annotations
@Override
getCredentialsProviderback to summary
protected CredentialsProvider getCredentialsProvider()

Retrieves the JGit CredentialsProvider to use for user interaction.

Returns:CredentialsProvider

the CredentialsProvider or null if none configured

Since
5.10
getPassphraseback to summary
public char[] getPassphrase(URIish uri, int attempt) throws IOException

Implements org.eclipse.jgit.transport.sshd.KeyPasswordProvider.getPassphrase.

Doc from org.eclipse.jgit.transport.sshd.KeyPasswordProvider.getPassphrase.

Obtains a passphrase to use to decrypt an ecrypted private key. Returning null or an empty array will skip this key. To cancel completely, the operation should raise java.util.concurrent.CancellationException.

Parameters
uri:URIish

identifying the key resource that is being attempted to be loaded

attempt:int

the number of previous attempts to get a passphrase; >= 0

Returns:char[]

the passphrase

Annotations
@Override
Exceptions
IOException:
if no password can be obtained
getPasswordback to summary
protected char[] getPassword(URIish uri, int attempt, IdentityPasswordProvider.State state) throws IOException

Retrieves a password to decrypt a private key.

Parameters
uri:URIish

identifying the resource to obtain a password for

attempt:int

number of previous attempts to get a passphrase

state:IdentityPasswordProvider.State

encapsulating state information about attempts to get the password

Returns:char[]

the password, or null or the empty string if none available.

Exceptions
IOException:
if an error occurs
getPasswordback to summary
protected char[] getPassword(URIish uri, String message)

Obtains the passphrase/password for an encrypted private key via the configured CredentialsProvider.

Parameters
uri:URIish

identifying the resource to obtain a password for

message:String

optional message text to display; may be null or empty if none

Returns:char[]

the password entered, or null if no CredentialsProvider is configured or none was entered

Exceptions
CancellationException:
if the user canceled the operation
Since
5.10
keyLoadedback to summary
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:URIish

identifying the key resource the key was attempted to be loaded from

state:IdentityPasswordProvider.State

associated with this key

password:char[]

the password that was attempted

err:Exception

the attempt result - null for success

Returns:boolean

how to proceed in case of error

Exceptions
IOException:
if an IO error occurred
GeneralSecurityException:
something went wrong
keyLoadedback to summary
public boolean keyLoaded(URIish uri, int attempt, Exception error) throws IOException, GeneralSecurityException

Implements org.eclipse.jgit.transport.sshd.KeyPasswordProvider.keyLoaded.

Doc from org.eclipse.jgit.transport.sshd.KeyPasswordProvider.keyLoaded.

Invoked after a key has been loaded. If this raises an exception, the original error is lost unless it is attached to that exception.

Parameters
uri:URIish

identifying the key resource the key was attempted to be loaded from

attempt:int

the number of times getPassphrase(URIish, int) had been called; zero indicates that uri refers to a non-encrypted key

error:Exception

null if the key was loaded successfully; otherwise an exception indicating why the key could not be loaded

Returns:boolean

true to re-try again; false to re-raise the error exception; Ignored if the key was loaded successfully, i.e., if error == null.

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
GeneralSecurityException:
something went wrong
setAttemptsback to summary
public void setAttempts(int numberOfPasswordPrompts)

Implements org.eclipse.jgit.transport.sshd.KeyPasswordProvider.setAttempts.

Doc from org.eclipse.jgit.transport.sshd.KeyPasswordProvider.setAttempts.

Define the maximum number of attempts to get a passphrase that should be attempted for one identity resource through this provider.

Parameters
numberOfPasswordPrompts:int

number of times to ask for a passphrase; IllegalArgumentException may be thrown if <= 0

Annotations
@Override
org.eclipse.jgit.transport.sshd back to summary

protected Class IdentityPasswordProvider.State

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.transport.sshd.IdentityPasswordProvider.State

A simple state object for repeated attempts to get a password for a resource.

Field Summary

Modifier and TypeField and Description
private int
private char[]

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the count
getCount
()

Obtains the current count.

public char[]

Returns:

the password, or null if none was obtained
getPassword
()

Retrieves the password from the current attempt.

public int

Returns:

the incremented count.
incCount
()

Increments the current count.

public void
setPassword(char[]
the password
password
)

Remembers the password.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private int count
passwordback to summary
private char[] password

Constructor Detail

Stateback to summary
protected State()

Method Detail

getCountback to summary
public int getCount()

Obtains the current count. The initial count is zero.

Returns:int

the count

getPasswordback to summary
public char[] getPassword()

Retrieves the password from the current attempt.

Returns:char[]

the password, or null if none was obtained

incCountback to summary
public int incCount()

Increments the current count. Should be called for each new attempt to get a password.

Returns:int

the incremented count.

setPasswordback to summary
public void setPassword(char[] password)

Remembers the password.

Parameters
password:char[]

the password