org.pfsw.security.authentication
Class AutoAuthenticationManager

java.lang.Object
  extended by java.net.Authenticator
      extended by org.pfsw.security.authentication.AutoAuthenticationManager

public class AutoAuthenticationManager
extends java.net.Authenticator

This manager class is responsible to hold a registry of LocationCredentials objects. With the method aboutToAccess( URL ) it selects the appropriate Authenticator from its regestry and sets in as default into the java.net.Authenticator class. That allows to do automatic authentication for different (URLs).
Be aware that this code is not thread-safe!


Nested Class Summary
 
Nested classes/interfaces inherited from class java.net.Authenticator
java.net.Authenticator.RequestorType
 
Field Summary
protected static org.pfsw.text.Version HOST_SUPPORT_VERSION
           
protected static org.pfsw.text.Version JAVA_VERSION
           
 
Method Summary
 boolean aboutToAccess(java.lang.String url)
          This method must be called to activate the authenticator that provides credentials to be able to access the given URL.
 boolean aboutToAccess(java.net.URL url)
          This method must be called to activate the authenticator that provides credentials to be able to access the given URL.
protected  void fillFallbackAuthenticator()
           
protected  LocationCredentials findCredentialsFor(java.lang.String url)
           
protected  LocationCredentials findCredentialsForRealm()
           
protected  LocationCredentials findCredentialsForRealm(java.lang.String realm)
           
protected  java.net.PasswordAuthentication findPasswordAuthenticationForRealm()
           
protected  LocationCredentials getActiveCredentials()
           
protected  LocationCredentials getCredentials(java.lang.String id)
          Returns the location credentials registered under the specified key or null if not found.
 AbstractAuthenticator getFallbackAuthenticator()
          Returns the fallback authenticator which will be called if no credentials can be found in the registered credtentials.
protected  java.util.Map<java.lang.String,LocationCredentials> getLocationCredentials()
           
protected  java.net.PasswordAuthentication getPasswordAuthentication()
           
protected  boolean hasActiveCredentials()
           
static AutoAuthenticationManager install()
          Must be called once, to activate this authentication manager mechanism within the java.net.Authenticator.
static AutoAuthenticationManager instance()
          Returns the only instance this class supports (design pattern "Singleton")
protected  boolean isBasicHttp()
           
 void register(java.lang.String id, LocationCredentials credentials)
          Registers the given location credentials under the specified id.
 LocationCredentials remove(java.lang.String id)
          Removes the location credentials registered under the specified key from the registry.
 void reset()
          Removes all registered credentials and the fallback authenticator.
protected  void setActiveCredentials(LocationCredentials newValue)
           
 void setFallbackAuthenticator(AbstractAuthenticator newValue)
          Sets the fallback authenticator which will be called if no credentials can be found in the registered credtentials.
protected  void setLocationCredentials(java.util.Map<java.lang.String,LocationCredentials> newValue)
           
protected  org.pfsw.text.StringUtil str()
           
protected  boolean supportsHostNames()
           
static void uninstall()
          Can be called to remove this authentication manager from the java.net.Authenticator.
 
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
 

Field Detail

HOST_SUPPORT_VERSION

protected static final org.pfsw.text.Version HOST_SUPPORT_VERSION

JAVA_VERSION

protected static final org.pfsw.text.Version JAVA_VERSION
Method Detail

install

public static AutoAuthenticationManager install()
Must be called once, to activate this authentication manager mechanism within the java.net.Authenticator.

Returns:
The single instance of this class

uninstall

public static void uninstall()
Can be called to remove this authentication manager from the java.net.Authenticator.


instance

public static AutoAuthenticationManager instance()
Returns the only instance this class supports (design pattern "Singleton")


getFallbackAuthenticator

public AbstractAuthenticator getFallbackAuthenticator()
Returns the fallback authenticator which will be called if no credentials can be found in the registered credtentials.


setFallbackAuthenticator

public void setFallbackAuthenticator(AbstractAuthenticator newValue)
Sets the fallback authenticator which will be called if no credentials can be found in the registered credtentials.


aboutToAccess

public boolean aboutToAccess(java.lang.String url)
This method must be called to activate the authenticator that provides credentials to be able to access the given URL.

Parameters:
url - The URL that might need authentication to be accessed
Returns:
true if an authenticator for the given URL was activated

aboutToAccess

public boolean aboutToAccess(java.net.URL url)
This method must be called to activate the authenticator that provides credentials to be able to access the given URL.

Parameters:
url - The URL that might need authentication to be accessed
Returns:
true if an authenticator for the given URL was activated

register

public void register(java.lang.String id,
                     LocationCredentials credentials)
Registers the given location credentials under the specified id. The id can be used to remove the credentials once again.


remove

public LocationCredentials remove(java.lang.String id)
Removes the location credentials registered under the specified key from the registry. Returns the removed credentials or null if not found.


reset

public void reset()
Removes all registered credentials and the fallback authenticator.


getPasswordAuthentication

protected java.net.PasswordAuthentication getPasswordAuthentication()
Overrides:
getPasswordAuthentication in class java.net.Authenticator

findPasswordAuthenticationForRealm

protected java.net.PasswordAuthentication findPasswordAuthenticationForRealm()

getCredentials

protected LocationCredentials getCredentials(java.lang.String id)
Returns the location credentials registered under the specified key or null if not found.


findCredentialsFor

protected LocationCredentials findCredentialsFor(java.lang.String url)

findCredentialsForRealm

protected LocationCredentials findCredentialsForRealm()

findCredentialsForRealm

protected LocationCredentials findCredentialsForRealm(java.lang.String realm)

fillFallbackAuthenticator

protected void fillFallbackAuthenticator()

hasActiveCredentials

protected boolean hasActiveCredentials()

isBasicHttp

protected boolean isBasicHttp()

supportsHostNames

protected boolean supportsHostNames()

getLocationCredentials

protected java.util.Map<java.lang.String,LocationCredentials> getLocationCredentials()

setLocationCredentials

protected void setLocationCredentials(java.util.Map<java.lang.String,LocationCredentials> newValue)

getActiveCredentials

protected LocationCredentials getActiveCredentials()

setActiveCredentials

protected void setActiveCredentials(LocationCredentials newValue)

str

protected org.pfsw.text.StringUtil str()