TrueZIP Driver ZIP.RAES (TZP) 7.1

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.View interface which is injected to this instance by a PromptingKeyManager. The view 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 using the given PromptingKeyProvider.Controller.

Author:
Christian Schlichtherle
See Also:
PromptingKeyManager

Nested Class Summary
static class PromptingKeyProvider.Controller<K extends SafeKey<K>>
          Proxies access to the key for PromptingKeyProvider.View implementations.
static class PromptingKeyProvider.Factory<K extends SafeKey<K>>
          A factory for PromptingKeyProviders.
private static class PromptingKeyProvider.ReadController<K extends SafeKey<K>>
           
(package private) static class PromptingKeyProvider.State
          Implements the behavior strategy of its enclosing class.
static interface PromptingKeyProvider.View<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.
private static class PromptingKeyProvider.WriteController<K extends SafeKey<K>>
           
 
Field Summary
private  boolean changeRequested
           
private  K key
           
private  URI resource
          The resource identifier for the protected resource.
private  PromptingKeyProvider.State state
           
private  PromptingKeyProvider.View<K> view
          The view 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
private  K getKey()
           
protected  K getReadKeyImpl(boolean invalid)
          Returns the key for reading the contents of an existing protected resource.
 URI getResource()
          Returns the unique resource identifier (resource ID) of the protected resource for which this key provider is used.
private  PromptingKeyProvider.State getState()
           
(package private)  PromptingKeyProvider.View<K> getView()
           
protected  K getWriteKeyImpl()
          Returns the key for (over)writing the contents of a new or existing protected resource.
private  boolean isChangeRequested()
          Returns whether or not the user shall get prompted for a new key upon the next call to SafeKeyProvider.getWriteKey(), provided that the key has been set before.
private  void reset()
           
 void resetCancelledKey()
          Resets the state of this key provider, its current key and the value of its changeRequested property if and only if prompting for a key has been cancelled.
 void resetUnconditionally()
          Resets the state of this key provider, its current key and the value of its changeRequested property unconditionally.
private  void setChangeRequested(boolean changeRequested)
           
 void setKey(K newKey)
          Sets the key programmatically.
(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 setView(PromptingKeyProvider.View<K> view)
           
 
Methods inherited from class de.schlichtherle.truezip.key.SafeKeyProvider
clone, getReadKey, getWriteKey, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resource

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


view

@CheckForNull
private volatile PromptingKeyProvider.View<K extends SafeKey<K>> view
The view instance which is used to prompt the user for a key.


state

@NonNull
private volatile PromptingKeyProvider.State state

key

@CheckForNull
private volatile K extends SafeKey<K> key

changeRequested

private volatile boolean changeRequested
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.


getView

final PromptingKeyProvider.View<K> getView()

setView

final void setView(PromptingKeyProvider.View<K> view)

getState

@NonNull
private PromptingKeyProvider.State getState()

setState

private void setState(@NonNull
                      PromptingKeyProvider.State state)

getWriteKeyImpl

protected final K getWriteKeyImpl()
                                              throws UnknownKeyException
Description copied from class: SafeKeyProvider
Returns the key for (over)writing the contents of a new or existing protected resource.

Subsequent calls to this method may return the same object.

Specified by:
getWriteKeyImpl in class SafeKeyProvider<K extends SafeKey<K>>
Returns:
The key for (over)writing the contents of a new or existing protected resource.
Throws:
UnknownKeyException - if the required key is unknown for some reason, e.g. if prompting for the key has been disabled or cancelled by the user.
See Also:
SafeKeyProvider.getWriteKey()

getReadKeyImpl

protected final K getReadKeyImpl(boolean invalid)
                                             throws UnknownKeyException
Description copied from class: SafeKeyProvider
Returns the key for reading the contents of an existing protected resource.

Subsequent calls to this method may return the same object.

Specified by:
getReadKeyImpl in class SafeKeyProvider<K extends SafeKey<K>>
Returns:
The key for reading the contents of an existing protected resource.
Throws:
UnknownKeyException - If the required key is unknown. At the subclasses discretion, this may mean that prompting for the key has been disabled or cancelled by the user.
See Also:
KeyProvider.getWriteKey()

getKey

@CheckForNull
private K getKey()

setKey

public void setKey(@CheckForNull
                   K newKey)
Description copied from interface: KeyProvider
Sets the key programmatically.

Parameters:
newKey - the key. If this is null, this key provider is set to a state as if prompting for the key had been disabled or cancelled.

isChangeRequested

private boolean isChangeRequested()
Returns whether or not the user shall get prompted for a new key upon the next call to SafeKeyProvider.getWriteKey(), 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.getWriteKey(), provided that the key has been set before.

setChangeRequested

private void setChangeRequested(boolean changeRequested)

resetCancelledKey

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


resetUnconditionally

public void resetUnconditionally()
Resets the state of this key provider, its current key and the value of its changeRequested property unconditionally.


reset

private void reset()

TrueZIP Driver ZIP.RAES (TZP) 7.1

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