Changeset 709306c
- Timestamp:
- Mar 31, 2011 11:01:51 PM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master
- Children:
- 1294d29
- Parents:
- 9f8dbc1
- Location:
- axis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
axis/Create.java
r9f8dbc1 r709306c 1 // Java I/O 2 import java.io.*; 3 4 // The WSDL generated types for messages and components of messages. 1 5 import edu.isi.www.fedd_types.*; 2 6 import edu.isi.www.fedd_wsdl.*; 3 import java.net.URL;4 import net.deterlab.isi.XTrustProvider;5 import java.io.*;6 import java.util.*;7 7 8 // The fault thrown by failed commands 8 9 import org.apache.axis.AxisFault; 9 10 10 import javax.net.*; 11 import javax.net.ssl.*; 11 // The ABAC commands throw this 12 12 import java.security.GeneralSecurityException; 13 13 14 // ABAC classes. http://abac.deterlab.net 14 15 import net.deterlab.abac.*; 15 16 16 17 class Create extends FeddCommand { 17 18 19 /** 20 * Read a file into a byte array; used to load the topology file. 21 * @param f the File to read 22 * @throws IOException if there is an error reading the file. 23 */ 18 24 static public byte[] readNsFile(File f) throws IOException { 25 // This is tedious but straightforward 19 26 final int bsize = 4096; 20 27 byte[] buf = new byte[bsize]; … … 33 40 } 34 41 42 /** 43 * Create an ABAC credential indicating the the given destination acts for 44 * the given Identity, and attach a certificate to it. 45 * @param id the Identity delegating authority 46 * @param dest the destination 47 * @throws IOException an I/O problem, very unlikely 48 * @throws GeneralSecurityException crypto or identity misconfiguration. 49 */ 35 50 static public Credential delegate(Identity id, String dest) 36 51 throws IOException,GeneralSecurityException { … … 42 57 43 58 /** 44 * Dummy program to test an AXIS fedd implementation generated from the45 * WSDL and run by axis.46 * It just calls terminate with a dummy id as a local name (which can be47 * supplied on the command line and reprints the localname that the server48 * replies with. A client certificate muct exist in the local keystore49 * file with the given password.59 * Create an experiment with the given mnemonic name, from the given tcl 60 * topology file using the given identity certificate, on the given fedd. 61 * Reads the identity and topology into memory and constructs a New request 62 * for an empty experiment and a Create request to actually start it. The 63 * start is asynchronous, so this returns when the creation begins, not 64 * when it completes. 50 65 */ 51 66 public static void main(String args[]) throws 52 67 javax.xml.rpc.ServiceException, java.net.MalformedURLException, 53 68 java.rmi.RemoteException { 69 70 // Parse out the args 71 String exptName = "test"; 72 String tclFile = "./deter-only.tcl"; 73 String certFile = "./emulab.pem"; 74 String urlString = "https://users.isi.deterlab.net:23235"; 75 76 if (args.length > 0) exptName = args[0]; 77 if (args.length > 1) tclFile = args[1]; 78 if (args.length > 2) certFile = args[2]; 79 if (args.length > 3) urlString = args[3]; 54 80 55 81 /* 56 * Boilerplate web services access stuff.82 * Get the Web Service for users and read the identity and topology 57 83 */ 58 FeddPortType port = getPort( "https://users.isi.deterlab.net:23235");84 FeddPortType port = getPort(urlString); 59 85 Identity AbacID = null; 60 86 byte[] nsContents = null; 61 87 try { 62 88 nsContents = readNsFile(new File(args[1])); 89 AbacID = new Identity(new File("./emulab.pem")); 90 } 91 catch (GeneralSecurityException e) { 92 System.err.println("Error reading ABAC identity " + e); 93 System.exit(20); 63 94 } 64 95 catch (IOException e) { 65 System.err.println("Cannot read " + args[1] + ":" + e);96 System.err.println("Cannot load file " + e); 66 97 System.exit(20); 67 98 } 68 99 69 100 /* 70 * The various parts of the MultiInfo message and response101 * Build and send a NewRequestType Message 71 102 */ 72 103 73 104 NewRequestType newReq = new NewRequestType(null, 74 new IDType(null, null, null, args[0], null),105 new IDType(null, null, null, exptName, null), 75 106 null); 76 107 NewResponseType newResp = null; 77 78 79 108 try { 80 // Build the message and make the call81 109 newResp = port._new(newReq); 82 110 } 83 catch ( Exceptionf) {111 catch (AxisFault f) { 84 112 System.err.println("Error in New: " + f); 85 113 System.exit(20); 86 114 } 115 116 // Parse out the name of the new empty experiment, and start building 117 // the CreateRequestType message. 87 118 ExperimentLabels newLabels = 88 119 new ExperimentLabels(newResp.getExperimentID()); 89 System.out.println("New success: " + newLabels.getLocalname() + "(" +90 newLabels.getFedid() + ")");91 120 92 121 CreateRequestType createReq = new CreateRequestType(null, 93 122 new ExperimentDescriptionType(nsContents, null), 94 123 null, 95 //new IDType(null, null, null, newLabels.getLocalname(), null), 96 new IDType(null, null, null, args[0], null), 124 new IDType(null, null, null, newLabels.getLocalname(), null), 97 125 null); 98 126 CreateResponseType createResp = null; 127 128 // Reloading the port clears cached SSL connections. 99 129 port = getPort("https://users.isi.deterlab.net:23235"); 100 130 101 Credential c = null; 102 byte[][] ca = new byte[1][]; 131 // This block creates an ABAC credential telling the fedd that the 132 // experiment we brought to life with the New call above can act with 133 // our authority. We could keep the certificate around for other 134 // commands to use, but once we tell fedd about it, fedd remembers it. 103 135 try { 104 AbacID = new Identity(new File("./emulab.pem")); 136 Credential c = null; 137 byte[][] ca = new byte[1][]; 138 105 139 c = delegate(AbacID, newLabels.getFedid()); 106 140 ca[0] = c.cert().getEncoded(); 107 141 createReq.setCredential(ca); 108 System.err.println(AbacID);109 System.err.println(c);110 142 } 111 catch (GeneralSecurityException e) { System.err.println(e); } 112 catch (IOException e) { System.err.println("IOException?!!" +e); } 143 catch (GeneralSecurityException e) { 144 System.err.println("Failed to delegate authority: " + e); 145 System.exit(20); 146 } 147 catch (IOException e) { 148 System.err.println("Failed to delegate authority: ?!!" +e); 149 System.exit(20); 150 } 113 151 152 // The create call 114 153 try { 115 /* Build the message and make the call */116 154 createResp = port.create(createReq); 117 155 } 118 156 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 157 System.err.println("Error in Create: " + f); 126 158 System.exit(20); 127 159 } 160 161 // Tell the user we're underway 128 162 ExperimentLabels createLabels = 129 163 new ExperimentLabels(createResp.getExperimentID()); 130 System.out.println(" New success: " + createLabels.getLocalname()131 + " (" + createLabels.getFedid() + ") "164 System.out.println("Success: " + createLabels.getLocalname() 165 + " (" + createLabels.getFedid() + ") " 132 166 + createResp.getExperimentStatus().getValue()); 133 167 } -
axis/FeddCommand.java
r9f8dbc1 r709306c 1 // WSDL generated types and port 1 2 import edu.isi.www.fedd_types.*; 2 3 import edu.isi.www.fedd_wsdl.*; 4 5 // The usual suspects 3 6 import java.net.*; 4 7 import java.util.*; 5 8 6 import net.deterlab.isi.XTrustProvider; 7 import net.deterlab.isi. Fedid;9 // The Fedid and XTrustManager classes 10 import net.deterlab.isi.*; 8 11 12 // SSL manipulations and a couple Exceptions 9 13 import javax.net.ssl.*; 14 import javax.xml.rpc.*; 10 15 16 /** 17 * Base class that all the example programs are derived from. It holds 18 * routines that several classes use, including some key routines to massage 19 * java's security model closer to fedd's. 20 */ 11 21 public class FeddCommand { 12 22 23 // SetUpSecurity is defined below. This is necessary stuff, and putting it 24 // here guarantees that it's always called before main. 13 25 static { setUpSecurity(); } 14 26 27 /** 28 * Parse out an experiment name from a return value. Several fedd 29 * responses identify the experiment that was operated on (or created) by 30 * both a human-readable name and a fedid. This class scans through the 31 * array of IDTypes returned and keeps the fedid and localname (mnemonic 32 * name) returned. 33 */ 15 34 static class ExperimentLabels { 35 /** The fedid */ 16 36 protected String fedid; 37 /** The localname */ 17 38 protected String localname; 18 39 40 /** 41 * Construct the class - i.e., parse the array 42 * @param experimentID an array of IDTypes holding the synonymous names 43 */ 19 44 public ExperimentLabels(IDType[] experimentID) { 20 45 fedid = null; … … 34 59 } 35 60 } 61 /** 62 * Return the fedid 63 * @return the fedid 64 */ 36 65 String getFedid() { return fedid; } 66 /** 67 * Return the localname 68 * @return the localname 69 */ 37 70 String getLocalname() { return localname; } 38 71 } 39 72 73 /** 74 * This magic convinces the SSL routines to accept self-signed certificates 75 * from the server (fedd) and points the SSL routines at the local 76 * keystore. Other applications may move the keystore assignment, but the 77 * XTrustProvider call is always necessary. 78 */ 40 79 public static void setUpSecurity() { 41 80 /* This magic turns off certificate chain checking. */ … … 52 91 } 53 92 93 /** 94 * Clear the SSL session cache. Java aggressively reuses SSL sessions, and 95 * it confuses fedd greatly - connections drop. This routine invalidates 96 * all the existing sessions. Necessary when you will make more than one 97 * call. This is also called by getPort, so getting a new port before each 98 * new call will also atomize the sessions. 99 */ 54 100 static public void clearSSLSessionCache() { 55 101 try { … … 60 106 SSLSession s = ssctxt.getSession(e.nextElement()); 61 107 s.invalidate(); 62 System.err.println("invalidated " + s);63 108 } 64 109 } … … 66 111 } 67 112 68 public static FeddPortType getPort(String server) throws 69 javax.xml.rpc.ServiceException, java.net.MalformedURLException { 113 /** 114 * Get a new FeddPortType on which requests can be made. The server to 115 * contact is passed as a string. 116 * @param server a String containing the server URL 117 * @return a FeddPortType to talk to. 118 * @throws ServiceException if the services/server can't be found 119 * @throws MalformedURLException if the URL is bad 120 */ 121 public static FeddPortType getPort(String server) 122 throws ServiceException, MalformedURLException { 70 123 /* 71 124 * Boilerplate web services access stuff. -
axis/MultiStatus.java
r9f8dbc1 r709306c 1 // WSDL generated classes 1 2 import edu.isi.www.fedd_types.*; 2 3 import edu.isi.www.fedd_wsdl.*; 3 import java.net.URL; 4 import net.deterlab.isi.XTrustProvider; 5 import net.deterlab.isi.Fedid;4 5 // The fault thrown by failed commands 6 import org.apache.axis.AxisFault; 6 7 7 8 class MultiStatus extends FeddCommand { 8 9 9 10 /** 10 * Dummy program to test an AXIS fedd implementation generated from the 11 * WSDL and run by axis. 12 * It just calls terminate with a dummy id as a local name (which can be 13 * supplied on the command line and reprints the localname that the server 14 * replies with. A client certificate muct exist in the local keystore 15 * file with the given password. 11 * Get the list of active experiments created by this user. The list has 12 * the same format as fedd_multistatus.py - name:fedid:state. If no 13 * experiments are active, a line to that effect is printed. 16 14 */ 17 15 public static void main(String args[]) throws … … 20 18 21 19 FeddPortType port = getPort("https://users.isi.deterlab.net:23235"); 22 /*23 * The various parts of the MultiInfo message and response24 */25 26 20 MultiInfoRequestType req = new MultiInfoRequestType(); 27 21 MultiInfoResponseType resp = null; 28 22 23 // Make the call: the request is basically empty 29 24 try { 30 /* Build the message and make the call */31 25 resp = port.multiInfo(req); 32 26 } 33 catch ( Exceptione) {34 System.out.println( e);35 System.exit( 0);27 catch (AxisFault e) { 28 System.out.println("Request failed: " + e); 29 System.exit(20); 36 30 } 31 32 // Parse out the response and print the lines. 37 33 if (resp.getInfo() != null) { 38 34 for (InfoResponseType info: resp.getInfo()) { -
axis/Terminate.java
r9f8dbc1 r709306c 1 // WSDL generated classes 1 2 import edu.isi.www.fedd_types.*; 2 3 import edu.isi.www.fedd_wsdl.*; 3 import java.net.URL; 4 import net.deterlab.isi.XTrustProvider; 4 5 // The fault thrown by failed commands 6 import org.apache.axis.AxisFault; 5 7 6 8 class Terminate extends FeddCommand { 7 9 /** 8 * Dummy program to test an AXIS fedd implementation generated from the 9 * WSDL and run by axis. 10 * It just calls terminate with a dummy id as a local name (which can be 11 * supplied on the command line and reprints the localname that the server 12 * replies with. A client certificate muct exist in the local keystore 13 * file with the given password. 10 * Terminate the experiment with the menmonic name given on the command 11 * line. 14 12 */ 15 13 public static void main(String args[]) throws 16 14 javax.xml.rpc.ServiceException, java.net.MalformedURLException, 17 15 java.rmi.RemoteException { 18 19 /* 20 * Boilerplate web services access stuff. 21 */ 16 17 // Get the port and construct the (simple) request. 22 18 FeddPortType port = getPort("https://users.isi.deterlab.net:23235"); 23 setUpSecurity();24 25 /*26 * The various parts of the Terminate message and response27 */28 29 19 TerminateRequestType req = new TerminateRequestType( 30 20 new IDType(null, null, null, args[0], null), … … 37 27 resp = port.terminate(req); 38 28 } 39 catch ( FaultTypef) {29 catch (AxisFault f) { 40 30 System.err.println("Error in Terminate: " + f); 41 31 System.exit(20);
Note: See TracChangeset
for help on using the changeset viewer.