edu.sdsc.inca
Class Component

java.lang.Object
  extended by edu.sdsc.inca.Component
Direct Known Subclasses:
Client, Server

public class Component
extends java.lang.Object

This class encapsulates the common behavior of the Client and Server classes.


Field Summary
protected  boolean authenticate
           
protected  java.security.cert.Certificate cert
           
protected  java.lang.String certPath
           
static java.lang.String COMPONENT_OPTS
           
protected  java.lang.String hostname
           
protected  java.security.KeyPair key
           
protected  java.lang.String keyPath
           
protected  java.lang.String logFile
           
protected static org.apache.log4j.Logger logger
           
protected  java.lang.String password
           
protected  int port
           
protected  java.util.Vector trusted
           
protected  java.lang.String trustedPath
           
 
Constructor Summary
Component()
           
 
Method Summary
 void addTrustedCert(java.security.cert.Certificate trusted)
          Add a single trusted certificate.
static void configComponent(Component c, java.lang.String[] args, java.lang.String opts, java.lang.String prefix, java.lang.String exec, java.lang.String versionFilename)
          A convenience function for configuring a Component (or descendent class) from the system properties, the arguments passed to main, and the properties file.
protected  java.lang.Object createSocket(boolean serverSocket, java.lang.String host, int port)
          Creates and returns a socket with any appropriate authentication.
 boolean getAuthenticate()
          Is the connection authenticated?
 java.security.cert.Certificate getCertificate()
          Returns the component certificate.
 java.lang.String getCertificatePath()
          Returns the path to the component certificate.
 java.lang.String getHostname()
          Returns the name of the host where the server is running.
 java.security.KeyPair getKey()
          Returns the component key.
 java.lang.String getKeyPath()
          Returns the path to the component private key.
 java.lang.String getLogFile()
          Returns the path to the file where the component writes log messages.
 java.lang.String getPassword()
          Gets the component encryption password.
 int getPort()
          Returns the port where the Server is listening.
 java.security.cert.Certificate[] getTrustedCertificates()
          Returns the set of certificates trusted by the component.
 java.lang.String getTrustedPath()
          Get the path to the component trusted certificate directory.
 java.lang.String getUri()
          Return the uri for the server.
static java.io.InputStream openResourceStream(java.lang.String resourcePath)
          Returns an input stream for a resource found either in the classpath or on the file system.
 void readCredentials()
          Read in the credentials using the paths to the credentials and passphrase.
static java.lang.String readVersion(java.lang.String versionFilename)
          Read the version for the component from a file in the classpath.
 void setAuthenticate(boolean authenticate)
          Determines whether or not the connection is authenticated.
 void setCertificatePath(java.lang.String path)
          Sets the path to the file that contains the component certificate.
 void setConfiguration(java.util.Properties config)
          A convenience function for setting multiple Component configuration properties at once.
 void setHostname(java.lang.String hostname)
          Sets the name of the host where the server is running.
 void setKeyPath(java.lang.String path)
          Sets the path to the file that contains the component private key.
 void setLogFile(java.lang.String path)
          Sets the path to the file where the component writes log messages.
 void setPassword(java.lang.String password)
          Sets the component encryption password.
 void setPort(int port)
          Set the port to bind to.
 void setTrustedPath(java.lang.String path)
          Set the trusted certificates to the contents of the directory given.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_OPTS

public static final java.lang.String COMPONENT_OPTS
See Also:
Constant Field Values

logger

protected static final org.apache.log4j.Logger logger

authenticate

protected boolean authenticate

certPath

protected java.lang.String certPath

hostname

protected java.lang.String hostname

keyPath

protected java.lang.String keyPath

logFile

protected java.lang.String logFile

password

protected java.lang.String password

port

protected int port

trustedPath

protected java.lang.String trustedPath

cert

protected java.security.cert.Certificate cert

key

protected java.security.KeyPair key

trusted

protected java.util.Vector trusted
Constructor Detail

Component

public Component()
Method Detail

addTrustedCert

public void addTrustedCert(java.security.cert.Certificate trusted)
Add a single trusted certificate.

Parameters:
trusted - the certificate to add

getAuthenticate

public boolean getAuthenticate()
Is the connection authenticated?

Returns:
whether or not the connection is authenticated

getCertificate

public java.security.cert.Certificate getCertificate()
Returns the component certificate. Valid only after the component's socket has been created.

Returns:
the component certificate

getCertificatePath

public java.lang.String getCertificatePath()
Returns the path to the component certificate.

Returns:
The path to the certificate.

getHostname

public java.lang.String getHostname()
Returns the name of the host where the server is running.

Returns:
A string containing the hostname of the server

getKey

public java.security.KeyPair getKey()
Returns the component key. Valid only after the component's socket has been created.

Returns:
the component key

getKeyPath

public java.lang.String getKeyPath()
Returns the path to the component private key.

Returns:
The path to the private key.

getLogFile

public java.lang.String getLogFile()
Returns the path to the file where the component writes log messages.

Returns:
the path to the log file

getPassword

public java.lang.String getPassword()
Gets the component encryption password.

Returns:
the encryption password

getPort

public int getPort()
Returns the port where the Server is listening.

Returns:
The port the server is or will be listening on

getTrustedCertificates

public java.security.cert.Certificate[] getTrustedCertificates()
Returns the set of certificates trusted by the component. Valid only after the component's socket has been created.

Returns:
the component trusted certificates

getTrustedPath

public java.lang.String getTrustedPath()
Get the path to the component trusted certificate directory.

Returns:
the trusted certificate directory

getUri

public java.lang.String getUri()
Return the uri for the server.

Returns:
A string containing the uri of the server

setAuthenticate

public void setAuthenticate(boolean authenticate)
Determines whether or not the connection is authenticated.

Parameters:
authenticate - authenticate the connection?

setCertificatePath

public void setCertificatePath(java.lang.String path)
Sets the path to the file that contains the component certificate.

Parameters:
path - path to the certificate file

setConfiguration

public void setConfiguration(java.util.Properties config)
                      throws ConfigurationException
A convenience function for setting multiple Component configuration properties at once. Recognized elements of config are: "auth", the authorization indicator; "cert", the path to the certificate file; "hostname", the name of the host the server is running on; "key", the path to the component key; "logfile", the path to the component log; "password", the encryption password; "port", the server port; "trusted", the trusted cert directory.

Parameters:
config - contains configuration values
Throws:
ConfigurationException - on a faulty configuration property value

setHostname

public void setHostname(java.lang.String hostname)
Sets the name of the host where the server is running.

Parameters:
hostname - A string containing the hostname of the server

setKeyPath

public void setKeyPath(java.lang.String path)
Sets the path to the file that contains the component private key.

Parameters:
path - path to the private key file

setLogFile

public void setLogFile(java.lang.String path)
                throws ConfigurationException
Sets the path to the file where the component writes log messages.

Parameters:
path - the path to the log file
Throws:
ConfigurationException - if the path is not writable

setPassword

public void setPassword(java.lang.String password)
Sets the component encryption password.

Parameters:
password - the encryption password

setPort

public void setPort(int port)
Set the port to bind to.

Parameters:
port - port number

setTrustedPath

public void setTrustedPath(java.lang.String path)
Set the trusted certificates to the contents of the directory given. The directory must be found in the classpath.

Parameters:
path - the trusted certificate directory path

createSocket

protected java.lang.Object createSocket(boolean serverSocket,
                                        java.lang.String host,
                                        int port)
                                 throws ConfigurationException,
                                        java.io.IOException
Creates and returns a socket with any appropriate authentication.

Parameters:
serverSocket - determines whether the return value is a Socket or a ServerSocket
host - the server host for client sockets; ignored for servers
port - the port to open (Server) or connect to (Clients)
Returns:
a new socket
Throws:
ConfigurationException - if a config attribute has a bad value
java.io.IOException - on socket creation failure

readCredentials

public void readCredentials()
                     throws ConfigurationException,
                            java.io.IOException
Read in the credentials using the paths to the credentials and passphrase.

Throws:
ConfigurationException - if problem finding credential properties
java.io.IOException - if problem reading credentials

readVersion

public static java.lang.String readVersion(java.lang.String versionFilename)
Read the version for the component from a file in the classpath.

Parameters:
versionFilename - The filename of the version file in the classpath
Returns:
A string containing the version read from file or "unknown" if not found.

openResourceStream

public static java.io.InputStream openResourceStream(java.lang.String resourcePath)
Returns an input stream for a resource found either in the classpath or on the file system. Returns null if the resource is not found.

Parameters:
resourcePath - the path (relative or absolute) to the resource
Returns:
an InputStream opened to the resource

configComponent

public static void configComponent(Component c,
                                   java.lang.String[] args,
                                   java.lang.String opts,
                                   java.lang.String prefix,
                                   java.lang.String exec,
                                   java.lang.String versionFilename)
                            throws ConfigurationException,
                                   java.io.IOException
A convenience function for configuring a Component (or descendent class) from the system properties, the arguments passed to main, and the properties file. Exits the program if parsing fails, or if the --help or --version arguments are included in args.

Parameters:
c - the component to configure
args - command-line arguments
opts - valid command-line options
prefix - property prefix from system props and property file
exec - main class name
versionFilename - classpath filename containing the version
Throws:
ConfigurationException - on faulty config properties
java.io.IOException - on an unreadable file property