K - The type of the keys.@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public interface KeyProvider<K>
Object.
The protected resource is not even explicitly modelled in this interface.
So in order to use it, an instance must be associated with a protected
resource by a third party - this is the job of the KeyManager class.
Once an instance has been associated to a protected resource, the client application is assumed to use the key for two basic operations:
getWriteKey().
getReadKey(boolean).
equal, but is not necessarily the same.
From a client application's perspective, the two basic operations may be executed in no particular order. Following are some typical use cases:
getWriteKey() needs to get called.
getWriteKey() needs to get called.
getReadKey(boolean) needs to get called.
getReadKey(boolean) needs to get called.
getReadKey(boolean) and then getWriteKey()
need to get called.
getWriteKey() returns a key which compares
equal to the key returned by getReadKey(boolean) or
returns a completely different new key.
Ideally, a brave provider implementation would allow the user to control
this.
Note that provider implementations must be thread-safe. This allows clients to use the same provider by multiple threads concurrently.
KeyManager| Modifier and Type | Interface and Description |
|---|---|
static interface |
KeyProvider.Factory<P extends KeyProvider<?>>
A factory for key providers.
|
| Modifier and Type | Method and Description |
|---|---|
K |
getReadKey(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.
|
void |
setKey(K key)
Sets the key programmatically.
|
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.
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.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.
invalid - true iff a previous call to this method resulted
in an invalid key.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.void setKey(@CheckForNull
K key)
key - the key.
If this is null, this key provider is set to a state
as if prompting for the key had been disabled or cancelled.Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.