Author: anil.saldhana(a)jboss.com
Date: 2009-07-29 18:51:15 -0400 (Wed, 29 Jul 2009)
New Revision: 667
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/request/SAML2Request.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/response/SAML2Response.java
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/saml/v2/SignatureValidationUnitTestCase.java
Log:
JBID-149: get binder
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/request/SAML2Request.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/request/SAML2Request.java 2009-07-29
22:46:04 UTC (rev 666)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/request/SAML2Request.java 2009-07-29
22:51:15 UTC (rev 667)
@@ -95,6 +95,17 @@
}
/**
+ * Get the Binder
+ * @return
+ * @throws JAXBException
+ */
+ public Binder<Node> getBinder() throws JAXBException
+ {
+ JAXBContext jaxb = JAXBContext.newInstance(RequestAbstractType.class);
+ return jaxb.createBinder();
+ }
+
+ /**
* Get a Request Type from Input Stream
* @param is
* @return
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/response/SAML2Response.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/response/SAML2Response.java 2009-07-29
22:46:04 UTC (rev 666)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/response/SAML2Response.java 2009-07-29
22:51:15 UTC (rev 667)
@@ -237,6 +237,17 @@
}
/**
+ * Get the Binder
+ * @return
+ * @throws JAXBException
+ */
+ public Binder<Node> getBinder() throws JAXBException
+ {
+ JAXBContext jaxb = JAXBContext.newInstance(ResponseType.class);
+ return jaxb.createBinder();
+ }
+
+ /**
* Convert a SAML2 Response into a Document
* @param responseType
* @return
@@ -247,7 +258,7 @@
{
JAXBContext jaxb = JAXBContext.newInstance(ResponseType.class);
Binder<Node> binder = jaxb.createBinder();
-
+
Document doc = DocumentUtil.createDocument();
binder.marshal(JAXBElementMappingUtil.get(responseType), doc);
return doc;
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/saml/v2/SignatureValidationUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/saml/v2/SignatureValidationUnitTestCase.java 2009-07-29
22:46:04 UTC (rev 666)
+++
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/saml/v2/SignatureValidationUnitTestCase.java 2009-07-29
22:51:15 UTC (rev 667)
@@ -28,6 +28,8 @@
import java.security.KeyPair;
import java.security.KeyPairGenerator;
+import javax.xml.bind.Binder;
+import javax.xml.bind.JAXBElement;
import javax.xml.crypto.dsig.SignatureMethod;
import org.jboss.identity.federation.api.saml.v2.common.IDGenerator;
@@ -124,6 +126,7 @@
assertTrue(isValid);
}
+ @SuppressWarnings("unchecked")
@Test
public void testSigningAnAssertionWithinResponse() throws Exception
{
@@ -165,15 +168,20 @@
validatingDoc.appendChild(importedSignedNode);
// Validate the signature
+ System.out.println(DocumentUtil.getDocumentAsString(validatingDoc));
boolean isValid = XMLSignatureUtil.validate(validatingDoc, kp.getPublic());
assertTrue("Signature is valid:", isValid);
- // Let's say someone sends the signed doc to a remote client and that the
client unmarshals the response.
- responseType = response.getResponseType(DocumentUtil.getNodeAsStream(signedDoc));
-
- // Now the remote client wants to validate the response. So he marshals it again to
Document.
- signedDoc = response.convert(responseType);
- signedNode = DocumentUtil.getNodeWithAttribute(signedDoc,
"urn:oasis:names:tc:SAML:2.0:assertion",
+
+ /**
+ * Now the signed document is marshalled across the wire using dom
+ * write
+ */
+ Binder<Node> binder = response.getBinder();
+ //We have to parse the dom coming from the stream and feed to binder
+ Document readDoc =
DocumentUtil.getDocument(DocumentUtil.getNodeAsStream(signedDoc));
+
+ signedNode = DocumentUtil.getNodeWithAttribute(readDoc,
"urn:oasis:names:tc:SAML:2.0:assertion",
"Assertion", "ID", id);
// The client creates a validating document, importing the signed assertion.
@@ -181,10 +189,14 @@
importedSignedNode = validatingDoc.importNode(signedNode, true);
validatingDoc.appendChild(importedSignedNode);
- // The client re-validates the signature.
- System.out.println("FIXME: Signature TEST");
- //assertTrue("Signature is valid:",
XMLSignatureUtil.validate(validatingDoc, kp.getPublic()));
-}
+ // The client re-validates the signature.
+ System.out.println(DocumentUtil.getDocumentAsString(validatingDoc));
+ assertTrue("Signature is valid:",
XMLSignatureUtil.validate(validatingDoc, kp.getPublic()));
+
+ JAXBElement<ResponseType> jaxbresponseType =
(JAXBElement<ResponseType>) binder.unmarshal(readDoc);
+ responseType = jaxbresponseType.getValue();
+ assertNotNull(responseType);
+ }
/**
* Test signing a string
@@ -203,5 +215,5 @@
boolean valid = SignatureUtil.validate(arbitContent.getBytes(), sigVal,
kp.getPublic());
assertTrue(valid);
- }
+ }
}
\ No newline at end of file
Show replies by date