|
TrueZIP 6.8.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.schlichtherle.key.AbstractKeyProvider
de.schlichtherle.key.PromptingKeyProvider
public class PromptingKeyProvider
A "friendly" implementation of KeyProvider which prompts the user
for a key for its protected resource, enforcing a three seconds suspension
penalty if a wrong key was provided.
The user is prompted via an instance of the PromptingKeyProviderUI
user interface which is determined by the default instance of
PromptingKeyManager as returned by KeyManager.getInstance().
Like its base class, this class does not impose a certain run time type
of the key.
It is actually the user interface implementation which determines the run
time type of the key provided by AbstractKeyProvider.getCreateKey() and
AbstractKeyProvider.getOpenKey().
Because the user interface implementation is determined by the singleton
PromptingKeyManager, it is ultimately at the discretion of
the key manager which type of keys are actually provided by this class.
Unlike its base class, instances of this class cannot get shared
among multiple protected resources because each instance has a unique
resource identifier associated with it.
Each try to share a key provider of this class among multiple protected
resources with the singleton KeyManager will be prosecuted and
sentenced with an IllegalStateException or, at the discretion of
this class, some other RuntimeException.
This class is thread safe.
PromptingKeyProviderUI,
KeyProvider,
PromptingKeyManager| Nested Class Summary | |
|---|---|
private static class |
PromptingKeyProvider.Cancelled
|
private static class |
PromptingKeyProvider.KeyChanged
|
private static class |
PromptingKeyProvider.KeyChangeRequested
|
private static class |
PromptingKeyProvider.KeyInvalidated
|
private static class |
PromptingKeyProvider.KeyProvided
|
private static class |
PromptingKeyProvider.PromptingLock
|
private static class |
PromptingKeyProvider.Reset
|
private static class |
PromptingKeyProvider.State
|
| Field Summary | |
|---|---|
private PromptingKeyProvider.PromptingLock |
lock
Used to lock out prompting by multiple threads. |
private String |
resourceID
The resource identifier for the protected resource. |
private PromptingKeyProvider.State |
state
|
private PromptingKeyProviderUI |
ui
The user interface instance which is used to prompt the user for a key. |
| Fields inherited from interface de.schlichtherle.key.KeyProvider |
|---|
MIN_KEY_RETRY_DELAY |
| Constructor Summary | |
|---|---|
PromptingKeyProvider()
|
|
| Method Summary | |
|---|---|
protected KeyProvider |
addToKeyManager(String resourceID)
Like the super class implementation, but throws an IllegalStateException if this instance is already mapped for
another resource identifier. |
Object |
getCreateKeyImpl()
Returns a clone of the key which may be used to create a new protected resource or entirely replace the contents of an already existing protected resource. |
protected Object |
getOpenKeyImpl()
Returns a clone of the key which may be used to open an existing protected resource in order to access its contents. |
String |
getResourceID()
Returns the unique resource identifier of the protected resource for which this key provider is used. |
private PromptingKeyProvider.State |
getState()
|
private PromptingKeyProviderUI |
getUI()
|
protected String |
getUIClassID()
Returns the identifier which is used by the PromptingKeyManager
to look up an instance of the PromptingKeyProviderUI user
interface class which is then used to prompt the user for a key. |
protected void |
invalidOpenKeyImpl()
Called to indicate that authentication of the key returned by AbstractKeyProvider.getOpenKey() has failed and to request an entirely different
key. |
protected void |
onReset()
This hook is run after reset() has been called. |
private Object |
promptCreateKey()
Prompts for a key to create or entirely overwrite a protected resource. |
private Object |
promptOpenKey(boolean invalid)
Prompts for a key to open a protected resource. |
protected KeyProvider |
removeFromKeyManager(String resourceID)
Remove this instance as the key provider for the given resource identifier from the map in the KeyManager. |
void |
reset()
Resets this key provider and finally calls onReset(). |
(package private) void |
resetCancelledPrompt()
Resets this key provider if and only if prompting for a key has been cancelled. |
private void |
resetKey(Object oldKey)
|
(package private) void |
setResourceID(String resourceID)
|
private void |
setState(PromptingKeyProvider.State state)
|
(package private) void |
setUI(PromptingKeyProviderUI ui)
|
| Methods inherited from class de.schlichtherle.key.AbstractKeyProvider |
|---|
clone, cloneKey, getCreateKey, getKey, getOpenKey, invalidOpenKey, resetKey, setKey |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final PromptingKeyProvider.PromptingLock lock
private String resourceID
private PromptingKeyProviderUI ui
private PromptingKeyProvider.State state
| Constructor Detail |
|---|
public PromptingKeyProvider()
| Method Detail |
|---|
public String getResourceID()
final void setResourceID(String resourceID)
protected String getUIClassID()
PromptingKeyManager
to look up an instance of the PromptingKeyProviderUI user
interface class which is then used to prompt the user for a key.
The implementation in this class returns the fully qualified name
of this class.
Subclasses which want to use a custom user interface should overwrite
this method to return the fully qualified name of their respective
class as the identifier and provide a custom
PromptingKeyManager which has registered a
PromptingKeyProviderUI class for this identifier.
private final PromptingKeyProviderUI getUI()
final void setUI(PromptingKeyProviderUI ui)
private final PromptingKeyProvider.State getState()
private final void setState(PromptingKeyProvider.State state)
public final Object getCreateKeyImpl()
throws UnknownKeyException
If required or explicitly requested by the user, the user is prompted for this key.
getCreateKeyImpl in class AbstractKeyProviderkey to use or null.
UnknownKeyException - If the user has cancelled prompting or
prompting has been disabled by the PromptingKeyManager.
RuntimeException - If cloning the key results in a runtime
exception.KeyProvider.getCreateKey()
private Object promptCreateKey()
throws UnknownKeyException
UnknownKeyException
protected final Object getOpenKeyImpl()
throws UnknownKeyException
If required, the user is prompted for this key.
This method enforces a three seconds suspension penalty if
AbstractKeyProvider.invalidOpenKey() was called by the same thread before
in order to qualify as a "friendly" implementation.
getOpenKeyImpl in class AbstractKeyProviderkey to use or null.
UnknownKeyException - If the user has cancelled prompting or
prompting has been disabled by the PromptingKeyManager.
RuntimeException - If cloning the key results in a runtime
exception.KeyProvider.getOpenKey()
private Object promptOpenKey(boolean invalid)
throws UnknownKeyException
UnknownKeyExceptionprivate void resetKey(Object oldKey)
protected final void invalidOpenKeyImpl()
AbstractKeyProvider.getOpenKey() has failed and to request an entirely different
key.
The user is prompted for a new key on the next call to
AbstractKeyProvider.getOpenKey().
Note that the user may actually not be prompted at the next call to
AbstractKeyProvider.getOpenKey() again if prompting has been disabled by the
PromptingKeyManager or this provider is in a state where
calling this method does not make any sense.
invalidOpenKeyImpl in class AbstractKeyProviderKeyProvider.invalidOpenKey()final void resetCancelledPrompt()
public final void reset()
onReset().
reset in class AbstractKeyProviderprotected void onReset()
reset() has been called.
This method is called from the constructor in the class
AbstractKeyProvider.
The implementation in this class does nothing.
May be overwritten by subclasses.
protected KeyProvider addToKeyManager(String resourceID)
throws NullPointerException,
IllegalStateException
IllegalStateException if this instance is already mapped for
another resource identifier.
addToKeyManager in class AbstractKeyProviderresourceID - The resource identifier to map this instance for.
null if no key provider was mapped.
IllegalStateException - If this instance is already mapped for
another resource identifier or mapping is prohibited
by a constraint in a subclass. In the latter case, please refer
to the subclass documentation for more information.
NullPointerException - If resourceID is
null.
protected KeyProvider removeFromKeyManager(String resourceID)
throws NullPointerException,
IllegalStateException
AbstractKeyProviderKeyManager.
The key manager will use this method whenever it adds a key provider
which is actually an instance of this class.
This allows subclasses to add additional behaviour or constraints
whenever an instance is unmapped in the KeyManager.
removeFromKeyManager in class AbstractKeyProviderresourceID - The resource identifier to unmap this instance from.
NullPointerException - If resourceID is
null.
IllegalStateException - If unmapping this instance is prohibited
by a constraint in a subclass.
Please refer to the respective subclass documentation for
more information about its constraint(s).
|
TrueZIP 6.8.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||