|
TrueZIP Driver TZP (ZIP.RAES) 7.0-rc1 | ||||||||
| 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 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 can be of any
run time type (it is just required to be Cloneable).
A clone of this key is returned on each call to getCreateKey()
and getOpenKey(boolean).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface de.schlichtherle.truezip.key.KeyProvider |
|---|
KeyProvider.Factory<K,P extends KeyProvider<K>> |
| 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 K |
clone(K key)
Returns a clone of the given key. |
private void |
enforceSuspensionPenalty()
|
K |
getCreateKey()
Returns the key which should be used to create a new protected resource or entirely replace the contents of an already existing protected resource. |
protected K |
getCreateKeyImpl()
Returns the key which should be used to create a new protected resource or entirely replace the contents of an already existing protected resource. |
K |
getOpenKey(boolean invalid)
Returns the key which should be used to open an existing protected resource in order to access its contents. |
protected K |
getOpenKeyImpl(boolean invalid)
Returns the key which should be used to open an existing protected resource in order to access its contents. |
protected void |
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 |
| Field Detail |
|---|
public static final int MIN_KEY_RETRY_DELAY
getOpenKey(boolean) by the same thread.
private final ThreadLocal<Long> invalidated
| Constructor Detail |
|---|
protected SafeKeyProvider()
| Method Detail |
|---|
public final K getCreateKey()
throws UnknownKeyException
Each call to this method returns an object which compares
equal to the previously returned object,
but is not necessarily the same.
The implementation in SafeKeyProvider forwards the call to
getCreateKeyImpl().
getCreateKey in interface KeyProvider<K extends SafeKey<K>>UnknownKeyException - If getCreateKeyImpl throws
this exception or the returned key is null.
@CheckForNull
protected K getCreateKeyImpl()
throws UnknownKeyException
Consecutive calls to this method may return the same object.
key to clone or null.
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.getCreateKey()
public final K getOpenKey(boolean invalid)
throws UnknownKeyException
Unless invalid is true, each call to this method returns
an object which compares equal to the previously
returned object,
but is not necessarily the same.
Important: From a client application's perspective, a
KeyProvider is not trustworthy!
Hence, the key returned by this method must not only get authenticated,
but the client 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
getOpenKeyImpl(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.
getOpenKey in interface KeyProvider<K extends SafeKey<K>>invalid - true iff a previous call to this method resulted
in an invalid key.
UnknownKeyException - If getOpenKeyImpl throws
this exception or the returned key is null.
@CheckForNull
protected K getOpenKeyImpl(boolean invalid)
throws UnknownKeyException
key to use or null.
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.getCreateKey()
@Nullable
protected K clone(@CheckForNull
K key)
protected void reset(@CheckForNull
K key)
key - the key to reset.private void enforceSuspensionPenalty()
|
TrueZIP Driver TZP (ZIP.RAES) 7.0-rc1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||