Interface FilePasswordProvider
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface FilePasswordProvider
- Author:
- Apache MINA SSHD Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceFilePasswordProvider.Decoder<T>Something that can produce a result given a password.static classFilePasswordProvider.ResourceDecodeResult
-
Field Summary
Fields Modifier and Type Field Description static FilePasswordProviderEMPTYAn "empty" provider that returnsnull- i.e., unprotected key file
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T> Tdecode(SessionContext session, NamedResource resourceKey, FilePasswordProvider.Decoder<? extends T> decoder)Obtains the password throughgetPassword(SessionContext, NamedResource, int), invokes theFilePasswordProvider.Decoderand thenhandleDecodeAttemptResult(SessionContext, NamedResource, int, String, Exception)and then returns the decoded result.StringgetPassword(SessionContext session, NamedResource resourceKey, int retryIndex)default FilePasswordProvider.ResourceDecodeResulthandleDecodeAttemptResult(SessionContext session, NamedResource resourceKey, int retryIndex, String password, Exception err)Invoked to inform the password provide about the decoding result.static FilePasswordProviderof(String password)
-
-
-
Field Detail
-
EMPTY
static final FilePasswordProvider EMPTY
An "empty" provider that returnsnull- i.e., unprotected key file
-
-
Method Detail
-
getPassword
String getPassword(SessionContext session, NamedResource resourceKey, int retryIndex) throws IOException
- Parameters:
session- TheSessionContextfor invoking this load command - may benullif not invoked within a session context (e.g., offline tool or session unknown).resourceKey- The resource key representing the private fileretryIndex- The zero-based index of the invocation for the specific resource (in case invoked several times for the same resource)- Returns:
- The password - if
null/empty then no password is required - Throws:
IOException- if cannot resolve password- See Also:
handleDecodeAttemptResult(SessionContext, NamedResource, int, String, Exception)
-
handleDecodeAttemptResult
default FilePasswordProvider.ResourceDecodeResult handleDecodeAttemptResult(SessionContext session, NamedResource resourceKey, int retryIndex, String password, Exception err) throws IOException, GeneralSecurityException
Invoked to inform the password provide about the decoding result. Note: any exception thrown from this method (including if called to inform about success) will be propagated instead of the original (if any was reported)- Parameters:
session- TheSessionContextfor invoking this load command - may benullif not invoked within a session context (e.g., offline tool or session unknown).resourceKey- The resource key representing the private fileretryIndex- The zero-based index of the invocation for the specific resource (in case invoked several times for the same resource). If success report, it indicates the number of retries it took to succeedpassword- The password that was attemptederr- The attempt result -nullfor success- Returns:
- How to proceed in case of error - ignored if invoked in order to report
success. Note:
nullis same asFilePasswordProvider.ResourceDecodeResult.TERMINATE. - Throws:
IOException- If cannot resolve a new passwordGeneralSecurityException- If not attempting to resolve a new password
-
decode
default <T> T decode(SessionContext session, NamedResource resourceKey, FilePasswordProvider.Decoder<? extends T> decoder) throws IOException, GeneralSecurityException
Obtains the password throughgetPassword(SessionContext, NamedResource, int), invokes theFilePasswordProvider.Decoderand thenhandleDecodeAttemptResult(SessionContext, NamedResource, int, String, Exception)and then returns the decoded result. If the decoder fails and theFilePasswordProvider.ResourceDecodeResultisFilePasswordProvider.ResourceDecodeResult.RETRY, the whole process is re-tried.- Type Parameters:
T- Result type of the decoder- Parameters:
session-SessionContext, may benullresourceKey-NamedResourceused for error reportingdecoder-FilePasswordProvider.Decoderto produce the result given a password- Returns:
- the decoder's result, or
nullif none - Throws:
IOException- if an I/O problem occursGeneralSecurityException- if the decoder throws it
-
of
static FilePasswordProvider of(String password)
-
-