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());
}
Aggregations