Obtain AADS Certificates

/* Example Program
     Obtain certificates from one or more AADS servers and save them to a 
     local disk file.

   Compile: javac -classpath sconfig.jar;jaas.jar;wcp.jar ObtainAADSCertificates.java

   Run: java -classpath sconfig.jar;jaas.jar;wcp.jar ObtainAADSCertificates <AADS1> [AADS2] ... [AADSn]
*/

import com.wrq.vhi.sconfig.*;

class ObtainAADSCertificates
{
	public static final String CERTFILE = "certificates.aads";

	static public void main(String [] args)
	{
		IAADSConnection aadsConn = ServerConfig.newAADSConnection();
		SCCertificate scc;

		if(args.length == 0) {
			System.out.println("Usage: ObtainAADSCertificates <AADS1> [AADS2] ... [AADSn]");
			return;
		}

		try {
			for(int i=0; i<args.length; i++) {

				/* Obtain a certificate directly from an AADS. */
				scc = aadsConn.getCertificateFromAADS( args[i] );
				System.out.println("Obtained certificate from AADS \"" + scc.getAADSName() + "\" -- " + scc.getFingerprint());

				/* Save the certificate in our local keystore */
				aadsConn.storeCertificate(scc);
			}

			/* Write the certificate(s) from our keystore, to a local disk file. */
			System.out.println("Writing certificate(s) to disk file \"" + CERTFILE + "\"...");
			aadsConn.saveKeystore( CERTFILE );
		}
		catch(Exception e) {
			System.err.println("Exception caught: " + e);
		}
	}
}