edu.sdsc.inca
Class Component

java.lang.Object
  extended byedu.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.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  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.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.
 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.
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 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 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

keyPath

protected java.lang.String keyPath

logFile

protected java.lang.String logFile

password

protected java.lang.String password

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.

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

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

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; "key" the path to the component key; "logfile", the * path to the component log; "password", the encryption password; "trusted", the trusted cert directory.

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

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

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)
Throws:
ConfigurationException - if a config attribute has a bad value
java.io.IOException - on socket creation failure

readCredentials

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

Throws:
java.io.IOException

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