|
TrueZIP Driver ZIP.RAES (TZP) 7.1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.schlichtherle.truezip.key.SafeKeyProvider<K>
K - The type of the keys.@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) @ThreadSafe public abstract class SafeKeyProvider<K extends SafeKey<K>>
Provides the base functionality required to implement a "safe" key provider.
Each instance of this class maintains a single key which implements the
interface SafeKey).
A clone of this key is returned on each call to getWriteKey()
and getReadKey(boolean).
| Nested Class Summary | |
|---|---|
private static class |
SafeKeyProvider.ThreadLocalLong
|
| Nested classes/interfaces inherited from interface de.schlichtherle.truezip.key.KeyProvider |
|---|
KeyProvider.Factory<P extends KeyProvider<?>> |
| Field Summary | |
|---|---|
private ThreadLocal<Long> |
invalidated
|
static int |
MIN_KEY_RETRY_DELAY
The minimum delay between subsequent attempts to verify a key in milliseconds. |
| Constructor Summary | |
|---|---|
protected |
SafeKeyProvider()
|
| Method Summary | ||
|---|---|---|
protected static
|
clone(K key)
Returns a clone of the given key. |
|
private void |
enforceSuspensionPenalty()
|
|
K |
getReadKey(boolean invalid)
Returns the key for reading the contents of an existing protected resource. |
|
protected abstract K |
getReadKeyImpl(boolean invalid)
Returns the key for reading the contents of an existing protected resource. |
|
K |
getWriteKey()
Returns the key for (over)writing the contents of a new or existing protected resource. |
|
protected abstract K |
getWriteKeyImpl()
Returns the key for (over)writing the contents of a new or existing protected resource. |
|
protected static
|
reset(K key)
Resets the given key. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface de.schlichtherle.truezip.key.KeyProvider |
|---|
setKey |
| Field Detail |
|---|
public static final int MIN_KEY_RETRY_DELAY
getReadKey(boolean) by the same thread.
private final ThreadLocal<Long> invalidated
| Constructor Detail |
|---|
protected SafeKeyProvider()
| Method Detail |
|---|
public final K getWriteKey()
throws UnknownKeyException
Subsequent calls to this method return an object which at least compares
equal to any previously returned object, but is
not necessarily the same.
The implementation in SafeKeyProvider forwards the call to
getWriteKeyImpl().
getWriteKey in interface KeyProvider<K extends SafeKey<K>>UnknownKeyException - If getWriteKeyImpl throws
this exception or the returned key is null.
@CheckForNull
protected abstract K getWriteKeyImpl()
throws UnknownKeyException
Subsequent calls to this method may return the same object.
UnknownKeyException - if the required key is unknown for some
reason, e.g. if prompting for the key has been disabled or
cancelled by the user.getWriteKey()
public final K getReadKey(boolean invalid)
throws UnknownKeyException
Unless invalid is true, subsequent calls to this method
return an object which at least compares equal to
any previously returned object, but is not necessarily the same.
Important: From an application's perspective, a
KeyProvider is not trustworthy!
Hence, the key returned by this method must not only get authenticated,
but the application should also throttle the pace for the return from a
subsequent call to this method if the key is invalid in order to protect
the client application from an exhaustive search for the correct key.
As a rule of thumb, at least three seconds should pass between two
consecutive calls to this method by the same thread.
"Safe" implementations of this interface should enforce this
behaviour in order to protect client applications which do not obeye
these considerations against abuses of the key provider implementation.
The implementation in SafeKeyProvider forwards the call to
getReadKeyImpl(boolean) and enforces a three seconds suspension penalty
if invalid is true before returning.
Because this method is final, this qualifies the implementation in
this class as a "friendly" KeyProvider implementation,
even when subclassed.
getReadKey in interface KeyProvider<K extends SafeKey<K>>invalid - true iff a previous call to this method resulted
in an invalid key.
UnknownKeyException - If getReadKeyImpl throws
this exception or the returned key is null.
@CheckForNull
protected abstract K getReadKeyImpl(boolean invalid)
throws UnknownKeyException
Subsequent calls to this method may return the same object.
UnknownKeyException - If the required key is unknown.
At the subclasses discretion, this may mean that prompting for
the key has been disabled or cancelled by the user.KeyProvider.getWriteKey()
@Nullable
protected static <K extends SafeKey<K>> K clone(@CheckForNull
K key)
protected static <K extends SafeKey<K>> void reset(@CheckForNull
K key)
key - the key to reset.private void enforceSuspensionPenalty()
|
TrueZIP Driver ZIP.RAES (TZP) 7.1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||