Changeset 709306c for axis


Ignore:
Timestamp:
Mar 31, 2011 11:01:51 PM (9 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
1294d29
Parents:
9f8dbc1
Message:

Commented and working.

Location:
axis
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • axis/Create.java

    r9f8dbc1 r709306c  
     1// Java I/O
     2import java.io.*;
     3
     4// The WSDL generated types for messages and components of messages.
    15import edu.isi.www.fedd_types.*;
    26import edu.isi.www.fedd_wsdl.*;
    3 import java.net.URL;
    4 import net.deterlab.isi.XTrustProvider;
    5 import java.io.*;
    6 import java.util.*;
    77
     8// The fault thrown by failed commands
    89import org.apache.axis.AxisFault;
    910
    10 import javax.net.*;
    11 import javax.net.ssl.*;
     11// The ABAC commands throw this
    1212import java.security.GeneralSecurityException;
    1313
     14// ABAC classes.  http://abac.deterlab.net
    1415import net.deterlab.abac.*;
    1516
    1617class Create extends FeddCommand {
    1718
     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     */
    1824    static public byte[] readNsFile(File f) throws IOException {
     25        // This is tedious but straightforward
    1926        final int bsize = 4096;
    2027        byte[] buf = new byte[bsize];
     
    3340    }
    3441
     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     */
    3550    static public Credential delegate(Identity id, String dest)
    3651            throws IOException,GeneralSecurityException {
     
    4257
    4358    /**
    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.
     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.
    5065     */
    5166    public static void main(String args[]) throws
    5267            javax.xml.rpc.ServiceException, java.net.MalformedURLException,
    5368            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];
    5480       
    5581        /*
    56          * Boilerplate web services access stuff.
     82         * Get the Web Service for users and read the identity and topology
    5783         */
    58         FeddPortType port = getPort("https://users.isi.deterlab.net:23235");
     84        FeddPortType port = getPort(urlString);
    5985        Identity AbacID = null;
    6086        byte[] nsContents = null;
    6187        try {
    6288            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);
    6394        }
    6495        catch (IOException e) {
    65             System.err.println("Cannot read " + args[1] + ": " + e);
     96            System.err.println("Cannot load file " + e);
    6697            System.exit(20);
    6798        }
    6899
    69100        /*
    70          * The various parts of the MultiInfo message and response
     101         * Build and send a NewRequestType Message
    71102         */
    72103
    73104        NewRequestType newReq = new NewRequestType(null,
    74                 new IDType(null, null, null, args[0], null),
     105                new IDType(null, null, null, exptName, null),
    75106                null);
    76107        NewResponseType newResp = null;
    77 
    78 
    79108        try {
    80             // Build the message and make the call
    81109            newResp = port._new(newReq);
    82110        }
    83         catch (Exception f) {
     111        catch (AxisFault f) {
    84112            System.err.println("Error in New: " + f);
    85113            System.exit(20);
    86114        }
     115
     116        // Parse out the name of the new empty experiment, and start building
     117        // the CreateRequestType message.
    87118        ExperimentLabels newLabels =
    88119            new ExperimentLabels(newResp.getExperimentID());
    89         System.out.println("New success: " + newLabels.getLocalname() + "(" +
    90             newLabels.getFedid() + ")");
    91120
    92121        CreateRequestType createReq = new CreateRequestType(null,
    93122                new ExperimentDescriptionType(nsContents, null),
    94123                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),
    97125                null);
    98126        CreateResponseType createResp = null;
     127
     128        // Reloading the port clears cached SSL connections.
    99129        port = getPort("https://users.isi.deterlab.net:23235");
    100130
    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.
    103135        try {
    104             AbacID = new Identity(new File("./emulab.pem"));
     136            Credential c = null;
     137            byte[][] ca = new byte[1][];
     138
    105139            c = delegate(AbacID, newLabels.getFedid());
    106140            ca[0] = c.cert().getEncoded();
    107141            createReq.setCredential(ca);
    108             System.err.println(AbacID);
    109             System.err.println(c);
    110142        }
    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        }
    113151
     152        // The create call
    114153        try {
    115             /* Build the message and make the call */
    116154            createResp = port.create(createReq);
    117155        }
    118156        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());
    125157            System.err.println("Error in Create: " + f);
    126158            System.exit(20);
    127159        }
     160
     161        // Tell the user we're underway
    128162        ExperimentLabels createLabels =
    129163            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() + ") "
    132166                + createResp.getExperimentStatus().getValue());
    133167    }
  • axis/FeddCommand.java

    r9f8dbc1 r709306c  
     1// WSDL generated types and port
    12import edu.isi.www.fedd_types.*;
    23import edu.isi.www.fedd_wsdl.*;
     4
     5// The usual suspects
    36import java.net.*;
    47import java.util.*;
    58
    6 import net.deterlab.isi.XTrustProvider;
    7 import net.deterlab.isi.Fedid;
     9// The Fedid and XTrustManager classes
     10import net.deterlab.isi.*;
    811
     12// SSL manipulations and a couple Exceptions
    913import javax.net.ssl.*;
     14import javax.xml.rpc.*;
    1015
     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 */
    1121public class FeddCommand {
    1222
     23    // SetUpSecurity is defined below. This is necessary stuff, and putting it
     24    // here guarantees that it's always called before main.
    1325    static { setUpSecurity(); }
    1426
     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     */
    1534    static class ExperimentLabels {
     35        /** The fedid */
    1636        protected String fedid;
     37        /** The localname */
    1738        protected String localname;
    1839
     40        /**
     41         * Construct the class - i.e., parse the array
     42         * @param experimentID an array of IDTypes holding the synonymous names
     43         */
    1944        public ExperimentLabels(IDType[] experimentID) {
    2045            fedid = null;
     
    3459            }
    3560        }
     61        /**
     62         * Return the fedid
     63         * @return the fedid
     64         */
    3665        String getFedid() { return fedid; }
     66        /**
     67         * Return the localname
     68         * @return the localname
     69         */
    3770        String getLocalname() { return localname; }
    3871    }
    3972
     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     */
    4079    public static void setUpSecurity() {
    4180        /* This magic turns off certificate chain checking. */
     
    5291    }
    5392
     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     */
    54100    static public void clearSSLSessionCache() {
    55101        try {
     
    60106                SSLSession s = ssctxt.getSession(e.nextElement());
    61107                s.invalidate();
    62                 System.err.println("invalidated " + s);
    63108            }
    64109        }
     
    66111    }
    67112
    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 {
    70123        /*
    71124         * Boilerplate web services access stuff.
  • axis/MultiStatus.java

    r9f8dbc1 r709306c  
     1// WSDL generated classes
    12import edu.isi.www.fedd_types.*;
    23import 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
     6import org.apache.axis.AxisFault;
    67
    78class MultiStatus extends FeddCommand {
    89
    910    /**
    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.
    1614     */
    1715    public static void main(String args[]) throws
     
    2018       
    2119        FeddPortType port = getPort("https://users.isi.deterlab.net:23235");
    22         /*
    23          * The various parts of the MultiInfo message and response
    24          */
    25 
    2620        MultiInfoRequestType req = new MultiInfoRequestType();
    2721        MultiInfoResponseType resp = null;
    2822
     23        // Make the call: the request is basically empty
    2924        try {
    30             /* Build the message and make the call */
    3125            resp = port.multiInfo(req);
    3226        }
    33         catch (Exception e) {
    34             System.out.println(e);
    35             System.exit(0);
     27        catch (AxisFault e) {
     28            System.out.println("Request failed: " + e);
     29            System.exit(20);
    3630        }
     31
     32        // Parse out the response and print the lines.
    3733        if (resp.getInfo() != null) {
    3834            for (InfoResponseType info: resp.getInfo()) {
  • axis/Terminate.java

    r9f8dbc1 r709306c  
     1// WSDL generated classes
    12import edu.isi.www.fedd_types.*;
    23import edu.isi.www.fedd_wsdl.*;
    3 import java.net.URL;
    4 import net.deterlab.isi.XTrustProvider;
     4
     5// The fault thrown by failed commands
     6import org.apache.axis.AxisFault;
    57
    68class Terminate extends FeddCommand {
    79    /**
    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.
    1412     */
    1513    public static void main(String args[]) throws
    1614            javax.xml.rpc.ServiceException, java.net.MalformedURLException,
    1715            java.rmi.RemoteException {
    18        
    19         /*
    20          * Boilerplate web services access stuff.
    21          */
     16
     17        // Get the port and construct the (simple) request.
    2218        FeddPortType port = getPort("https://users.isi.deterlab.net:23235");
    23         setUpSecurity();
    24 
    25         /*
    26          * The various parts of the Terminate message and response
    27          */
    28 
    2919        TerminateRequestType req = new TerminateRequestType(
    3020                new IDType(null, null, null, args[0], null),
     
    3727            resp = port.terminate(req);
    3828        }
    39         catch (FaultType f) {
     29        catch (AxisFault f) {
    4030            System.err.println("Error in Terminate: " + f);
    4131            System.exit(20);
Note: See TracChangeset for help on using the changeset viewer.