net.sourceforge.jradiusclient
Class RadiusClient

java.lang.Object
  |
  +--net.sourceforge.jradiusclient.RadiusClient

public class RadiusClient
extends java.lang.Object

Released under the LGPL
This class provides basic functionality required to implement a NAS as defined by the RADIUS protocol as specified in RFC 2865 and RFC 2866. This implementation is stateless and not thread safe, i.e. since the user name could be changed by the current thread or any other thread, it is difficult to ensure that the responseAttributes correlate to the request we think we are dealing with. It is up to the user of this class to ensure these things at this point. A future release may change this class to a stateful, threadsafe object, but it works for now. Users of this class must also manage building their own request attributes and submitting them with their call to authenticate. For example a programmer using this library, wanting to do chap authentication needs to generate the random challenge, send it to the user, who generates the MD5 of

(see RFC 2865 section 2.2) The user software returns the CHAP Identifier and the MD5 result and the programmer using RadiusClient sets that as the CHAP Password. The programmer also sets the CHAP-Challenge attribute and sends that to the Radius Server for authentication.
Special Thanks to the original creator of the "RadiusClient" August Mueller http://augiesoft.com/java/radius/ and to Aziz Abouchi for laying the groundwork for the development of this class.

Version:
$Revision: 1.34 $
Author:
Robert J. Loihl

Constructor Summary
RadiusClient(java.lang.String hostname, int authPort, int acctPort, java.lang.String sharedSecret)
          Constructor allows the user to specify an alternate port for the radius server
RadiusClient(java.lang.String hostname, int authPort, int acctPort, java.lang.String sharedSecret, int sockTimeout)
          Constructor allows the user to specify an alternate port for the radius server
RadiusClient(java.lang.String hostname, java.lang.String sharedSecret)
          Constructor - uses the default port 1812 for authentication and 1813 for accounting
 
Method Summary
 RadiusPacket account(RadiusPacket requestPacket)
          This method performs the job of sending accounting information for the current user to the radius accounting server.
 RadiusPacket authenticate(RadiusPacket accessRequest)
          This method performs the job of authenticating the given RadiusPacket against the radius server.
 RadiusPacket authenticate(RadiusPacket accessRequest, int retries)
          This method performs the job of authenticating the given RadiusPacket against the radius server.
protected  void closeSocket()
          closes the socket
 boolean equals(java.lang.Object object)
          Compares the specified Object with this RadiusClient for equality.
 void finalize()
          overrides finalize to close socket and then normal finalize on super class
 int getAcctPort()
          This method returns the current port to be used for accounting
 int getAuthPort()
          This method returns the current port to be used for authentication
 java.lang.String getHostname()
          This method returns the current Host Name to be used for RADIUS authentication or accounting
 java.lang.String getSharedSecret()
          This method returns the current secret value that the Radius Client shares with the RADIUS Server.
 int getTimeout()
          This method returns the current timeout period on a recieve of a response from the RADIUS Server.
 int hashCode()
           
 java.lang.String toString()
          This method returns a string representation of this RadiusClient.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RadiusClient

public RadiusClient(java.lang.String hostname,
                    java.lang.String sharedSecret)
             throws RadiusException,
                    InvalidParameterException
Constructor - uses the default port 1812 for authentication and 1813 for accounting

Parameters:
hostname - java.lang.String
sharedSecret - java.lang.String
Throws:
java.net.SocketException - If we could not create the necessary socket
java.security.NoSuchAlgorithmException - If we could not get an instance of the MD5 algorithm.
InvalidParameterException - If an invalid hostname (null or empty string), an invalid port (port < 0 or port > 65536) or an invalid shared secret (null, shared secret can be empty string) is passed in.
RadiusException

RadiusClient

public RadiusClient(java.lang.String hostname,
                    int authPort,
                    int acctPort,
                    java.lang.String sharedSecret)
             throws RadiusException,
                    InvalidParameterException
Constructor allows the user to specify an alternate port for the radius server

Parameters:
hostname - java.lang.String
authPort - int the port to use for authentication requests
acctPort - int the port to use for accounting requests
sharedSecret - java.lang.String
Throws:
java.net.SocketException - If we could not create the necessary socket
java.security.NoSuchAlgorithmException - If we could not get an instance of the MD5 algorithm.
InvalidParameterException - If an invalid hostname (null or empty string), an invalid port ( port < 0 or port > 65536) or an invalid shared secret (null, shared secret can be empty string) is passed in.
RadiusException

RadiusClient

public RadiusClient(java.lang.String hostname,
                    int authPort,
                    int acctPort,
                    java.lang.String sharedSecret,
                    int sockTimeout)
             throws RadiusException,
                    InvalidParameterException
Constructor allows the user to specify an alternate port for the radius server

Parameters:
hostname - java.lang.String
authPort - int the port to use for authentication requests
acctPort - int the port to use for accounting requests
sharedSecret - java.lang.String
Throws:
RadiusException - If we could not create the necessary socket, If we could not get an instance of the MD5 algorithm, or the hostname did not pass validation
InvalidParameterException - If an invalid hostname (null or empty string), an invalid port ( port < 0 or port > 65536) or an invalid shared secret (null, shared secret can be empty string) is passed in.
Method Detail

authenticate

public RadiusPacket authenticate(RadiusPacket accessRequest)
                          throws RadiusException,
                                 InvalidParameterException
This method performs the job of authenticating the given RadiusPacket against the radius server.

Returns:
RadiusPacket containing the response attributes for this request
Throws:
RadiusException
InvalidParameterException

authenticate

public RadiusPacket authenticate(RadiusPacket accessRequest,
                                 int retries)
                          throws RadiusException,
                                 InvalidParameterException
This method performs the job of authenticating the given RadiusPacket against the radius server.

Returns:
RadiusPacket containing the response attributes for this request
Throws:
RadiusException
InvalidParameterException

account

public RadiusPacket account(RadiusPacket requestPacket)
                     throws InvalidParameterException,
                            RadiusException
This method performs the job of sending accounting information for the current user to the radius accounting server.

Parameters:
requestPacket - Any request attributes to add to the accounting packet.
Returns:
RadiusPacket a packet containing the response from the Radius server
Throws:
RadiusException
InvalidParameterException

getHostname

public java.lang.String getHostname()
This method returns the current Host Name to be used for RADIUS authentication or accounting

Returns:
java.lang.String The name of the host the radius server is running on. Can be either the name or the dotted-quad IP address

getAuthPort

public int getAuthPort()
This method returns the current port to be used for authentication

Returns:
int

getAcctPort

public int getAcctPort()
This method returns the current port to be used for accounting

Returns:
int

getSharedSecret

public java.lang.String getSharedSecret()
This method returns the current secret value that the Radius Client shares with the RADIUS Server.

Returns:
java.lang.String

getTimeout

public int getTimeout()
This method returns the current timeout period on a recieve of a response from the RADIUS Server.

Returns:
int

toString

public java.lang.String toString()
This method returns a string representation of this RadiusClient.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object.

equals

public boolean equals(java.lang.Object object)
Compares the specified Object with this RadiusClient for equality. Returns true if the given object is also a RadiusClient and the two RadiusClient have the same host, port, sharedSecret & username.

Overrides:
equals in class java.lang.Object
Parameters:
object - Object to be compared for equality with this RadiusClient.
Returns:
true if the specified Object is equal to this RadiusClient.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
int the hashCode for this RadiusClient

closeSocket

protected void closeSocket()
closes the socket


finalize

public void finalize()
              throws java.lang.Throwable
overrides finalize to close socket and then normal finalize on super class

Overrides:
finalize in class java.lang.Object
java.lang.Throwable