anon.infoservice
Class ProxyInterface

java.lang.Object
  extended by anon.infoservice.ListenerInterface
      extended by anon.infoservice.ProxyInterface
All Implemented Interfaces:
ImmutableListenerInterface, ImmutableProxyInterface, IXMLEncodable

public final class ProxyInterface
extends ListenerInterface
implements ImmutableProxyInterface, IXMLEncodable

This class is used to store information about a proxy connection.

Author:
Wendolsky

Field Summary
private static long AUTH_PASS_CANCEL_WAIT_TIME
          Authentication stuff
private  java.lang.String m_authenticationPassword
          A password for http authentication.
private  java.lang.String m_authenticationUserID
          A user id for http authentication.
private  long m_authPassLastCancelTime
           
private  boolean m_bAuthPassDialogShown
           
private  boolean m_bUseAuthentication
          If the authentication strings are used.
private  boolean m_bUseInterface
          If the proxy is used or not.
private  IPasswordReader m_passwordReader
          The password reader instance.
private static java.lang.String XML_AUTHENTICATION_USER_ID
          The name of the xml node that stores the user id for authentication.
private static java.lang.String XML_USE_AUTHENTICATION
          The name of the xml node that describes if authentication is used.
private static java.lang.String XML_USE_PROXY
          The name of the xml node that describes if authentication is used.
 
Fields inherited from class anon.infoservice.ListenerInterface
PORT_MAX_VALUE, PORT_MIN_VALUE, XML_ATTR_HIDDEN, XML_ATTR_VIRTUAL, XML_ELEM_FILE, XML_ELEM_HOST, XML_ELEM_PORT, XML_ELEMENT_CONTAINER_NAME, XML_ELEMENT_NAME
 
Fields inherited from interface anon.infoservice.ImmutableListenerInterface
PROTOCOL_STR_TYPE_HTTP, PROTOCOL_STR_TYPE_HTTPS, PROTOCOL_STR_TYPE_RAW_TCP, PROTOCOL_STR_TYPE_RAW_UNIX, PROTOCOL_STR_TYPE_SOCKS, PROTOCOL_STR_TYPE_UNKNOWN, PROTOCOL_TYPE_HTTP, PROTOCOL_TYPE_HTTPS, PROTOCOL_TYPE_RAW_TCP, PROTOCOL_TYPE_RAW_UNIX, PROTOCOL_TYPE_SOCKS, PROTOCOL_TYPE_UNKNOWN
 
Fields inherited from interface anon.util.IXMLEncodable
FIELD_XML_ELEMENT_CONTAINER_NAME, FIELD_XML_ELEMENT_NAME, XML_ATTR_ID, XML_ATTR_LANGUAGE, XML_ATTR_VERSION
 
Constructor Summary
ProxyInterface(org.w3c.dom.Element a_proxyInterfaceNode, IPasswordReader a_passwordReader)
          Creates a new ProxyInterface from XML description (ProxyInterface node).
ProxyInterface(java.lang.String a_hostname, int a_port, int a_protocol, IPasswordReader a_passwordReader)
          Creates a new ListenerInterface from a hostname / IP address, a port and a protocol information.
ProxyInterface(java.lang.String a_hostname, int a_port, int a_protocol, java.lang.String a_authenticationUserID, IPasswordReader a_passwordReader, boolean a_bUseAuthentication, boolean a_bIsValid)
          Creates a new interface for a proxy that needs basic http authentication.
ProxyInterface(java.lang.String a_hostname, int a_port, IPasswordReader a_passwordReader)
          Creates a new interface from a hostname / IP address and a port.
ProxyInterface(java.lang.String a_hostname, int a_port, java.lang.String a_protocol, java.lang.String a_authenticationUserID, IPasswordReader a_passwordReader, boolean a_bUseAuthentication, boolean a_bIsValid)
          Creates a new interface for a proxy that needs basic http authentication.
 
Method Summary
 void clearAuthenticationPassword()
           
 boolean equals(ProxyInterface a_proxyInterface)
          Tests if two interface instances are equal.
 java.lang.String getAuthenticationPassword()
          Gets the authentication password of this interface.
 java.lang.String getAuthenticationUserID()
          Gets the authentication user ID of this interface.
 HTTPClient.NVPair getProxyAuthorizationHeader()
          Get the authorization header with the current user id and password.
 java.lang.String getProxyAuthorizationHeaderAsString()
          Gets the authorization header with the current user id and password as a String.
static java.lang.String getXMLElementName()
          Gets the name of the corresponding xml element.
 boolean isAuthenticationUsed()
          Gets if the authentication strings are used.
 boolean isValid()
          Gets if the proxy is used or not.
static boolean isValidUserID(java.lang.String a_authenticationUserID)
          Gets if the given string is a valid user ID for authentication.
 void setAuthenticationUserID(java.lang.String a_authenticationUserID)
          Sets the authentication user ID of this interface and resets the authentication password if the user id has changed.
 boolean setUseAuthentication(boolean a_bUseAuthentication)
          Sets if the authentication strings are used and reads a password form the password reader if necessary.
 void setUseInterface(boolean a_bUseInterface)
          Activates and deactivates the proxy.
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
          Creates an XML node without signature and password for this ProxyInterface.
 
Methods inherited from class anon.infoservice.ListenerInterface
blockInterface, equals, getHost, getPort, getProtocol, getProtocolAsString, isHidden, isValidHostname, isValidIP, isValidPort, isValidProtocol, isValidProtocol, isVirtual, recognizeProtocol, recognizeProtocol, setHostname, setPort, setProtocol, setProtocol, toString, toVector, toXmlElementInternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface anon.infoservice.ImmutableListenerInterface
getHost, getPort, getProtocol
 

Field Detail

XML_USE_AUTHENTICATION

private static java.lang.String XML_USE_AUTHENTICATION
The name of the xml node that describes if authentication is used.


XML_USE_PROXY

private static java.lang.String XML_USE_PROXY
The name of the xml node that describes if authentication is used.


XML_AUTHENTICATION_USER_ID

private static java.lang.String XML_AUTHENTICATION_USER_ID
The name of the xml node that stores the user id for authentication.


m_authenticationPassword

private java.lang.String m_authenticationPassword
A password for http authentication.


m_authenticationUserID

private java.lang.String m_authenticationUserID
A user id for http authentication.


m_bUseAuthentication

private boolean m_bUseAuthentication
If the authentication strings are used.


m_bUseInterface

private boolean m_bUseInterface
If the proxy is used or not.


m_passwordReader

private IPasswordReader m_passwordReader
The password reader instance.


AUTH_PASS_CANCEL_WAIT_TIME

private static final long AUTH_PASS_CANCEL_WAIT_TIME
Authentication stuff

See Also:
Constant Field Values

m_authPassLastCancelTime

private volatile long m_authPassLastCancelTime

m_bAuthPassDialogShown

private boolean m_bAuthPassDialogShown
Constructor Detail

ProxyInterface

public ProxyInterface(org.w3c.dom.Element a_proxyInterfaceNode,
                      IPasswordReader a_passwordReader)
               throws XMLParseException
Creates a new ProxyInterface from XML description (ProxyInterface node).

Parameters:
a_proxyInterfaceNode - The ProxyInterface node from an XML document.
a_passwordReader - the password reader; this is allowed to be null, but then you won`t be able to use proxy authentication
Throws:
XMLParseException - if an error in the xml structure occurs

ProxyInterface

public ProxyInterface(java.lang.String a_hostname,
                      int a_port,
                      IPasswordReader a_passwordReader)
               throws java.lang.IllegalArgumentException
Creates a new interface from a hostname / IP address and a port.

Parameters:
a_hostname - The hostname or the IP address of this interface.
a_port - The port of this interface.
a_passwordReader - the password reader; this is allowed to be null, but then you won`t be able to use proxy authentication
Throws:
java.lang.IllegalArgumentException - if an illegal host name or port was given

ProxyInterface

public ProxyInterface(java.lang.String a_hostname,
                      int a_port,
                      int a_protocol,
                      IPasswordReader a_passwordReader)
               throws java.lang.IllegalArgumentException
Creates a new ListenerInterface from a hostname / IP address, a port and a protocol information.

Parameters:
a_hostname - The hostname or the IP address of this interface.
a_port - The port of this interface (1 <= port <= 65535).
a_protocol - The protocol information. Invalid protocols are replaced by http.
a_passwordReader - the password reader; this is allowed to be null, but then you won`t be able to use proxy authentication
Throws:
java.lang.IllegalArgumentException - if an illegal host name, port or protocol was given

ProxyInterface

public ProxyInterface(java.lang.String a_hostname,
                      int a_port,
                      java.lang.String a_protocol,
                      java.lang.String a_authenticationUserID,
                      IPasswordReader a_passwordReader,
                      boolean a_bUseAuthentication,
                      boolean a_bIsValid)
               throws java.lang.IllegalArgumentException
Creates a new interface for a proxy that needs basic http authentication.

Parameters:
a_hostname - The hostname or the IP address of this interface.
a_port - The port of this interface (1 <= port <= 65535).
a_protocol - The protocol information. Invalid protocols are replaced by http.
a_authenticationUserID - a user ID for authentication
a_passwordReader - the password reader; this is allowed to be null, but then you won`t be able to use proxy authentication
a_bUseAuthentication - true if the authentication strings are used; false otherwise
a_bIsValid - if the proxy should be used by now (true) or later (false)
Throws:
java.lang.IllegalArgumentException - if an illegal host name, port or protocol was given or if authentication should be used without password reader

ProxyInterface

public ProxyInterface(java.lang.String a_hostname,
                      int a_port,
                      int a_protocol,
                      java.lang.String a_authenticationUserID,
                      IPasswordReader a_passwordReader,
                      boolean a_bUseAuthentication,
                      boolean a_bIsValid)
               throws java.lang.IllegalArgumentException
Creates a new interface for a proxy that needs basic http authentication.

Parameters:
a_hostname - The hostname or the IP address of this interface.
a_port - The port of this interface (1 <= port <= 65535).
a_protocol - The protocol information. Invalid protocols are replaced by http.
a_authenticationUserID - a user ID for authentication
a_passwordReader - the password reader; this is allowed to be null, but then you won`t be able to use proxy authentication
a_bUseAuthentication - true if the authentication strings are used; false otherwise
a_bIsValid - if the proxy should be used by now (true) or later (false)
Throws:
java.lang.IllegalArgumentException - if an illegal host name, port or protocol was given or if authentication should be used without password reader
Method Detail

getXMLElementName

public static java.lang.String getXMLElementName()
Gets the name of the corresponding xml element.

Returns:
the name of the corresponding xml element

isValidUserID

public static boolean isValidUserID(java.lang.String a_authenticationUserID)
Gets if the given string is a valid user ID for authentication.

Parameters:
a_authenticationUserID - a String
Returns:
true if the given string is a valid user ID for authentication; false otherwise

isAuthenticationUsed

public boolean isAuthenticationUsed()
Gets if the authentication strings are used.

Specified by:
isAuthenticationUsed in interface ImmutableProxyInterface
Returns:
true if the authentication strings are used; false otherwise

setUseAuthentication

public boolean setUseAuthentication(boolean a_bUseAuthentication)
                             throws java.lang.IllegalStateException
Sets if the authentication strings are used and reads a password form the password reader if necessary.

Parameters:
a_bUseAuthentication - true if the authentication strings should be used; false otherwise
Returns:
true if the authentication strings are used; false otherwise or if no password reader is registered
Throws:
java.lang.IllegalStateException - if authentication should be used, but it is not possible

getAuthenticationPassword

public java.lang.String getAuthenticationPassword()
                                           throws java.lang.IllegalStateException
Gets the authentication password of this interface. If no password is set, it is read from the password reader.

Specified by:
getAuthenticationPassword in interface ImmutableProxyInterface
Returns:
the authentication password of this interface
Throws:
java.lang.IllegalStateException - if no password reader is registered

clearAuthenticationPassword

public void clearAuthenticationPassword()

getAuthenticationUserID

public java.lang.String getAuthenticationUserID()
Gets the authentication user ID of this interface.

Specified by:
getAuthenticationUserID in interface ImmutableProxyInterface
Returns:
the authentication user ID of this interface

setAuthenticationUserID

public void setAuthenticationUserID(java.lang.String a_authenticationUserID)
Sets the authentication user ID of this interface and resets the authentication password if the user id has changed.

Parameters:
a_authenticationUserID - the authentication user ID of this interface

getProxyAuthorizationHeaderAsString

public java.lang.String getProxyAuthorizationHeaderAsString()
                                                     throws java.lang.IllegalStateException
Gets the authorization header with the current user id and password as a String.

Specified by:
getProxyAuthorizationHeaderAsString in interface ImmutableProxyInterface
Returns:
the authorization header with the current user id and password as a String
Throws:
java.lang.IllegalStateException - if the authentication mode is not activated

getProxyAuthorizationHeader

public HTTPClient.NVPair getProxyAuthorizationHeader()
                                              throws java.lang.IllegalStateException
Get the authorization header with the current user id and password.

Specified by:
getProxyAuthorizationHeader in interface ImmutableProxyInterface
Returns:
the authorization header with the current user id and password
Throws:
java.lang.IllegalStateException - if the authentication mode is not activated

equals

public boolean equals(ProxyInterface a_proxyInterface)
Tests if two interface instances are equal. The authentication passwords are not compared!

Parameters:
a_proxyInterface - a ListenerInterface
Returns:
true if the two ListenerInterface instances are equal; false otherwise

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
Creates an XML node without signature and password for this ProxyInterface.

Specified by:
toXmlElement in interface IXMLEncodable
Overrides:
toXmlElement in class ListenerInterface
Parameters:
a_doc - The XML document, which is the environment for the created XML node.
Returns:
The ProxyInterface XML node.

isValid

public boolean isValid()
Gets if the proxy is used or not.

Specified by:
isValid in interface ImmutableListenerInterface
Overrides:
isValid in class ListenerInterface
Returns:
true if the proxy is used; false otherwise

setUseInterface

public void setUseInterface(boolean a_bUseInterface)
Activates and deactivates the proxy.

Overrides:
setUseInterface in class ListenerInterface
Parameters:
a_bUseInterface - boolean