org.pf.security.authentication
Class AutoAuthenticationManager

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

public class AutoAuthenticationManager
extends 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!

Version:
1.0
Author:
Manfred Duchrow

Nested Class Summary
 
Nested classes/interfaces inherited from class java.net.Authenticator
Authenticator.RequestorType
 
Method Summary
 boolean aboutToAccess(String url)
          This method must be called to activate the authenticator that provides credentials to be able to access the given URL.
 boolean aboutToAccess(URL url)
          This method must be called to activate the authenticator that provides credentials to be able to access the given URL.
 AbstractAuthenticator getFallbackAuthenticator()
          Returns the fallback authenticator which will be called if no credentials can be found in the registered credtentials.
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")
 void register(String id, LocationCredentials credentials)
          Registers the given location credentials under the specified id.
 LocationCredentials remove(String id)
          Removes the location credentials registered under the specified key from the registry.
 void reset()
          Removes all registered credentials and the fallback authenticator.
 void setFallbackAuthenticator(AbstractAuthenticator newValue)
          Sets the fallback authenticator which will be called if no credentials can be found in the registered credtentials.
static void uninstall()
          Can be called to remove this authentication manager from the java.net.Authenticator.
 
Methods inherited from class java.net.Authenticator
requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, setDefault
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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.


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")


aboutToAccess

public boolean aboutToAccess(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(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(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(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.



Copyright © 2013 Manfred Duchrow Consulting & Software. All Rights Reserved.