Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r2474 - in trunk/perfsonar/src/org/perfsonar/client: commons commons/authn testHarness

Subject: perfsonar development work

List archive

perfsonar: r2474 - in trunk/perfsonar/src/org/perfsonar/client: commons commons/authn testHarness


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r2474 - in trunk/perfsonar/src/org/perfsonar/client: commons commons/authn testHarness
  • Date: Mon, 18 Jun 2007 06:39:25 -0400

Author: rodriguez
Date: 2007-06-18 06:39:24 -0400 (Mon, 18 Jun 2007)
New Revision: 2474

Added:
trunk/perfsonar/src/org/perfsonar/client/commons/authn/
trunk/perfsonar/src/org/perfsonar/client/commons/authn/AuthNData.java

trunk/perfsonar/src/org/perfsonar/client/commons/authn/AuthNDataFactory.java
trunk/perfsonar/src/org/perfsonar/client/commons/authn/WSSAuthNData.java
Modified:
trunk/perfsonar/src/org/perfsonar/client/testHarness/SOAPX509Client.java
Log:
Added the authn library for automated client developers. Also, the
'SOAPX509Client' test class is updated for using that library

Added: trunk/perfsonar/src/org/perfsonar/client/commons/authn/AuthNData.java

Added:
trunk/perfsonar/src/org/perfsonar/client/commons/authn/AuthNDataFactory.java

Added:
trunk/perfsonar/src/org/perfsonar/client/commons/authn/WSSAuthNData.java

Modified:
trunk/perfsonar/src/org/perfsonar/client/testHarness/SOAPX509Client.java
===================================================================
--- trunk/perfsonar/src/org/perfsonar/client/testHarness/SOAPX509Client.java
2007-06-14 12:56:09 UTC (rev 2473)
+++ trunk/perfsonar/src/org/perfsonar/client/testHarness/SOAPX509Client.java
2007-06-18 10:39:24 UTC (rev 2474)
@@ -1,47 +1,24 @@
package org.perfsonar.client.testHarness;

-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
import java.io.FileWriter;
-import java.io.InputStream;
import java.net.URL;
-import java.security.Key;
-import java.security.KeyFactory;
-import java.security.KeyStore;
-import java.security.PrivateKey;
-import java.security.Provider;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.util.Vector;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

-import org.apache.axis.Message;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.utils.XMLUtils;
-import org.apache.ws.security.SOAPConstants;
-import org.apache.ws.security.WSConstants;
-import org.apache.ws.security.WSEncryptionPart;
-import org.apache.ws.security.components.crypto.Crypto;
-import org.apache.ws.security.message.WSSecHeader;
-import org.apache.ws.security.message.WSSecSignature;
-import org.apache.ws.security.util.Base64;
-import org.apache.ws.security.util.WSSecurityUtil;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.w3c.dom.Document;

-import org.perfsonar.commons.auxiliary.components.authn.DynamicCrypto;
-import org.perfsonar.commons.auxiliary.components.authn.SOAPUtil;
+import org.perfsonar.client.commons.authn.AuthNData;
+import org.perfsonar.client.commons.authn.AuthNDataFactory;

/**
* Class which provides the basic web service (Doc/Lit) client capability
@@ -77,16 +54,15 @@
System.out.println("Private key file: " + keyFile);
System.out.println("Certificate file: " + certFile);

- // read the certificate... more or less...
- InputStream isCert=new FileInputStream(certFile);
-
- // prepare to call - set service elements
+ // prepare to call - set service elements
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL(endPoint));
call.setOperationName(new
QName("http://soapinterop.org/","submit";));

- // read the request into a org.w3c.DOM.Document
+
+ // read the request into a org.w3c.DOM.Document
+
Document request = null;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
@@ -94,79 +70,34 @@
DocumentBuilder builder = factory.newDocumentBuilder();
request = builder.parse(new File(inputFile));

+
// build a SOAPBodyElement from the document
- SOAPBodyElement requestMessage =
+
+ SOAPBodyElement requestMessage =
new SOAPBodyElement(request.getDocumentElement());
- SOAPEnvelope envelope = new SOAPEnvelope();
- envelope.addBodyElement(requestMessage);

- // add the security provider
- BouncyCastleProvider bcp = new BouncyCastleProvider();
- java.security.Security.addProvider((Provider)bcp);
+ AuthNData authnData=AuthNDataFactory.getDefaultAuthNData();
+ Object reqRaw=authnData.addX509STInMessage(requestMessage,
keyFile, certFile);
+ SOAPEnvelope envelope=(SOAPEnvelope)reqRaw;

- // add the private and public keys
- Crypto crypto = new DynamicCrypto();
- KeyStore ks=crypto.getKeyStore();
-
- BufferedReader in = new BufferedReader(new FileReader(keyFile));
- String str;
- String previousStr="";
- String data="";
- in.readLine();
- while ((str = in.readLine()) != null) {
- data+=previousStr;
- previousStr=str+"\n";
- }
- in.close();
-
- byte[] bytes=Base64.decode(data);
- PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes);
- KeyFactory keyFactory = KeyFactory.getInstance("RSA");
- PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
- X509Certificate cert=crypto.loadCertificate(isCert);
- ks.setKeyEntry("xmlsec", (Key)privateKey,
"security".toCharArray(), new Certificate[]{(Certificate)cert});
-
- WSSecSignature sec509 = new WSSecSignature();
- sec509.setUserInfo("xmlsec", "security");
- SOAPConstants soapConstants =
WSSecurityUtil.getSOAPConstants(envelope.getAsDOM());
- Vector<WSEncryptionPart> parts = new
Vector<WSEncryptionPart>(1,1);
-
- // Set up to use STRTransorm to sign the signature token
- WSEncryptionPart encP =
- new WSEncryptionPart(
- "STRTransform",
- soapConstants.getEnvelopeURI(),
- "Content");
- parts.add(encP);
-
- sec509.setParts(parts);
- sec509.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
- Document doc = envelope.getAsDocument();
- WSSecHeader secHeader = new WSSecHeader();
- secHeader.setActor("test");
- secHeader.insertSecurityHeader(doc);
-
- // Signing the message
- Document signedDoc = sec509.build(doc, crypto, secHeader);
-
- Message signedMsg = (Message) SOAPUtil.toSOAPMessage(signedDoc);
- envelope = signedMsg.getSOAPEnvelope();
-
// Saving SOAP message
saveSOAPMessage(envelope.getAsDocument(), inputFile);

// get a timestamp.
- double startTime =
+ double startTime =
new Long(System.currentTimeMillis()).doubleValue();

- // call on the end point
+ // call on the end point
+
Object resultObject = call.invoke(envelope);

// get another timestamp
- double endTime =
+ double endTime =
new Long(System.currentTimeMillis()).doubleValue();

+ // result object is a vector - strange!!! But this is how the
world works :-D
+ // we will now extract the result from the vector
+
SOAPEnvelope envelopeResult;
SOAPBodyElement resultSBE;
Document result = null;



  • perfsonar: r2474 - in trunk/perfsonar/src/org/perfsonar/client: commons commons/authn testHarness, svnlog, 06/18/2007

Archive powered by MHonArc 2.6.16.

Top of Page