net.geant.edugain.base
Class Configurator

java.lang.Object
  extended by net.geant.edugain.base.Configurator

public final class Configurator
extends java.lang.Object

This class is used to globally configure eduGAIN and the underlaying OpenSAML libraries. If you are using eduGAIN libraries, commonly the configurator will get instanced by validation classes, but you may want to get your own instance.

Author:
Jose Manuel Macias, Jaime Perez

Nested Class Summary
protected  class Configurator.LoggerFilter
          LoggerFilter extension to filter class names.
 
Field Summary
protected  java.util.ArrayList<java.lang.String> components
           
protected  org.opensaml.SAMLConfig config
           
protected  java.security.cert.X509CRL crl
           
protected  java.lang.Integer crl_timeout
           
protected  java.util.Calendar crl_tmstamp
           
static java.lang.String DEFAULT_CONFIG_FILE
           
static java.lang.String DEFAULT_CRL_TIMEOUT
           
static java.lang.String DEFAULT_LOG_FILTER
           
static org.opensaml.common.SAMLVersion DEFAULT_SAML_VERSION
           
protected  java.security.Key key
           
protected  java.security.KeyStore keystore
           
protected  org.apache.log4j.Logger log
           
protected  java.util.Properties properties
           
static java.lang.String PROPS_BE_TEMPLATE
           
static java.lang.String PROPS_CANONICALIZATION_ALG
           
static java.lang.String PROPS_CERT_CHAIN_ALIAS
           
static java.lang.String PROPS_CONFIG_FILE
           
static java.lang.String PROPS_CRL_TIMEOUT
           
static java.lang.String PROPS_CRL_URL
           
static java.lang.String PROPS_DIGEST_ALG
           
static java.lang.String PROPS_KEYSTORE_FILE
           
static java.lang.String PROPS_KEYSTORE_PASSWD
           
static java.lang.String PROPS_LOG_LOGGER_FILTER
           
static java.lang.String PROPS_MDS_URL
           
static java.lang.String PROPS_PRIV_KEY_ALIAS
           
static java.lang.String PROPS_PRIV_KEY_PASSWD
           
static java.lang.String PROPS_SAML_VERSION
           
static java.lang.String PROPS_SIGNATURE_ALG
           
static java.lang.String PROPS_STRICT_MODE
           
static java.lang.String PROPS_TRUSTSTORE_FILE
           
static java.lang.String PROPS_TRUSTSTORE_PASSWD
           
static java.lang.String PROPS_VALID_COMPONENTS
           
protected static Configurator ref
           
protected  java.security.KeyStore truststore
           
protected  org.opensaml.common.SAMLVersion version
           
 
Constructor Summary
protected Configurator(java.util.Properties props)
          Create a new instance of Configurator, wrapping eduGAIN properties into OpenSAML properties.
 
Method Summary
 java.lang.Object clone()
          This class is not clonable...
 java.security.cert.X509CRL getCRL()
          Get a CRL with the full list of revocated certs.
 java.security.cert.X509CRL getCRL(java.lang.String url)
          Get a CRL with the full list of revocated certs.
 java.lang.Integer getCRLTimeout()
          Get the CRL timeout.
static Configurator getInstance()
          Get a running instance of the configuration or instantiate a new one.
static Configurator getInstance(java.io.InputStream stream)
          Get a running instance of the configuration or instantiate a new one.
static Configurator getInstance(java.util.Properties props)
          Instantiate a new configurator with the specified properties.
static Configurator getInstance(java.lang.String path)
          Get a running instance of the configuration or instantiate a new one.
static Configurator getInstance(java.net.URL url)
          Get a running instance of the configuration or instantiate a new one.
 java.security.Key getPrivateKey()
          Get the keystore.
private  java.security.Key getPrivateKey(boolean force)
          Force get the key from the keystore.
 java.util.Properties getProperties()
          This method returns the properties stored in the current configuration.
 java.lang.String getProperty(java.lang.String property)
          This method returns the value of a property, if set.
 java.lang.String getProperty(java.lang.String property, java.lang.String value)
          This method returns the value of a property if set, or a default value if not.
 java.util.ArrayList<java.lang.String> getValidComponents()
          Get the current valid components list.
 org.opensaml.common.SAMLVersion getVersion()
          Get the currently configured SAML version to use.
 java.security.KeyStore loadKeyStore()
          Load the default keystore.
private  java.security.KeyStore loadKeyStore(java.lang.String path, java.lang.String password)
          Load a KeyStore.
private  java.security.KeyStore loadKeyStore(java.net.URL url, java.lang.String password)
          Load a KeyStore.
protected static java.util.Properties loadProperties(java.io.InputStream inStream)
          Load a set of configuration properties.
 java.security.KeyStore loadTrustStore()
          Load the default truststore.
 boolean overrideCRL()
          Determine whether user has overrided the CRL by configuration or not.
protected  void setLoggerFilter()
          Set some eduGAIN custom log filters.
 void setValidComponents(java.util.ArrayList<java.lang.String> list)
          Set the list of valid components used in any eduGAIN validation procedure.
 void setVersion(java.lang.String v)
          Set the SAML version to use within the library.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPS_CONFIG_FILE

public static java.lang.String PROPS_CONFIG_FILE

PROPS_SAML_VERSION

public static java.lang.String PROPS_SAML_VERSION

PROPS_LOG_LOGGER_FILTER

public static java.lang.String PROPS_LOG_LOGGER_FILTER

PROPS_CRL_URL

public static java.lang.String PROPS_CRL_URL

PROPS_CRL_TIMEOUT

public static java.lang.String PROPS_CRL_TIMEOUT

PROPS_VALID_COMPONENTS

public static java.lang.String PROPS_VALID_COMPONENTS

PROPS_PRIV_KEY_ALIAS

public static java.lang.String PROPS_PRIV_KEY_ALIAS

PROPS_PRIV_KEY_PASSWD

public static java.lang.String PROPS_PRIV_KEY_PASSWD

PROPS_CERT_CHAIN_ALIAS

public static java.lang.String PROPS_CERT_CHAIN_ALIAS

PROPS_SIGNATURE_ALG

public static java.lang.String PROPS_SIGNATURE_ALG

PROPS_DIGEST_ALG

public static java.lang.String PROPS_DIGEST_ALG

PROPS_CANONICALIZATION_ALG

public static java.lang.String PROPS_CANONICALIZATION_ALG

PROPS_MDS_URL

public static java.lang.String PROPS_MDS_URL

PROPS_STRICT_MODE

public static java.lang.String PROPS_STRICT_MODE

PROPS_BE_TEMPLATE

public static java.lang.String PROPS_BE_TEMPLATE

PROPS_KEYSTORE_FILE

public static java.lang.String PROPS_KEYSTORE_FILE

PROPS_KEYSTORE_PASSWD

public static java.lang.String PROPS_KEYSTORE_PASSWD

PROPS_TRUSTSTORE_FILE

public static java.lang.String PROPS_TRUSTSTORE_FILE

PROPS_TRUSTSTORE_PASSWD

public static java.lang.String PROPS_TRUSTSTORE_PASSWD

DEFAULT_CRL_TIMEOUT

public static java.lang.String DEFAULT_CRL_TIMEOUT

DEFAULT_CONFIG_FILE

public static java.lang.String DEFAULT_CONFIG_FILE

DEFAULT_LOG_FILTER

public static java.lang.String DEFAULT_LOG_FILTER

DEFAULT_SAML_VERSION

public static org.opensaml.common.SAMLVersion DEFAULT_SAML_VERSION

properties

protected java.util.Properties properties

ref

protected static Configurator ref

config

protected org.opensaml.SAMLConfig config

components

protected java.util.ArrayList<java.lang.String> components

crl

protected java.security.cert.X509CRL crl

crl_tmstamp

protected java.util.Calendar crl_tmstamp

crl_timeout

protected java.lang.Integer crl_timeout

version

protected org.opensaml.common.SAMLVersion version

log

protected org.apache.log4j.Logger log

keystore

protected java.security.KeyStore keystore

truststore

protected java.security.KeyStore truststore

key

protected java.security.Key key
Constructor Detail

Configurator

protected Configurator(java.util.Properties props)
                throws BaseException
Create a new instance of Configurator, wrapping eduGAIN properties into OpenSAML properties.

Parameters:
props - The properties to use.
Throws:
BaseException
Method Detail

getInstance

public static Configurator getInstance()
Get a running instance of the configuration or instantiate a new one.

Returns:
A reference to the current configuration.

getInstance

public static Configurator getInstance(java.util.Properties props)
Instantiate a new configurator with the specified properties.

Parameters:
props - The properties object representing a new eduGAIN configuration.
Returns:
A reference to the current configuration.

getInstance

public static Configurator getInstance(java.lang.String path)
Get a running instance of the configuration or instantiate a new one.

Parameters:
path - The path of a file containing a set of properties.
Returns:
A reference to the current configuration.

getInstance

public static Configurator getInstance(java.io.InputStream stream)
Get a running instance of the configuration or instantiate a new one.

Parameters:
stream - An InputStream pointing to a set of properties.
Returns:
A reference to the current configuration.

getInstance

public static Configurator getInstance(java.net.URL url)
Get a running instance of the configuration or instantiate a new one.

Parameters:
url - An URL pointing to a set of properties.
Returns:
A reference to the current configuration.

getProperties

public java.util.Properties getProperties()
This method returns the properties stored in the current configuration.

Returns:
The current properties.

getProperty

public java.lang.String getProperty(java.lang.String property)
This method returns the value of a property, if set.

Parameters:
property - The name of the property.
Returns:
The value of the property.

getProperty

public java.lang.String getProperty(java.lang.String property,
                                    java.lang.String value)
This method returns the value of a property if set, or a default value if not.

Parameters:
property - The name of the property.
value - The default value of the property.
Returns:
The value of the property.

setVersion

public void setVersion(java.lang.String v)
Set the SAML version to use within the library.

Parameters:
v - A string defining the version of SAML to use.

getVersion

public org.opensaml.common.SAMLVersion getVersion()
Get the currently configured SAML version to use.

Returns:
The SAML version.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
This class is not clonable...

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

loadProperties

protected static java.util.Properties loadProperties(java.io.InputStream inStream)
                                              throws java.io.IOException
Load a set of configuration properties.

Throws:
java.io.IOException

loadKeyStore

private java.security.KeyStore loadKeyStore(java.lang.String path,
                                            java.lang.String password)
                                     throws BaseException
Load a KeyStore.

Parameters:
path - The path to the keystore.
password - The password for the provided keystore.
Returns:
The keystore.
Throws:
BaseException - Thrown if an error occurs while loading the keystore.

loadKeyStore

private java.security.KeyStore loadKeyStore(java.net.URL url,
                                            java.lang.String password)
                                     throws BaseException
Load a KeyStore.

Parameters:
url - The URL to the keystore.
password - The password for the provided keystore.
Returns:
The keystore.
Throws:
BaseException - Thrown if an error occurs while loading the keystore.

loadKeyStore

public java.security.KeyStore loadKeyStore()
                                    throws BaseException
Load the default keystore.

Returns:
The eduGAIN keystore.
Throws:
BaseException - Thrown if an error occurs while loading the keystore.

loadTrustStore

public java.security.KeyStore loadTrustStore()
                                      throws BaseException
Load the default truststore.

Returns:
The eduGAIN truststore.
Throws:
BaseException - Thrown if an error occurs while loading the truststore.

setValidComponents

public void setValidComponents(java.util.ArrayList<java.lang.String> list)
Set the list of valid components used in any eduGAIN validation procedure.

Parameters:
list - The list of valid components to use.

getValidComponents

public java.util.ArrayList<java.lang.String> getValidComponents()
                                                         throws BaseException
Get the current valid components list. If empty, then the default list will be loaded from file. This is intended only for development! In the future this method will be replaced by some automatic mechanism to fetch dinamically a full list of valid components from the eduGAIN registry.

Returns:
Trusted eduGAIN component identifiers.
Throws:
BaseException - Thrown if an error occurs while loading the valid component identifiers file.

getCRL

public java.security.cert.X509CRL getCRL(java.lang.String url)
                                  throws BaseException
Get a CRL with the full list of revocated certs. Please be aware that this method doesn't check if a CRL is expired at all!

Parameters:
url - The URL where the CRL is located.
Returns:
An up to date CRL.
Throws:
BaseException - Thrown if an error occurs while loading the CRL.

getCRL

public java.security.cert.X509CRL getCRL()
                                  throws BaseException
Get a CRL with the full list of revocated certs.

Returns:
An up to date CRL.
Throws:
BaseException - Thrown if an error occurs while loading the CRL.

overrideCRL

public boolean overrideCRL()
Determine whether user has overrided the CRL by configuration or not.

Returns:
True if overrided, false in any other case.

getCRLTimeout

public java.lang.Integer getCRLTimeout()
Get the CRL timeout.

Returns:
The configured CRL timeout. If no one was configured, return the default one.

getPrivateKey

private java.security.Key getPrivateKey(boolean force)
                                 throws BaseException
Force get the key from the keystore.

Parameters:
force - Whether to force fetch the key from the keystore or not.
Returns:
The key from the keystore.
Throws:
BaseException

getPrivateKey

public java.security.Key getPrivateKey()
                                throws BaseException
Get the keystore.

Returns:
The keystore with eduGAIN cryptographic material.
Throws:
BaseException

setLoggerFilter

protected void setLoggerFilter()
Set some eduGAIN custom log filters.