perfsonar-dev - perfsonar: r2451 - in branches/as/src/org/perfsonar/service: commons/authn commons/authn/tokens testHarness testHarness/authService
Subject: perfsonar development work
List archive
perfsonar: r2451 - in branches/as/src/org/perfsonar/service: commons/authn commons/authn/tokens testHarness testHarness/authService
Chronological Thread
- From:
- To:
- Subject: perfsonar: r2451 - in branches/as/src/org/perfsonar/service: commons/authn commons/authn/tokens testHarness testHarness/authService
- Date: Tue, 5 Jun 2007 05:24:43 -0400
Author: rodriguez
Date: 2007-06-05 05:24:43 -0400 (Tue, 05 Jun 2007)
New Revision: 2451
Added:
branches/as/src/org/perfsonar/service/testHarness/authService/
branches/as/src/org/perfsonar/service/testHarness/authService/AuthNRequestTest.java
Modified:
branches/as/src/org/perfsonar/service/commons/authn/AADispatchSOAPProtocol.java
branches/as/src/org/perfsonar/service/commons/authn/AuthNResponse.java
branches/as/src/org/perfsonar/service/commons/authn/tokens/SecTokenSOAPManager.java
Log:
Updating the code... now, the library for service developers can reach the
AS. Also, added a new test
Modified:
branches/as/src/org/perfsonar/service/commons/authn/AADispatchSOAPProtocol.java
===================================================================
---
branches/as/src/org/perfsonar/service/commons/authn/AADispatchSOAPProtocol.java
2007-06-04 13:47:35 UTC (rev 2450)
+++
branches/as/src/org/perfsonar/service/commons/authn/AADispatchSOAPProtocol.java
2007-06-05 09:24:43 UTC (rev 2451)
@@ -1,7 +1,6 @@
package org.perfsonar.service.commons.authn;
import java.io.File;
-import java.io.FileWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.Iterator;
@@ -15,10 +14,10 @@
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPEnvelope;
-import org.apache.axis.message.SOAPHeader;
import org.apache.axis.utils.XMLUtils;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
+import org.ggf.ns.nmwg.base.v2_0.Message;
import org.perfsonar.commons.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.commons.auxiliary.ComponentNames;
import
org.perfsonar.commons.auxiliary.components.configuration.ConfigurationComponent;
@@ -29,22 +28,24 @@
public class AADispatchSOAPProtocol implements AADispatchProtocol {
private final String AS_POINT_PARAM = "service.as.point";
private final String FILE_AUTHN_PARAM = "service.as.authnRequest";
+ private final String SAX_PARSER_CONFIG = "service.sax_parser.config";
private LoggerComponent logger;
private ConfigurationComponent config;
private String asPoint;
private String fileAuthnRequest;
+ private String saxParser;
public AADispatchSOAPProtocol() throws SystemException {
try {
logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ .getComponent(ComponentNames.LOGGER);
} catch (SystemException e) {
String m = "AADispatchSOAPProtocol: Can't obtain
Logger component ";
throw new SystemException(m);
}
try {
config = (ConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ .getInstance().getComponent(ComponentNames.CONFIG);
} catch (SystemException e) {
String m = "AADispatchSOAPProtocol: Can't obtain
Config component ";
@@ -54,6 +55,7 @@
try {
asPoint=config.getProperty(AS_POINT_PARAM);
fileAuthnRequest=config.getProperty(FILE_AUTHN_PARAM);
+ saxParser=config.getProperty(SAX_PARSER_CONFIG);
} catch (Exception e) {
String m = "AADispatchSOAPProtocol: Can't obtain
required parameters ";
logger.error(m);
@@ -61,86 +63,93 @@
}
}
+ public AADispatchSOAPProtocol(String asPoint, String
fileAuthnRequest, String saxParser) throws SystemException {
+ try {
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
+ .getComponent(ComponentNames.LOGGER);
+ } catch (SystemException e) {
+ String m = "AADispatchSOAPProtocol: Can't obtain
Logger component ";
+ throw new SystemException(m);
+ }
+ this.asPoint=asPoint;
+ this.fileAuthnRequest=fileAuthnRequest;
+ this.saxParser=saxParser;
+ }
+
public AuthNResponse getAuthentication(AuthNRequest req) {
- // TODO Make a real response
- // prepare to call - set service elements
+ AuthNResponse resp=new AuthNResponse();
+ StringWriter outWriter = null;
+ // prepare to call - set service elements
try {
- Service service = new Service();
- Call call = (Call)service.createCall();
- call.setTargetEndpointAddress(new URL(asPoint));
- call.setOperationName(new QName("http://soapinterop.org/","submit"));
+ Service service = new Service();
+ Call call = (Call)service.createCall();
+ call.setTargetEndpointAddress(new URL(asPoint));
+ call.setOperationName(new
QName("http://soapinterop.org/","submit"));
- // read the request into a org.w3c.DOM.Document
- Document request = null;
- DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
+ // read the request into a org.w3c.DOM.Document
+ Document request = null;
+ DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- request = builder.parse(new File(fileAuthnRequest));
+ DocumentBuilder builder =
factory.newDocumentBuilder();
+ request = builder.parse(new File(fileAuthnRequest));
- // build a SOAPBodyElement from the document
- SOAPBodyElement requestMessage =
- new SOAPBodyElement(request.getDocumentElement());
- SOAPEnvelope envelope = new SOAPEnvelope();
- envelope.addBodyElement(requestMessage);
- SOAPHeader header=(SOAPHeader)req.getSecurityToken().getSecToken();
- envelope.setHeader(header);
+ // build a SOAPBodyElement from the document
+ SOAPBodyElement requestMessage =
+ new
SOAPBodyElement(request.getDocumentElement());
+ SOAPEnvelope envelope = new SOAPEnvelope();
+ envelope.addBodyElement(requestMessage);
+ javax.xml.soap.SOAPHeader
header=(javax.xml.soap.SOAPHeader)req.getSecurityToken().getSecToken();
+ Iterator it=header.examineAllHeaderElements();
+ while (it.hasNext()) {
+ SOAPHeaderElement
he=(SOAPHeaderElement)it.next();
+ envelope.getHeader().addChildElement(he);
+ }
- StringWriter sw=new StringWriter();
- XMLUtils.PrettyElementToWriter(requestMessage.getAsDOM(),sw);
- logger.debug("---------- Request: ");
- logger.debug(sw.toString());
- // get a timestamp.
- double startTime =
- new Long(System.currentTimeMillis()).doubleValue();
+ StringWriter sw=new StringWriter();
+
XMLUtils.PrettyElementToWriter(requestMessage.getAsDOM(),sw);
- // call on the end point
- Object resultObject = call.invoke(envelope);
+ // call on the end point
+ Object resultObject = call.invoke(envelope);
- // get another timestamp
- double endTime =
- new Long(System.currentTimeMillis()).doubleValue();
+ SOAPEnvelope envelopeResult;
+ SOAPBodyElement resultSBE;
+ Document result = null;
- SOAPEnvelope envelopeResult;
- SOAPBodyElement resultSBE;
- Document result = null;
+ envelopeResult= (SOAPEnvelope)resultObject;
+ resultSBE= envelopeResult.getFirstBody();
- envelopeResult= (SOAPEnvelope)resultObject;
- resultSBE= envelopeResult.getFirstBody();
+ // change it to document - here is where validity
+ // can be checked..
+ result = resultSBE.getAsDocument();
- // change it to document - here is where validity
- // can be checked..
- result = resultSBE.getAsDocument();
+ // output it to a string
+ outWriter = new StringWriter();
- // output it to a file
- StringWriter outWriter = new StringWriter();
+ OutputFormat format = new OutputFormat( result );
+ format.setIndent(4);
+ format.setIndenting(true);
+ format.setLineSeparator("\n");
- OutputFormat format = new OutputFormat( result );
- format.setIndent(4);
- format.setIndenting(true);
- format.setLineSeparator("\n");
+ XMLSerializer serial = new XMLSerializer(outWriter,
format );
+ serial.asDOMSerializer();
+ serial.serialize( result.getDocumentElement() );
- XMLSerializer serial = new XMLSerializer(outWriter, format );
- serial.asDOMSerializer();
- serial.serialize( result.getDocumentElement() );
+ outWriter.close();
- outWriter.close();
- logger.debug("---------- Response: ");
- logger.debug(outWriter.toString());
- } catch (ClassCastException e) {
- e.printStackTrace();
- System.out.println("SOAPX509Client.makeRequest: We didn't get a
Vector of SOAPBodyElements!");
- } catch (Exception e) {
- System.out.println("SOAPX509Client.makeRequest: General
exception while retrieving report");
- e.printStackTrace();
- }
+ Message responseNmwg =
org.perfsonar.commons.util.XMLUtils.convertToMessage(
+ result, saxParser);
-
- AuthNResponse resp=new AuthNResponse();
-// if (!isAuthorized)
-// resp.setStatus(AuthNResponse.NOT_AUTHORIZED);
-// else
- resp.setStatus(AuthNResponse.AUTHORIZED);
+ resp=AuthNResponse.getAuthNResponse(responseNmwg);
+
+ } catch (ClassCastException e) {
+ e.printStackTrace();
+
System.out.println("AADispatchSOAPProtocol.getAuthentication: We didn't get a
Vector of SOAPBodyElements!");
+ } catch (Exception e) {
+
System.out.println("AADispatchSOAPProtocol.getAuthentication: General
exception while retrieving report");
+ e.printStackTrace();
+ }
+
return resp;
}
Modified:
branches/as/src/org/perfsonar/service/commons/authn/AuthNResponse.java
===================================================================
--- branches/as/src/org/perfsonar/service/commons/authn/AuthNResponse.java
2007-06-04 13:47:35 UTC (rev 2450)
+++ branches/as/src/org/perfsonar/service/commons/authn/AuthNResponse.java
2007-06-05 09:24:43 UTC (rev 2451)
@@ -1,12 +1,19 @@
package org.perfsonar.service.commons.authn;
+import org.ggf.ns.nmwg.base.v2_0.EventType;
+import org.ggf.ns.nmwg.base.v2_0.Message;
+import org.ggf.ns.nmwg.base.v2_0.Metadata;
+
public class AuthNResponse {
public static final int AUTHORIZED=0;
public static final int NOT_AUTHORIZED=1;
private int status;
+ private String codeResult;
+
public AuthNResponse() {
status=AuthNResponse.NOT_AUTHORIZED;
+ codeResult="";
}
public int getStatus() {
@@ -17,4 +24,29 @@
this.status = status;
}
+ public String getCodeResult() {
+ return codeResult;
+ }
+
+ public void setCodeResult(String codeResult) {
+ this.codeResult = codeResult;
+ }
+
+ public static AuthNResponse getAuthNResponse(Message message) {
+ AuthNResponse res=new AuthNResponse();
+
+ Metadata[] metadatas=message.getMetadataArray();
+ for (int i=0; i<metadatas.length; i++) {
+ EventType et=metadatas[i].getEventType();
+ res.setCodeResult(et.getEventType());
+ if (et.getEventType().equals("success.as.authn")) {
+ res.setStatus(AuthNResponse.AUTHORIZED);
+ }
+ else {
+ res.setStatus(AuthNResponse.NOT_AUTHORIZED);
+ }
+ }
+
+ return res;
+ }
}
Modified:
branches/as/src/org/perfsonar/service/commons/authn/tokens/SecTokenSOAPManager.java
===================================================================
---
branches/as/src/org/perfsonar/service/commons/authn/tokens/SecTokenSOAPManager.java
2007-06-04 13:47:35 UTC (rev 2450)
+++
branches/as/src/org/perfsonar/service/commons/authn/tokens/SecTokenSOAPManager.java
2007-06-05 09:24:43 UTC (rev 2451)
@@ -11,6 +11,7 @@
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
+import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.message.SOAPHeader;
import org.apache.ws.security.WSSecurityEngine;
@@ -44,7 +45,8 @@
return null;
MessageContext mc=MessageContext.getCurrentContext();
try {
- SOAPHeader
sh=(SOAPHeader)mc.getCurrentMessage().getSOAPHeader();
+ Message m=mc.getCurrentMessage();
+ SOAPHeader sh=(SOAPHeader)m.getSOAPHeader();
return sh;
} catch (SOAPException e) {
String m = "Error getting the SOAP header";
Added:
branches/as/src/org/perfsonar/service/testHarness/authService/AuthNRequestTest.java
- perfsonar: r2451 - in branches/as/src/org/perfsonar/service: commons/authn commons/authn/tokens testHarness testHarness/authService, svnlog, 06/05/2007
Archive powered by MHonArc 2.6.16.