Search in sources :

Example 1 with SubjectConfirmationDataBuilder

use of org.opensaml.saml.saml2.core.impl.SubjectConfirmationDataBuilder in project ddf by codice.

the class SimpleSignTest method testSignSamlObjectModifyAndResign.

@Test
public void testSignSamlObjectModifyAndResign() throws Exception {
    Document responseDoc = StaxUtils.read(new ByteArrayInputStream(cannedResponse.getBytes()));
    XMLObject responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
    org.opensaml.saml.saml2.core.Response response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
    simpleSign.signSamlObject(response);
    final SubjectConfirmationData scd = new SubjectConfirmationDataBuilder().buildObject();
    scd.setNotOnOrAfter(DateTime.now().plusMinutes(30));
    for (Assertion assertion : response.getAssertions()) {
        assertion.getSubject().getSubjectConfirmations().forEach(sc -> sc.setSubjectConfirmationData(scd));
    }
    Document doc = DOMUtils.createDocument();
    Element requestElement = OpenSAMLUtil.toDom(response, doc);
    String responseMessage = DOM2Writer.nodeToString(requestElement);
    responseDoc = StaxUtils.read(new ByteArrayInputStream(responseMessage.getBytes()));
    responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
    response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
    simpleSign.validateSignature(response.getSignature(), response.getDOM().getOwnerDocument());
}
Also used : Element(org.w3c.dom.Element) Assertion(org.opensaml.saml.saml2.core.Assertion) XMLObject(org.opensaml.core.xml.XMLObject) Document(org.w3c.dom.Document) SubjectConfirmationData(org.opensaml.saml.saml2.core.SubjectConfirmationData) SubjectConfirmationDataBuilder(org.opensaml.saml.saml2.core.impl.SubjectConfirmationDataBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1 XMLObject (org.opensaml.core.xml.XMLObject)1 Assertion (org.opensaml.saml.saml2.core.Assertion)1 SubjectConfirmationData (org.opensaml.saml.saml2.core.SubjectConfirmationData)1 SubjectConfirmationDataBuilder (org.opensaml.saml.saml2.core.impl.SubjectConfirmationDataBuilder)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1