[55de6a9] | 1 | import edu.isi.www.fedd_types.*; |
---|
| 2 | import edu.isi.www.fedd_wsdl.*; |
---|
| 3 | import java.net.URL; |
---|
| 4 | import net.deterlab.isi.XTrustProvider; |
---|
[10f5e84] | 5 | import java.io.*; |
---|
| 6 | import java.util.*; |
---|
| 7 | |
---|
| 8 | import org.apache.axis.AxisFault; |
---|
| 9 | |
---|
| 10 | import javax.net.*; |
---|
| 11 | import javax.net.ssl.*; |
---|
| 12 | import java.security.GeneralSecurityException; |
---|
| 13 | |
---|
| 14 | import net.deterlab.abac.*; |
---|
[55de6a9] | 15 | |
---|
| 16 | class Create extends FeddCommand { |
---|
[10f5e84] | 17 | |
---|
| 18 | static public byte[] readNsFile(File f) throws IOException { |
---|
| 19 | final int bsize = 4096; |
---|
| 20 | byte[] buf = new byte[bsize]; |
---|
| 21 | byte[] rv = new byte[0]; |
---|
| 22 | int r = 0; |
---|
| 23 | FileInputStream fs = new FileInputStream(f); |
---|
| 24 | |
---|
| 25 | while ((r = fs.read(buf)) != -1 ) { |
---|
| 26 | byte[] newRv = new byte[rv.length + r]; |
---|
| 27 | System.arraycopy(rv, 0, newRv, 0, rv.length); |
---|
| 28 | System.arraycopy(buf, 0, newRv, rv.length, r); |
---|
| 29 | rv = newRv; |
---|
| 30 | } |
---|
| 31 | fs.close(); |
---|
| 32 | return rv; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | static public Credential delegate(Identity id, String dest) |
---|
| 36 | throws IOException,GeneralSecurityException { |
---|
| 37 | Credential c = new Credential(new Role(id.getKeyID()+".acting_for"), |
---|
| 38 | new Role(dest)); |
---|
| 39 | c.make_cert(id); |
---|
| 40 | return c; |
---|
| 41 | } |
---|
| 42 | |
---|
[55de6a9] | 43 | /** |
---|
| 44 | * Dummy program to test an AXIS fedd implementation generated from the |
---|
| 45 | * WSDL and run by axis. |
---|
| 46 | * It just calls terminate with a dummy id as a local name (which can be |
---|
| 47 | * supplied on the command line and reprints the localname that the server |
---|
| 48 | * replies with. A client certificate muct exist in the local keystore |
---|
| 49 | * file with the given password. |
---|
| 50 | */ |
---|
| 51 | public static void main(String args[]) throws |
---|
| 52 | javax.xml.rpc.ServiceException, java.net.MalformedURLException, |
---|
| 53 | java.rmi.RemoteException { |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | * Boilerplate web services access stuff. |
---|
| 57 | */ |
---|
| 58 | FeddPortType port = getPort("https://users.isi.deterlab.net:23235"); |
---|
[10f5e84] | 59 | Identity AbacID = null; |
---|
| 60 | byte[] nsContents = null; |
---|
| 61 | try { |
---|
| 62 | nsContents = readNsFile(new File(args[1])); |
---|
| 63 | } |
---|
| 64 | catch (IOException e) { |
---|
| 65 | System.err.println("Cannot read " + args[1] + ": " + e); |
---|
| 66 | System.exit(20); |
---|
| 67 | } |
---|
[55de6a9] | 68 | |
---|
| 69 | /* |
---|
| 70 | * The various parts of the MultiInfo message and response |
---|
| 71 | */ |
---|
| 72 | |
---|
[10f5e84] | 73 | NewRequestType newReq = new NewRequestType(null, |
---|
[55de6a9] | 74 | new IDType(null, null, null, args[0], null), |
---|
| 75 | null); |
---|
[10f5e84] | 76 | NewResponseType newResp = null; |
---|
[55de6a9] | 77 | |
---|
| 78 | |
---|
| 79 | try { |
---|
[10f5e84] | 80 | // Build the message and make the call |
---|
| 81 | newResp = port._new(newReq); |
---|
[55de6a9] | 82 | } |
---|
[10f5e84] | 83 | catch (Exception f) { |
---|
[55de6a9] | 84 | System.err.println("Error in New: " + f); |
---|
| 85 | System.exit(20); |
---|
| 86 | } |
---|
| 87 | ExperimentLabels newLabels = |
---|
[10f5e84] | 88 | new ExperimentLabels(newResp.getExperimentID()); |
---|
[55de6a9] | 89 | System.out.println("New success: " + newLabels.getLocalname() + "(" + |
---|
| 90 | newLabels.getFedid() + ")"); |
---|
[10f5e84] | 91 | |
---|
| 92 | CreateRequestType createReq = new CreateRequestType(null, |
---|
| 93 | new ExperimentDescriptionType(nsContents, null), |
---|
| 94 | null, |
---|
| 95 | //new IDType(null, null, null, newLabels.getLocalname(), null), |
---|
| 96 | new IDType(null, null, null, args[0], null), |
---|
| 97 | null); |
---|
| 98 | CreateResponseType createResp = null; |
---|
| 99 | port = getPort("https://users.isi.deterlab.net:23235"); |
---|
| 100 | |
---|
| 101 | Credential c = null; |
---|
| 102 | byte[][] ca = new byte[1][]; |
---|
| 103 | try { |
---|
| 104 | AbacID = new Identity(new File("./emulab.pem")); |
---|
| 105 | c = delegate(AbacID, newLabels.getFedid()); |
---|
| 106 | ca[0] = c.cert().getEncoded(); |
---|
| 107 | createReq.setCredential(ca); |
---|
| 108 | System.err.println(AbacID); |
---|
| 109 | System.err.println(c); |
---|
| 110 | } |
---|
| 111 | catch (GeneralSecurityException e) { System.err.println(e); } |
---|
| 112 | catch (IOException e) { System.err.println("IOException?!!" +e); } |
---|
| 113 | |
---|
| 114 | try { |
---|
| 115 | /* Build the message and make the call */ |
---|
| 116 | createResp = port.create(createReq); |
---|
| 117 | } |
---|
| 118 | catch (AxisFault f) { |
---|
| 119 | System.err.println(f.getClass().getName()); |
---|
| 120 | System.err.println("AxisFault Error in Create: " + f); |
---|
| 121 | System.exit(20); |
---|
| 122 | } |
---|
| 123 | catch (Exception f) { |
---|
| 124 | System.err.println(f.getClass().getName()); |
---|
| 125 | System.err.println("Error in Create: " + f); |
---|
| 126 | System.exit(20); |
---|
| 127 | } |
---|
| 128 | ExperimentLabels createLabels = |
---|
| 129 | new ExperimentLabels(createResp.getExperimentID()); |
---|
| 130 | System.out.println("New success: " + createLabels.getLocalname() |
---|
| 131 | + "(" + createLabels.getFedid() + ") " |
---|
| 132 | + createResp.getExperimentStatus().getValue()); |
---|
[55de6a9] | 133 | } |
---|
| 134 | } |
---|