TrueZIP 6.8.2

de.schlichtherle.key.passwd.swing
Class PromptingKeyProviderUI

java.lang.Object
  extended by de.schlichtherle.key.passwd.swing.PromptingKeyProviderUI
All Implemented Interfaces:
PromptingKeyProviderUI
Direct Known Subclasses:
PromptingAesKeyProviderUI

public class PromptingKeyProviderUI
extends Object
implements PromptingKeyProviderUI

A Swing based user interface to prompt for passwords or key files. This class is thread safe.

Since:
TrueZIP 6.0
Version:
$Id: PromptingKeyProviderUI.java 5e709f50671d 2010/11/05 11:52:07 christian $
Author:
Christian Schlichtherle

Nested Class Summary
private static class PromptingKeyProviderUI.BooleanRunnable
           
 
Field Summary
private static String CLASS_NAME
           
private  CreateKeyPanel createKeyPanel
          Deprecated. This field is not used anymore and will be removed for the next major release number.
private  Feedback invalidCreateKeyFeedback
           
private  Feedback invalidOpenKeyFeedback
           
static int KEY_FILE_LEN
          This is the number of bytes to load from the beginning of a key file.
(package private) static String lastResourceID
          The last resource ID used when prompting.
private static Logger logger
           
private  OpenKeyPanel openKeyPanel
          Deprecated. This field is not used anymore and will be removed for the next major release number.
private static Map openKeyPanels
           
private static String PACKAGE_NAME
           
private static ResourceBundle resources
           
private static long START_PROMPTING_TIMEOUT
          The timeout for the EDT to start prompting for a key in milliseconds.
private  Feedback unknownCreateKeyFeedback
           
private  Feedback unknownOpenKeyFeedback
           
 
Constructor Summary
PromptingKeyProviderUI()
           
 
Method Summary
protected  CreateKeyPanel createCreateKeyPanel()
          A factory method to create the Create Protected Resource Key Panel.
private static Feedback createFeedback(String type)
           
protected  OpenKeyPanel createOpenKeyPanel()
          A factory method to create the Open Protected Resource Key Panel.
private static void eventuallyDispose(Window window)
          The following is a double work around for Sun's J2SE 1.4.2 which has been tested with 1.4.2-b28 and 1.4.2_12-b03 on the Windows platform.
protected  CreateKeyPanel getCreateKeyPanel()
          Deprecated. This method is not used anymore and will be removed for the next major release number. It's use may dead lock the GUI. Use createCreateKeyPanel() instead.
protected  Feedback getInvalidCreateKeyFeedback()
           
protected  Feedback getInvalidOpenKeyFeedback()
           
protected  OpenKeyPanel getOpenKeyPanel()
          Deprecated. This method is not used anymore and will be removed for the next major release number. It's use may dead lock the GUI. Use createOpenKeyPanel() instead.
protected  Feedback getUnknownCreateKeyFeedback()
           
protected  Feedback getUnknownOpenKeyFeedback()
           
private static void multiplexOnEDT(Runnable task)
          Invokes the given task on the AWT Event Dispatching Thread (EDT) and waits until it's finished.
 void promptCreateKey(PromptingKeyProvider provider)
          Prompts the user for the key which may be used to create a new protected resource or entirely replace the contents of an already existing protected resource.
protected  void promptCreateKey(PromptingKeyProvider provider, JComponent extraDataUI)
          This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.
 boolean promptInvalidOpenKey(PromptingKeyProvider provider)
          Prompts the user for the key which may be used to open an existing protected resource in order to access its contents.
protected  boolean promptOpenKey(PromptingKeyProvider provider, boolean invalid, JComponent extraDataUI)
          This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.
 boolean promptUnknownOpenKey(PromptingKeyProvider provider)
          Prompts the user for the key which may be used to open an existing protected resource in order to access its contents.
(package private) static byte[] readKeyFile(String pathname)
          Reads the encryption key as a byte sequence from the given pathname into a buffer of exactly KEY_FILE_LEN bytes and returns it.
protected  void setInvalidCreateKeyFeedback(Feedback ickf)
           
protected  void setInvalidOpenKeyFeedback(Feedback iokf)
           
protected  void setUnknownOpenKeyFeedback(Feedback uokf)
           
protected  void setUnkownCreateKeyFeedback(Feedback uckf)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKAGE_NAME

private static final String PACKAGE_NAME
See Also:
Constant Field Values

CLASS_NAME

private static final String CLASS_NAME
See Also:
Constant Field Values

resources

private static final ResourceBundle resources

logger

private static final Logger logger

START_PROMPTING_TIMEOUT

private static final long START_PROMPTING_TIMEOUT
The timeout for the EDT to start prompting for a key in milliseconds.

See Also:
Constant Field Values

KEY_FILE_LEN

public static final int KEY_FILE_LEN
This is the number of bytes to load from the beginning of a key file. A valid key file for encryption must contain at least this number of bytes!

See Also:
Constant Field Values

openKeyPanels

private static final Map openKeyPanels

lastResourceID

static String lastResourceID
The last resource ID used when prompting. Initialized to the empty string.


createKeyPanel

private CreateKeyPanel createKeyPanel
Deprecated. This field is not used anymore and will be removed for the next major release number.

openKeyPanel

private OpenKeyPanel openKeyPanel
Deprecated. This field is not used anymore and will be removed for the next major release number.

unknownCreateKeyFeedback

private Feedback unknownCreateKeyFeedback

invalidCreateKeyFeedback

private Feedback invalidCreateKeyFeedback

unknownOpenKeyFeedback

private Feedback unknownOpenKeyFeedback

invalidOpenKeyFeedback

private Feedback invalidOpenKeyFeedback
Constructor Detail

PromptingKeyProviderUI

public PromptingKeyProviderUI()
Method Detail

readKeyFile

static byte[] readKeyFile(String pathname)
                   throws IOException
Reads the encryption key as a byte sequence from the given pathname into a buffer of exactly KEY_FILE_LEN bytes and returns it.

Throws:
EOFException - If the file is not at least KEY_FILE_LEN bytes long.
IOException - on any other I/O related issue.

getCreateKeyPanel

protected CreateKeyPanel getCreateKeyPanel()
Deprecated. This method is not used anymore and will be removed for the next major release number. It's use may dead lock the GUI. Use createCreateKeyPanel() instead.


createCreateKeyPanel

protected CreateKeyPanel createCreateKeyPanel()
A factory method to create the Create Protected Resource Key Panel.


getOpenKeyPanel

protected OpenKeyPanel getOpenKeyPanel()
Deprecated. This method is not used anymore and will be removed for the next major release number. It's use may dead lock the GUI. Use createOpenKeyPanel() instead.


createOpenKeyPanel

protected OpenKeyPanel createOpenKeyPanel()
A factory method to create the Open Protected Resource Key Panel.


getUnknownCreateKeyFeedback

protected Feedback getUnknownCreateKeyFeedback()

setUnkownCreateKeyFeedback

protected void setUnkownCreateKeyFeedback(Feedback uckf)

getInvalidCreateKeyFeedback

protected Feedback getInvalidCreateKeyFeedback()

setInvalidCreateKeyFeedback

protected void setInvalidCreateKeyFeedback(Feedback ickf)

getUnknownOpenKeyFeedback

protected Feedback getUnknownOpenKeyFeedback()

setUnknownOpenKeyFeedback

protected void setUnknownOpenKeyFeedback(Feedback uokf)

getInvalidOpenKeyFeedback

protected Feedback getInvalidOpenKeyFeedback()

setInvalidOpenKeyFeedback

protected void setInvalidOpenKeyFeedback(Feedback iokf)

createFeedback

private static Feedback createFeedback(String type)

promptCreateKey

public final void promptCreateKey(PromptingKeyProvider provider)
Description copied from interface: PromptingKeyProviderUI
Prompts the user for the key which may be used to create a new protected resource or entirely replace the contents of an already existing protected resource.

Upon return, the implementation is expected to update the common key in provider. Upon return, if provider.getKey() returns null, prompting for the key is assumed to have been cancelled by the user. In this case, the current and each subsequent call to KeyProvider.getOpenKey() or KeyProvider.getCreateKey() by the client results in an UnknownKeyException and the user is not prompted anymore until the provider is reset by the KeyManager. Otherwise, the key is used as the common key, a clone of which is provided to the client upon request.

Hint: If the user cancels the dialog, it is recommended to leave the provider's key property simply unmodified. This causes the old key to be reused and allows the client to continue its operation as if the user would not have requested to change the key.

Since TrueZIP 6.4, an implementation may also throw a RuntimeException with any kind of UnknownKeyException as its cause. This will trigger the calling method in the PromptingKeyProvider class to unwrap and pass on the cause without changing its state. This may be useful if prompting was interrupted by a call to Thread.interrupt() while waiting on the Event Dispatch Thread. In this case, another try to prompt the user should have the chance to succeed instead of being cancelled without actually prompting the user again. To trigger this behaviour, the implementation should simply throw any kind of RuntimeException with a KeyPromptingInterruptedException as its cause.

Specified by:
promptCreateKey in interface PromptingKeyProviderUI
Parameters:
provider - The default key provider to store the result in.

promptUnknownOpenKey

public final boolean promptUnknownOpenKey(PromptingKeyProvider provider)
Description copied from interface: PromptingKeyProviderUI
Prompts the user for the key which may be used to open an existing protected resource in order to access its contents.

Upon return, the implementation is expected to update the common key in provider. Upon return, if provider.getKey() returns null, prompting for the key is assumed to have been cancelled by the user. In this case, the current and each subsequent call to KeyProvider.getOpenKey() or KeyProvider.getCreateKey() by the client results in an UnknownKeyException and the user is not prompted anymore until the provider is reset by the KeyManager. Otherwise, the key is used as the common key, a clone of which is provided to the client upon request.

Since TrueZIP 6.4, an implementation may also throw a RuntimeException with any kind of UnknownKeyException as its cause. This will trigger the calling method in the PromptingKeyProvider class to unwrap and pass on the cause without changing its state. This may be useful if prompting was interrupted by a call to Thread.interrupt() while waiting on the Event Dispatch Thread. In this case, another try to prompt the user should have the chance to succeed instead of being cancelled without actually prompting the user again. To trigger this behaviour, the implementation should simply throw any kind of RuntimeException with a KeyPromptingInterruptedException as its cause.

Specified by:
promptUnknownOpenKey in interface PromptingKeyProviderUI
Parameters:
provider - The key provider to store the result in.
Returns:
true if the user has requested to change the provided key.

promptInvalidOpenKey

public final boolean promptInvalidOpenKey(PromptingKeyProvider provider)
Description copied from interface: PromptingKeyProviderUI
Prompts the user for the key which may be used to open an existing protected resource in order to access its contents. This is called if the key returned by a previous call to PromptingKeyProviderUI.promptUnknownOpenKey(de.schlichtherle.key.PromptingKeyProvider) is invalid.

Upon return, the implementation is expected to update the common key in provider. Upon return, if provider.getKey() returns null, prompting for the key is assumed to have been cancelled by the user. In this case, the current and each subsequent call to KeyProvider.getOpenKey() or KeyProvider.getCreateKey() by the client results in an UnknownKeyException and the user is not prompted anymore until the provider is reset by the KeyManager. Otherwise, the key is used as the common key, a clone of which is provided to the client upon request.

Since TrueZIP 6.4, an implementation may also throw a RuntimeException with any kind of UnknownKeyException as its cause. This will trigger the calling method in the PromptingKeyProvider class to unwrap and pass on the cause without changing its state. This may be useful if prompting was interrupted by a call to Thread.interrupt() while waiting on the Event Dispatch Thread. In this case, another try to prompt the user should have the chance to succeed instead of being cancelled without actually prompting the user again. To trigger this behaviour, the implementation should simply throw any kind of RuntimeException with a KeyPromptingInterruptedException as its cause.

Specified by:
promptInvalidOpenKey in interface PromptingKeyProviderUI
Parameters:
provider - The key provider to store the result in.
Returns:
true if the user has requested to change the provided key.

promptCreateKey

protected void promptCreateKey(PromptingKeyProvider provider,
                               JComponent extraDataUI)
This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.


promptOpenKey

protected boolean promptOpenKey(PromptingKeyProvider provider,
                                boolean invalid,
                                JComponent extraDataUI)
This method is only called by the AWT Event Dispatch Thread, so it doesn't need to be thread safe.


eventuallyDispose

private static void eventuallyDispose(Window window)
The following is a double work around for Sun's J2SE 1.4.2 which has been tested with 1.4.2-b28 and 1.4.2_12-b03 on the Windows platform. The issue for which this work around is required is known to be present in the Java code of the AWT package, so this should pertain to all platforms. This issue has been fixed with Sun's JSE 1.5.0-b64 or higher.

The issue is that an application will not terminate until all Window's have been dispose()d or System.exit() has been called - it is not sufficient just to hide() all Window's.

The JOptionPane properly dispose()s its Dialog which displays our password panels. However, by default JOptionPane uses an internal Frame as its parent window if the application does not specify a parent window explicitly. JOptionPane never dispose()s the parent window, so the client application may eventually not terminate.

The workaround is to dispose the parent window if it's not showing.


multiplexOnEDT

private static void multiplexOnEDT(Runnable task)
Invokes the given task on the AWT Event Dispatching Thread (EDT) and waits until it's finished.

In multithreaded environments, although technically possible, do not allow multiple threads to prompt for a key concurrently, because this would only confuse users. By explicitly locking the class object rather than the instance, we enforce this even if multiple implementations and instances are used.

If the current thread is interrupted, an UndeclaredThrowableException is thrown with a KeyPromptingInterruptedException as its cause.

If a Throwable is thrown by the EDT, then it's wrapped in an UndeclaredThrowableException and re-thrown by this thread.


TrueZIP 6.8.2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.