import edu.isi.www.fedd_types.*; import edu.isi.www.fedd_wsdl.*; import java.net.URL; import net.deterlab.isi.XTrustProvider; import java.io.*; import java.util.*; import org.apache.axis.AxisFault; import javax.net.*; import javax.net.ssl.*; import java.security.GeneralSecurityException; import net.deterlab.abac.*; class Create extends FeddCommand { static public byte[] readNsFile(File f) throws IOException { final int bsize = 4096; byte[] buf = new byte[bsize]; byte[] rv = new byte[0]; int r = 0; FileInputStream fs = new FileInputStream(f); while ((r = fs.read(buf)) != -1 ) { byte[] newRv = new byte[rv.length + r]; System.arraycopy(rv, 0, newRv, 0, rv.length); System.arraycopy(buf, 0, newRv, rv.length, r); rv = newRv; } fs.close(); return rv; } static public Credential delegate(Identity id, String dest) throws IOException,GeneralSecurityException { Credential c = new Credential(new Role(id.getKeyID()+".acting_for"), new Role(dest)); c.make_cert(id); return c; } /** * Dummy program to test an AXIS fedd implementation generated from the * WSDL and run by axis. * It just calls terminate with a dummy id as a local name (which can be * supplied on the command line and reprints the localname that the server * replies with. A client certificate muct exist in the local keystore * file with the given password. */ public static void main(String args[]) throws javax.xml.rpc.ServiceException, java.net.MalformedURLException, java.rmi.RemoteException { /* * Boilerplate web services access stuff. */ FeddPortType port = getPort("https://users.isi.deterlab.net:23235"); Identity AbacID = null; byte[] nsContents = null; try { nsContents = readNsFile(new File(args[1])); } catch (IOException e) { System.err.println("Cannot read " + args[1] + ": " + e); System.exit(20); } /* * The various parts of the MultiInfo message and response */ NewRequestType newReq = new NewRequestType(null, new IDType(null, null, null, args[0], null), null); NewResponseType newResp = null; try { // Build the message and make the call newResp = port._new(newReq); } catch (Exception f) { System.err.println("Error in New: " + f); System.exit(20); } ExperimentLabels newLabels = new ExperimentLabels(newResp.getExperimentID()); System.out.println("New success: " + newLabels.getLocalname() + "(" + newLabels.getFedid() + ")"); CreateRequestType createReq = new CreateRequestType(null, new ExperimentDescriptionType(nsContents, null), null, //new IDType(null, null, null, newLabels.getLocalname(), null), new IDType(null, null, null, args[0], null), null); CreateResponseType createResp = null; port = getPort("https://users.isi.deterlab.net:23235"); Credential c = null; byte[][] ca = new byte[1][]; try { AbacID = new Identity(new File("./emulab.pem")); c = delegate(AbacID, newLabels.getFedid()); ca[0] = c.cert().getEncoded(); createReq.setCredential(ca); System.err.println(AbacID); System.err.println(c); } catch (GeneralSecurityException e) { System.err.println(e); } catch (IOException e) { System.err.println("IOException?!!" +e); } try { /* Build the message and make the call */ createResp = port.create(createReq); } catch (AxisFault f) { System.err.println(f.getClass().getName()); System.err.println("AxisFault Error in Create: " + f); System.exit(20); } catch (Exception f) { System.err.println(f.getClass().getName()); System.err.println("Error in Create: " + f); System.exit(20); } ExperimentLabels createLabels = new ExperimentLabels(createResp.getExperimentID()); System.out.println("New success: " + createLabels.getLocalname() + "(" + createLabels.getFedid() + ") " + createResp.getExperimentStatus().getValue()); } }