TrueZIP Driver TZP (ZIP.RAES) 7.0-rc1

de.schlichtherle.truezip.key
Class PromptingKeyProvider<K extends SafeKey<K>>

java.lang.Object
  extended by de.schlichtherle.truezip.key.SafeKeyProvider<K>
      extended by de.schlichtherle.truezip.key.PromptingKeyProvider<K>
Type Parameters:
K - The type of the keys.
All Implemented Interfaces:
KeyProvider<K>

@ThreadSafe
public final class PromptingKeyProvider<K extends SafeKey<K>>
extends SafeKeyProvider<K>

A "safe" key provider which prompts the user for a key for its protected resource. The user is prompted via an instance of the PromptingKeyProvider.UI user interface which is injected to this instance by a PromptingKeyManager. The UI may then display the resource URI by calling getResource() on this instance (which is also injected by a PromptingKeyManager) and finally set the key by calling setKey(K).

Author:
Christian Schlichtherle
See Also:
PromptingKeyManager

Nested Class Summary
(package private) static class PromptingKeyProvider.State
          Implements the behavior strategy of its enclosing class.
static interface PromptingKeyProvider.UI<K extends SafeKey<K>>
          Used for the actual prompting of the user for a key (a password for example) which is required to access a protected resource.
 
Nested classes/interfaces inherited from interface de.schlichtherle.truezip.key.KeyProvider
KeyProvider.Factory<K,P extends KeyProvider<K>>
 
Field Summary
private  boolean changeKeySelected
           
private  K key
           
private  URI resource
          The resource identifier for the protected resource.
private  PromptingKeyProvider.State state
           
private  PromptingKeyProvider.UI<? extends K> ui
          The user interface instance which is used to prompt the user for a key.
 
Fields inherited from class de.schlichtherle.truezip.key.SafeKeyProvider
MIN_KEY_RETRY_DELAY
 
Constructor Summary
PromptingKeyProvider()
           
 
Method Summary
protected  K getCreateKeyImpl()
          Returns the key which should be used to create a new protected resource or entirely replace the contents of an already existing protected resource.
(package private)  K getKey()
          Returns the key property maintained by this key provider.
protected  K getOpenKeyImpl(boolean invalid)
          Returns the key which should be used to open an existing protected resource in order to access its contents.
 URI getResource()
          Returns the unique resource identifier (resource ID) of the protected resource for which this key provider is used.
(package private)  PromptingKeyProvider.State getState()
           
(package private)  PromptingKeyProvider.UI<? extends K> getUI()
           
(package private)  boolean isChangeKeySelected()
          Returns whether or not the user shall get prompted for a new key upon the next call to SafeKeyProvider.getCreateKey(), provided that the key has been set before.
private  void reset()
           
 void resetCancelledKey()
          Resets the state of this key provider and the current key if and only if prompting for a key has been cancelled.
 void resetUnconditionally()
          Resets the state of this key provider and the current key unconditionally.
 void setChangeKeySelected(boolean changeKeySelected)
          Requests to prompt the user for a new key upon the next call to SafeKeyProvider.getCreateKey(), provided that the key has been set before.
 void setKey(K key)
          Sets the key property maintained by this key provider.
private  void setKeyImpl(K newKey)
           
(package private)  void setResource(URI resource)
          Returns the unique resource identifier (resource ID) of the protected resource for which this key provider is used.
private  void setState(PromptingKeyProvider.State state)
           
(package private)  void setUI(PromptingKeyProvider.UI<? extends K> ui)
           
 
Methods inherited from class de.schlichtherle.truezip.key.SafeKeyProvider
clone, getCreateKey, getOpenKey, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

state

@NonNull
private volatile PromptingKeyProvider.State state

resource

private volatile URI resource
The resource identifier for the protected resource.


ui

private volatile PromptingKeyProvider.UI<? extends K extends SafeKey<K>> ui
The user interface instance which is used to prompt the user for a key.


key

private volatile K extends SafeKey<K> key

changeKeySelected

private volatile boolean changeKeySelected
Constructor Detail

PromptingKeyProvider

public PromptingKeyProvider()
Method Detail

getResource

public URI getResource()
Returns the unique resource identifier (resource ID) of the protected resource for which this key provider is used. May be null.


setResource

void setResource(URI resource)
Returns the unique resource identifier (resource ID) of the protected resource for which this key provider is used. May be null.


getUI

final PromptingKeyProvider.UI<? extends K> getUI()

setUI

final void setUI(PromptingKeyProvider.UI<? extends K> ui)

getState

@NonNull
PromptingKeyProvider.State getState()

setState

private void setState(@NonNull
                      PromptingKeyProvider.State state)

getCreateKeyImpl

protected final K getCreateKeyImpl()
                                               throws UnknownKeyException
Returns the key which should be used to create a new protected resource or entirely replace the contents of an already existing protected resource.

If required or explicitly requested by the user, the user is prompted for this key.

Overrides:
getCreateKeyImpl in class SafeKeyProvider<K extends SafeKey<K>>
Returns:
A template for the key to clone or null.
Throws:
UnknownKeyException - If the user has cancelled prompting or prompting has been disabled by the PromptingKeyManager.
See Also:
KeyProvider.getCreateKey()

getOpenKeyImpl

protected final K getOpenKeyImpl(boolean invalid)
                                             throws UnknownKeyException
Returns the key which should be used to open an existing protected resource in order to access its contents.

If required, the user is prompted for this key.

Overrides:
getOpenKeyImpl in class SafeKeyProvider<K extends SafeKey<K>>
Returns:
A template for the key to use or null.
Throws:
UnknownKeyException - If the user has cancelled prompting or prompting has been disabled by the PromptingKeyManager.
See Also:
KeyProvider.getOpenKey(boolean)

getKey

K getKey()
Returns the key property maintained by this key provider. Client applications should not call this method directly but rather call SafeKeyProvider.getOpenKey(boolean) or SafeKeyProvider.getCreateKey(): It's intended to be used by subclasses and user interface classes only.

Returns:
The nullable key property.

setKey

public void setKey(@CheckForNull
                   K key)
Sets the key property maintained by this key provider. Client applications should not call this method directly: It's intended to be used by user interface classes only.

Parameters:
key - The key property.
Throws:
IllegalStateException - if setting the key is not legal in the current state.

setKeyImpl

private void setKeyImpl(@CheckForNull
                        K newKey)

isChangeKeySelected

boolean isChangeKeySelected()
Returns whether or not the user shall get prompted for a new key upon the next call to SafeKeyProvider.getCreateKey(), provided that the key has been set before.

Returns:
Whether or not the user shall get prompted for a new key upon the next call to SafeKeyProvider.getCreateKey(), provided that the key has been set before.

setChangeKeySelected

public void setChangeKeySelected(boolean changeKeySelected)
Requests to prompt the user for a new key upon the next call to SafeKeyProvider.getCreateKey(), provided that the key has been set before.

Parameters:
changeKeySelected - whether or not the user shall get prompted for a new key upon the next call to SafeKeyProvider.getCreateKey(), provided that the key has been set before.

resetCancelledKey

public void resetCancelledKey()
Resets the state of this key provider and the current key if and only if prompting for a key has been cancelled.


resetUnconditionally

public void resetUnconditionally()
Resets the state of this key provider and the current key unconditionally.


reset

private void reset()

TrueZIP Driver TZP (ZIP.RAES) 7.0-rc1

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