K - The type of the keys.@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) @ThreadSafe public abstract class SafeKeyProvider<K extends SafeKey<K>> extends Object implements KeyProvider<K>
SafeKey).
A clone of this key is returned on each call to getWriteKey()
and getReadKey(boolean).| Modifier and Type | Class and Description |
|---|---|
private static class |
SafeKeyProvider.ThreadLocalLong |
KeyProvider.Factory<P extends KeyProvider<?>>| Modifier and Type | Field and Description |
|---|---|
private ThreadLocal<Long> |
invalidated |
static int |
MIN_KEY_RETRY_DELAY
The minimum delay between subsequent attempts to verify a key in
milliseconds.
|
| Modifier | Constructor and Description |
|---|---|
protected |
SafeKeyProvider() |
| Modifier and Type | Method and Description |
|---|---|
protected static <K extends SafeKey<K>> |
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 <K extends SafeKey<K>> |
reset(K key)
Resets the given key.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetKeypublic static final int MIN_KEY_RETRY_DELAY
getReadKey(boolean) by the same thread.private final ThreadLocal<Long> invalidated
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()
Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.