|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.schlichtherle.key.KeyManager
de.schlichtherle.key.PromptingKeyManager
public abstract class PromptingKeyManager
An abstract KeyManager
which prompts the user for a key if required.
This class maintains a map of user interface classes for the
PromptingKeyProvider
class and each of its subclasses which
require an individual user interface.
The particular user interface classes are determined by a subclass of this
key manager. This enables the subclass to determine which user interface
technology should actually be used to prompt the user for a key.
For example, the implementation in the class
PromptingKeyManager
uses Swing
to prompt the user for either a password or a key file.
Subclasses must use the method mapPromptingKeyProviderUIType(java.lang.String, java.lang.Class)
to
register a user interface class for a particular user interface class
identifier (the value returned by PromptingKeyProvider.getUIClassID()
).
This is best done in the constructor of the subclass.
Note that class loading and instantiation may happen in a JVM shutdown hook, so class initializers and constructors must behave accordingly. In particular, it's not permitted to construct or use a Swing GUI there.
This class is thread safe.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class de.schlichtherle.key.KeyManager |
---|
KeyManager.KeyProviderCommand |
Constructor Summary | |
---|---|
PromptingKeyManager()
Constructs a new PromptingKeyManager . |
Method Summary | |
---|---|
protected void |
ensurePromptingImpl()
Called by some methods in the PromptingKeyProvider class in
order to ensure that prompting mode is enabled. |
KeyProvider |
getKeyProvider(String resourceID,
Class keyProviderType)
Behaves like the super class implementation, but adds additional behaviour in case the resulting key provider is an instance of PromptingKeyProvider . |
static boolean |
isPrompting()
Returns true if and only if prompting mode is enabled. |
protected boolean |
isPromptingImpl()
Called by isPrompting() on the default key manager instance in
order to implement its behaviour and allow subclasses to override it. |
protected void |
mapPromptingKeyProviderUIType(String uiClassID,
Class uiClass)
Subclasses must use this method to register a user interface class for a particular user interface class identifier as returned by PromptingKeyProvider.getUIClassID() . |
protected void |
register(String uiClassID,
Class uiClass)
Deprecated. Use mapPromptingKeyProviderUIType(uiClassID, uiClass) instead. |
static void |
resetCancelledPrompts()
Resets all cancelled key prompts, forcing a new prompt on the next call to AbstractKeyProvider.getOpenKey() or
AbstractKeyProvider.getCreateKey() . |
static void |
setPrompting(boolean prompting)
Enables or disables prompting mode. |
protected void |
setPromptingImpl(boolean prompting)
Called by isPrompting() on the default key manager instance in
order to implement its behaviour and allow subclasses to override it. |
Methods inherited from class de.schlichtherle.key.KeyManager |
---|
forEachKeyProvider, getInstance, getKeyProvider, mapKeyProviderType, moveKeyProvider, resetAndClearKeyProviders, resetAndRemoveKeyProvider, resetAndRemoveKeyProviders, resetKeyProvider, resetKeyProviders, setInstance, setKeyProvider |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PromptingKeyManager()
PromptingKeyManager
.
This instance maps the following key provider types using
KeyManager.mapKeyProviderType(java.lang.Class, java.lang.Class)
:
forKeyProviderType | useKeyProviderType |
---|---|
KeyProvider.class | PromptingKeyProvider.class |
AesKeyProvider.class | PromptingAesKeyProvider.class |
Method Detail |
---|
public static boolean isPrompting()
true
if and only if prompting mode is enabled.
This is a class property.
Note that subclasses might add additional behaviour to both
isPrompting()
and setPrompting(boolean)
through the default
key manager instance (see KeyManager.getInstance()
).
Regardless, an application may safely assume that
isPrompting()
reflects the actual behaviour of the API
in this package although it may not reflect the parameter value of
the last call to setPrompting(boolean)
.
setPrompting(boolean)
protected boolean isPromptingImpl()
isPrompting()
on the default key manager instance in
order to implement its behaviour and allow subclasses to override it.
Subclasses should call the implementation in this class when
overriding this method.
setPromptingImpl(boolean)
,
KeyManager.getInstance()
public static void setPrompting(boolean prompting)
PromptingKeyProvider
is first requested to provide a key
for the respective resource.
If prompting mode is disabled, all attempts to prompt the user will
result in an UnknownKeyException
until prompting mode is
enabled again.
This is a class property.
Note that subclasses might add additional behaviour to both
isPrompting()
and setPrompting(boolean)
through the default
key manager instance (see KeyManager.getInstance()
).
Regardless, an application may safely assume that
isPrompting()
reflects the actual behaviour of the API
in this package although it may not reflect the parameter value of
the last call to setPrompting(boolean)
.
prompting
- The value of the property prompting
.isPrompting()
protected void setPromptingImpl(boolean prompting)
isPrompting()
on the default key manager instance in
order to implement its behaviour and allow subclasses to override it.
Subclasses should call the implementation in this class when
overriding this method.
isPromptingImpl()
,
KeyManager.getInstance()
protected void ensurePromptingImpl() throws KeyPromptingDisabledException
PromptingKeyProvider
class in
order to ensure that prompting mode is enabled.
This method may be overridden by subclasses in order to throw a more
detailed exception.
The implementation in this class is equivalent to:
if (!isPromptingImpl()) throw new KeyPromptingDisabledException();
KeyPromptingDisabledException
public static void resetCancelledPrompts()
AbstractKeyProvider.getOpenKey()
or
AbstractKeyProvider.getCreateKey()
.
Of course, this call only affects instances of
PromptingKeyProvider
.
protected final void register(String uiClassID, Class uiClass)
mapPromptingKeyProviderUIType(uiClassID, uiClass)
instead.
protected final void mapPromptingKeyProviderUIType(String uiClassID, Class uiClass)
PromptingKeyProvider.getUIClassID()
.
This is best done in the constructor of the subclass.
uiClassID
- The identifier of the user interface class.uiClass
- The class of the user interface. This must have
NullPointerException
- If any of the parameters is
null
.
IllegalArgumentException
- If the runtime type of uiClass is not
PromptingKeyProviderUI
or a subclass or does not provide
a public constructor with no parameters.getKeyProvider(String, Class)
public KeyProvider getKeyProvider(String resourceID, Class keyProviderType) throws NullPointerException, ClassCastException, IllegalArgumentException
PromptingKeyProvider
.
In this case, the appropriate user interface instance is determined
and installed in the key provider before it is returned.
getKeyProvider
in class KeyManager
resourceID
- The identifier of the protected resource.keyProviderType
- Unless another key provider is already mapped
for the protected resource, this denotes the root of the class
hierarchy to which the run time type of the returned instance
may belong.
In case the key manager does not know a more suitable class in
this hierarchy, this parameter must denote an implementation of
the KeyProvider
interface with a public no-argument
constructor.
KeyProvider
mapped for the protected resource.
If no key provider has been previously mapped for the protected
resource, the run time type of this instance is guaranteed to be
assignment compatible to the given keyProviderType
.
NullPointerException
- If resourceID
or
keyProviderType
is null
.
ClassCastException
- If no other key provider is mapped for the
protected resource and the given class is not an implementation
of the KeyProvider
interface.
IllegalArgumentException
- If any other precondition on the
parameter keyProviderType
does not hold.KeyManager.getKeyProvider(String, Class)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |