TrueZIP 6.8.2

de.schlichtherle.key.passwd.console
Class PromptingKeyProviderUI

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

public class PromptingKeyProviderUI
extends Object
implements PromptingKeyProviderUI

A out I/O based user interface to prompt for passwords. This class is thread safe.

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

Nested Class Summary
private static class PromptingKeyProviderUI.PromptingLock
           
 
Field Summary
private static String CLASS_NAME
           
protected static Console con
          The console to use for I/O.
private static String lastResourceID
          The last resource ID used when prompting.
private static PromptingKeyProviderUI.PromptingLock lock
          Used to lock out prompting by multiple threads.
private static int MIN_PASSWD_LEN
          The minimum acceptable length of a password.
protected static ResourceBundle resources
           
 
Constructor Summary
PromptingKeyProviderUI()
           
 
Method Summary
protected  Console printf(String format)
           
protected  Console printf(String format, Object arg)
           
 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 promptExtraData(PromptingKeyProvider provider)
           
 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.
private  boolean promptOpenKey(PromptingKeyProvider provider, boolean invalid)
           
 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.
protected  String readLine(String format)
           
protected  String readLine(String format, Object arg)
           
protected  char[] readPassword(String format)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_NAME

private static final String CLASS_NAME
See Also:
Constant Field Values

resources

protected static final ResourceBundle resources

con

protected static final Console con
The console to use for I/O. If null, the prompt methods are never called, so it's safe to assume that it's not null in these methods.


lock

private static final PromptingKeyProviderUI.PromptingLock lock
Used to lock out prompting by multiple threads.


MIN_PASSWD_LEN

private static final int MIN_PASSWD_LEN
The minimum acceptable length of a password.

See Also:
Constant Field Values

lastResourceID

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

Constructor Detail

PromptingKeyProviderUI

public PromptingKeyProviderUI()
Method Detail

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.

promptExtraData

protected void promptExtraData(PromptingKeyProvider provider)

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.

promptOpenKey

private boolean promptOpenKey(PromptingKeyProvider provider,
                              boolean invalid)

printf

protected final Console printf(String format)

printf

protected final Console printf(String format,
                               Object arg)

readLine

protected final String readLine(String format)

readLine

protected final String readLine(String format,
                                Object arg)

readPassword

protected final char[] readPassword(String format)

TrueZIP 6.8.2

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