ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui
Class JxNetAuthenticator

java.lang.Object
  extended by java.net.Authenticator
      extended by com.ehsbe.commons.util.NetAuthenticator
          extended by com.ehsbe.commons.gui.JxNetAuthenticator

public abstract class JxNetAuthenticator
extends NetAuthenticator

A GUI enabled Authenticator, which fires up a login dialog on NetAuthenticator.getPasswordAuthentications() to let the user enter username/password and optionally a master password for encryption/decryption of an external password store.

To save the internal password store back to the external form, call close() on this instance.

Version:
$Revision: 462 $
Author:
Jens Elkner
See Also:
Authenticator.setDefault(java.net.Authenticator), NetAuthenticator

Nested Class Summary
 
Nested classes/interfaces inherited from class java.net.Authenticator
Authenticator.RequestorType
 
Constructor Summary
JxNetAuthenticator()
          Create a new JxNetAuthenticator.
JxNetAuthenticator(Component guiAnchor)
          Create a new JxNetAuthenticator.
 
Method Summary
 void close()
          Reset this instance to its initial state.
 Component getGuiAnchor()
          Set the "anchor" to which dialogs should be relative positioned.
protected  char[] getMasterPassword(Boolean type)
          Get the master password to generate the secret key for decrypting the encrypted password store.
protected  Set<PasswordAuthentication> getPasswordAuthentications()
          Fires up the authentication dialog to obtain a username/password pair for the authorization requesting entity.
protected abstract  byte[] getPasswordStore()
          Get the encrypted password store.
protected  PasswordAuthentication getUserPass(Set<PasswordAuthentication> pa)
          Invoke a dialog to let the user enter the required username and password.
 void setGuiAnchor(Component anchor)
          Set the "anchor" to which dialogs should be relative positioned.
protected abstract  void setPasswordStore(byte[] store)
          Set/save the encrypted password store.
 
Methods inherited from class com.ehsbe.commons.util.NetAuthenticator
add, cleanPass, getPasswordAuthentication, isEmpty, isSecretKeySet, read, read, remove, reset, setSecretKey, store, store, storeModified
 
Methods inherited from class java.net.Authenticator
getRequestingHost, getRequestingPort, getRequestingPrompt, getRequestingProtocol, getRequestingScheme, getRequestingSite, getRequestingURL, getRequestorType, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, setDefault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JxNetAuthenticator

public JxNetAuthenticator()
Create a new JxNetAuthenticator. Dialogs will be centered on the screen.


JxNetAuthenticator

public JxNetAuthenticator(Component guiAnchor)
Create a new JxNetAuthenticator.

Parameters:
guiAnchor - anchor for dialogs. If nont null, dialogs are positioned relative to the given anchor, otherwise centered on the screen.
See Also:
Window.setLocationRelativeTo(Component), Util.center(Component)
Method Detail

getPasswordStore

protected abstract byte[] getPasswordStore()
Get the encrypted password store.

Returns:
null if there is none, the store otherwise.

setPasswordStore

protected abstract void setPasswordStore(byte[] store)
Set/save the encrypted password store.

Parameters:
store - the encrypted store to save.
See Also:
close()

getMasterPassword

protected char[] getMasterPassword(Boolean type)
Get the master password to generate the secret key for decrypting the encrypted password store.

Parameters:
type - if null, ask for the existing master password to encrypt/decrypt the password store, if true ask for a initial master password to set for a new password store, otherwise ask for the old and a new master password to set.
Returns:
null if not password could be obtained from the user, i.e. don't ask again, the password otherwise.

getUserPass

protected PasswordAuthentication getUserPass(Set<PasswordAuthentication> pa)
Invoke a dialog to let the user enter the required username and password.

Parameters:
pa - a list of username/password pairs from the password store
Returns:
null if dialog has been canceled, i.e. no username/password pair is available, the appropriate pair otherwise.

getPasswordAuthentications

protected Set<PasswordAuthentication> getPasswordAuthentications()
Fires up the authentication dialog to obtain a username/password pair for the authorization requesting entity.

Overrides:
getPasswordAuthentications in class NetAuthenticator
Returns:
null if not entries are found, a copy of the set of possible authentication pairs matching the entity requesting authentication otherwise.
See Also:
getPasswordStore(), getMasterPassword(Boolean), getUserPass(Set)

close

public void close()
           throws SecurityException
Reset this instance to its initial state. If the internal store has been modified and a secret key has been set, the internal store gets encrypted and setPasswordStore(byte[]) called. Finally the internal password store as well the its secret key gets cleared.

Throws:
SecurityException
See Also:
NetAuthenticator.storeModified(), NetAuthenticator.isSecretKeySet(), NetAuthenticator.store(), NetAuthenticator.reset()

setGuiAnchor

public void setGuiAnchor(Component anchor)
Set the "anchor" to which dialogs should be relative positioned.

Parameters:
anchor - anchor to set. Might be null, if dialogs should be centered on the screen.
See Also:
Window.setLocationRelativeTo(Component), Util.center(Component)

getGuiAnchor

public Component getGuiAnchor()
Set the "anchor" to which dialogs should be relative positioned.

Returns:
the anchor. Might be null, if dialogs are currently centered on the screen.

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.