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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Something that can produce a result given a password.static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FilePasswordProvider
An "empty" provider that returnsnull
- i.e., unprotected key file -
Method Summary
Modifier and TypeMethodDescriptiondefault <T> T
decode
(SessionContext session, NamedResource resourceKey, FilePasswordProvider.Decoder<? extends T> decoder) Obtains the password throughgetPassword(SessionContext, NamedResource, int)
, invokes theFilePasswordProvider.Decoder
and thenhandleDecodeAttemptResult(SessionContext, NamedResource, int, String, Exception)
and then returns the decoded result.getPassword
(SessionContext session, NamedResource resourceKey, int retryIndex) handleDecodeAttemptResult
(SessionContext session, NamedResource resourceKey, int retryIndex, String password, Exception err) Invoked to inform the password provide about the decoding result.static FilePasswordProvider
-
Field Details
-
EMPTY
An "empty" provider that returnsnull
- i.e., unprotected key file
-
-
Method Details
-
getPassword
String getPassword(SessionContext session, NamedResource resourceKey, int retryIndex) throws IOException - Parameters:
session
- TheSessionContext
for invoking this load command - may benull
if 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
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
- TheSessionContext
for invoking this load command - may benull
if 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 -null
for success- Returns:
- How to proceed in case of error - ignored if invoked in order to report
success. Note:
null
is 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.Decoder
and thenhandleDecodeAttemptResult(SessionContext, NamedResource, int, String, Exception)
and then returns the decoded result. If the decoder fails and theFilePasswordProvider.ResourceDecodeResult
isFilePasswordProvider.ResourceDecodeResult.RETRY
, the whole process is re-tried.- Type Parameters:
T
- Result type of the decoder- Parameters:
session
-SessionContext
, may benull
resourceKey
-NamedResource
used for error reportingdecoder
-FilePasswordProvider.Decoder
to produce the result given a password- Returns:
- the decoder's result, or
null
if none - Throws:
IOException
- if an I/O problem occursGeneralSecurityException
- if the decoder throws it
-
of
-