Changeset 10f5e84


Ignore:
Timestamp:
Mar 31, 2011 10:07:29 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
9f8dbc1
Parents:
56baf92
Message:

Create works!

Location:
axis
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • axis/Create.java

    r56baf92 r10f5e84  
    33import java.net.URL;
    44import net.deterlab.isi.XTrustProvider;
     5import java.io.*;
     6import java.util.*;
     7
     8import org.apache.axis.AxisFault;
     9
     10import javax.net.*;
     11import javax.net.ssl.*;
     12import java.security.GeneralSecurityException;
     13
     14import net.deterlab.abac.*;
    515
    616class Create extends FeddCommand {
     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
    743    /**
    844     * Dummy program to test an AXIS fedd implementation generated from the
     
    2157         */
    2258        FeddPortType port = getPort("https://users.isi.deterlab.net:23235");
    23         setUpSecurity();
     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        }
    2468
    2569        /*
     
    2771         */
    2872
    29         NewResponseType resp = null;
    30 
    31         /* This magic turns off certificate chain checking. */
    32         XTrustProvider.install();
    33 
    34         /* This tells the SSL system where to find client certificate
    35          * information. */
    36         String keyStore = "./keystore";
    37         String keyStorePassword = "importkey";
    38 
    39         System.setProperty("javax.net.ssl.keyStore", keyStore);
    40         System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
    41         IDType id = new IDType();
    42 
    43         NewRequestType req = new NewRequestType(null,
     73        NewRequestType newReq = new NewRequestType(null,
    4474                new IDType(null, null, null, args[0], null),
    4575                null);
     76        NewResponseType newResp = null;
    4677
    4778
    4879        try {
    49             /* Build the message and make the call */
    50             resp = port._new(req);
     80            // Build the message and make the call
     81            newResp = port._new(newReq);
    5182        }
    52         catch (FaultType f) {
     83        catch (Exception f) {
    5384            System.err.println("Error in New: " + f);
    5485            System.exit(20);
    5586        }
    5687        ExperimentLabels newLabels =
    57             new ExperimentLabels(resp.getExperimentID());
     88            new ExperimentLabels(newResp.getExperimentID());
    5889        System.out.println("New success: " + newLabels.getLocalname() + "(" +
    5990            newLabels.getFedid() + ")");
     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());
    60133    }
    61134}
  • axis/FeddCommand.java

    r56baf92 r10f5e84  
    11import edu.isi.www.fedd_types.*;
    22import edu.isi.www.fedd_wsdl.*;
    3 import java.net.URL;
     3import java.net.*;
     4import java.util.*;
     5
    46import net.deterlab.isi.XTrustProvider;
    57import net.deterlab.isi.Fedid;
    68
    7 class FeddCommand {
     9import javax.net.ssl.*;
     10
     11public class FeddCommand {
     12
     13    static { setUpSecurity(); }
    814
    915    static class ExperimentLabels {
     
    4349        System.setProperty("javax.net.ssl.keyStore", keyStore);
    4450        System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
     51
     52    }
     53
     54    static public void clearSSLSessionCache() {
     55        try {
     56            SSLContext sctxt = SSLContext.getDefault();
     57            SSLSessionContext ssctxt = sctxt.getClientSessionContext();
     58            Enumeration<byte[]> e = ssctxt.getIds();
     59            while (e.hasMoreElements()) {
     60                SSLSession s = ssctxt.getSession(e.nextElement());
     61                s.invalidate();
     62                System.err.println("invalidated " + s);
     63            }
     64        }
     65        catch (Exception e) { System.err.println(e); }
    4566    }
    4667
     
    5071         * Boilerplate web services access stuff.
    5172         */
     73        clearSSLSessionCache();
    5274        FeddServiceLocator service = new FeddServiceLocator();
    5375        FeddPortType port = service.getfeddPort(new URL(server));
  • axis/MultiStatus.java

    r56baf92 r10f5e84  
    2020       
    2121        FeddPortType port = getPort("https://users.isi.deterlab.net:23235");
    22         setUpSecurity();
    2322        /*
    2423         * The various parts of the MultiInfo message and response
     
    3231            resp = port.multiInfo(req);
    3332        }
    34         catch (FaultType e) {
     33        catch (Exception e) {
    3534            System.out.println(e);
    3635            System.exit(0);
Note: See TracChangeset for help on using the changeset viewer.