Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r2468 - in branches/as/src/org/perfsonar: client/commons client/commons/authn client/testHarness commons/auxiliary/components/authn/wssec service/testHarness/authService

Subject: perfsonar development work

List archive

perfsonar: r2468 - in branches/as/src/org/perfsonar: client/commons client/commons/authn client/testHarness commons/auxiliary/components/authn/wssec service/testHarness/authService


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r2468 - in branches/as/src/org/perfsonar: client/commons client/commons/authn client/testHarness commons/auxiliary/components/authn/wssec service/testHarness/authService
  • Date: Tue, 12 Jun 2007 07:23:00 -0400

Author: rodriguez
Date: 2007-06-12 07:23:00 -0400 (Tue, 12 Jun 2007)
New Revision: 2468

Added:
branches/as/src/org/perfsonar/client/commons/authn/
branches/as/src/org/perfsonar/client/commons/authn/AuthNData.java
branches/as/src/org/perfsonar/client/commons/authn/AuthNDataFactory.java
branches/as/src/org/perfsonar/client/commons/authn/WSSAuthNData.java
Modified:
branches/as/src/org/perfsonar/client/testHarness/SOAPX509Client.java

branches/as/src/org/perfsonar/commons/auxiliary/components/authn/wssec/WSSecAuthNComponent.java

branches/as/src/org/perfsonar/service/testHarness/authService/AuthNRequestTest.java
Log:
Updating the code... now, there is a set of classes for automated client
developers

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

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

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

Modified: branches/as/src/org/perfsonar/client/testHarness/SOAPX509Client.java
===================================================================
--- branches/as/src/org/perfsonar/client/testHarness/SOAPX509Client.java
2007-06-11 10:17:57 UTC (rev 2467)
+++ branches/as/src/org/perfsonar/client/testHarness/SOAPX509Client.java
2007-06-12 11:23:00 UTC (rev 2468)
@@ -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;

Modified:
branches/as/src/org/perfsonar/commons/auxiliary/components/authn/wssec/WSSecAuthNComponent.java
===================================================================
---
branches/as/src/org/perfsonar/commons/auxiliary/components/authn/wssec/WSSecAuthNComponent.java
2007-06-11 10:17:57 UTC (rev 2467)
+++
branches/as/src/org/perfsonar/commons/auxiliary/components/authn/wssec/WSSecAuthNComponent.java
2007-06-12 11:23:00 UTC (rev 2468)
@@ -51,7 +51,6 @@
}
}
} catch (Exception e) {
- e.printStackTrace();
checkAuthN=false;
}
}

Modified:
branches/as/src/org/perfsonar/service/testHarness/authService/AuthNRequestTest.java
===================================================================
---
branches/as/src/org/perfsonar/service/testHarness/authService/AuthNRequestTest.java
2007-06-11 10:17:57 UTC (rev 2467)
+++
branches/as/src/org/perfsonar/service/testHarness/authService/AuthNRequestTest.java
2007-06-12 11:23:00 UTC (rev 2468)
@@ -1,22 +1,9 @@
package org.perfsonar.service.testHarness.authService;

-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.InputStream;
import java.io.StringWriter;
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.Iterator;
-import java.util.Vector;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
@@ -28,20 +15,11 @@
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.ggf.ns.nmwg.base.v2_0.Message;
-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;
import org.perfsonar.service.commons.authn.AADispatchManager;
import org.perfsonar.service.commons.authn.AADispatchProtocol;
import org.perfsonar.service.commons.authn.AuthNRequest;
@@ -78,9 +56,6 @@
System.out.println("Certificate file: " + certFile);
System.out.println("SAX parser: " + saxParser);

- // read the certificate... more or less...
- InputStream isCert=new FileInputStream(certFile);
-
// read the request into a org.w3c.DOM.Document
Document request = null;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
@@ -92,62 +67,11 @@
// build a SOAPBodyElement from the document
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 data=AuthNDataFactory.getDefaultAuthNData();
+ Object newRequest=data.addX509STInMessage(requestMessage,
keyFile, certFile);
+ SOAPEnvelope envelope = (SOAPEnvelope)newRequest;

- // 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);
-
- org.apache.axis.Message signedMsg = (org.apache.axis.Message)
SOAPUtil.toSOAPMessage(signedDoc);
- envelope = signedMsg.getSOAPEnvelope();
-
try {

SecurityToken st=new SecurityToken(new SecTokenRawManager());
@@ -158,10 +82,10 @@
AADispatchManager aadm=new AADispatchManager(new
AADispatchBasicSOAPProtocol(endPoint,inputFile,saxParser));
AuthNResponse authnRes=aadm.getAuthentication(authnReq);
if (authnRes.getStatus()==AuthNResponse.AUTHENTICATED) {
- System.out.println("Result: AUTHORIZED!");
+ System.out.println("Result: AUTHENTICATED!");
}
else {
- System.out.println("Result: NOT AUTHORIZED!");

+ System.out.println("Result: NOT AUTHENTICATED!");

}
System.out.println("Code Result: "+authnRes.getResultCode());




  • perfsonar: r2468 - in branches/as/src/org/perfsonar: client/commons client/commons/authn client/testHarness commons/auxiliary/components/authn/wssec service/testHarness/authService, svnlog, 06/12/2007

Archive powered by MHonArc 2.6.16.

Top of Page