net.geant.edugain.base
Class SecureConnection

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

public class SecureConnection
extends java.lang.Object

This class manages HTTP connections through secure SSL channels verified within the eduGAIN trust policies.

Author:
Jaime Perez

Field Summary
private  java.lang.StringBuffer buffer
           
private  Configurator cfg
           
private  javax.net.ssl.HttpsURLConnection connection
           
private  javax.net.ssl.SSLContext context
           
private  javax.net.ssl.SSLSocketFactory factory
           
private  java.security.KeyStore keystore
           
private  javax.net.ssl.KeyManagerFactory kmf
           
private  org.apache.log4j.Logger log
           
private  boolean opened
           
private  java.lang.String req_method
           
private  java.security.cert.X509Certificate srv_crt
           
private  javax.net.ssl.TrustManagerFactory tmf
           
private  java.security.KeyStore truststore
           
 
Constructor Summary
SecureConnection()
          Create a new instance of SecureConnection
SecureConnection(Configurator config)
          Create a new instance of SecureConnection
SecureConnection(java.security.KeyStore ks)
          Create a new instance of SecureConnection
SecureConnection(java.security.cert.X509Certificate[] chain)
          Create a new instance of SecureConnection
 
Method Summary
 java.lang.StringBuffer getContents()
          Get the contents of the response, if any.
private  void loadFactory()
           
 javax.net.ssl.HttpsURLConnection open(java.net.URL url)
          Open a new SSL connection, validating the server certificate.
 javax.net.ssl.HttpsURLConnection open(java.net.URL url, boolean validate)
          Open a new SSL connection specifying whether you want to validate server certificate or not.
 void setGet()
          Configure this connection as a HTTP GET request.
 void setPost()
          Configure this connection as a HTTP POST request.
 void setTrustPath(java.security.cert.X509Certificate[] chain)
          Set the trust path to use to validate server certificate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keystore

private java.security.KeyStore keystore

truststore

private java.security.KeyStore truststore

connection

private javax.net.ssl.HttpsURLConnection connection

factory

private javax.net.ssl.SSLSocketFactory factory

kmf

private javax.net.ssl.KeyManagerFactory kmf

tmf

private javax.net.ssl.TrustManagerFactory tmf

context

private javax.net.ssl.SSLContext context

cfg

private Configurator cfg

srv_crt

private java.security.cert.X509Certificate srv_crt

opened

private boolean opened

buffer

private java.lang.StringBuffer buffer

req_method

private java.lang.String req_method

log

private org.apache.log4j.Logger log
Constructor Detail

SecureConnection

public SecureConnection()
                 throws BaseException
Create a new instance of SecureConnection

Throws:
BaseException

SecureConnection

public SecureConnection(Configurator config)
                 throws BaseException
Create a new instance of SecureConnection

Parameters:
config - An eduGAIN Configurator instance.
Throws:
BaseException

SecureConnection

public SecureConnection(java.security.KeyStore ks)
                 throws BaseException
Create a new instance of SecureConnection

Parameters:
ks - A keystore to retrieve keys from.
Throws:
BaseException

SecureConnection

public SecureConnection(java.security.cert.X509Certificate[] chain)
                 throws BaseException
Create a new instance of SecureConnection

Parameters:
chain - The certificate chain to use as trust path.
Throws:
BaseException
Method Detail

loadFactory

private void loadFactory()
                  throws BaseException
Throws:
BaseException

setTrustPath

public void setTrustPath(java.security.cert.X509Certificate[] chain)
                  throws BaseException
Set the trust path to use to validate server certificate.

Parameters:
chain - The certificate chain to use as trust path.
Throws:
BaseException

setGet

public void setGet()
Configure this connection as a HTTP GET request.


setPost

public void setPost()
Configure this connection as a HTTP POST request.


open

public javax.net.ssl.HttpsURLConnection open(java.net.URL url)
                                      throws BaseException
Open a new SSL connection, validating the server certificate.

Parameters:
url - The URL to connect to.
Returns:
The connection to the appropiate server.
Throws:
BaseException

open

public javax.net.ssl.HttpsURLConnection open(java.net.URL url,
                                             boolean validate)
                                      throws BaseException
Open a new SSL connection specifying whether you want to validate server certificate or not.

Parameters:
url - The URL to connect to.
validate - Whether to validate server cert or not.
Returns:
The connection to the appropiate server.
Throws:
BaseException

getContents

public java.lang.StringBuffer getContents()
                                   throws BaseException
Get the contents of the response, if any.

Returns:
A string buffer with the contents of the response, or null.
Throws:
BaseException