use of org.keycloak.dom.saml.v1.protocol.SAML11ResponseType in project keycloak by keycloak.
the class SAML11ResponseParser method parse.
/**
* @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
*/
public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
// Get the startelement
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
StaxParserUtil.validate(startElement, RESPONSE);
Attribute idAttr = startElement.getAttributeByName(new QName(SAML11Constants.RESPONSE_ID));
if (idAttr == null)
throw logger.parserRequiredAttribute(SAML11Constants.RESPONSE_ID);
String id = StaxParserUtil.getAttributeValue(idAttr);
Attribute issueInstant = startElement.getAttributeByName(new QName(SAML11Constants.ISSUE_INSTANT));
if (issueInstant == null)
throw logger.parserRequiredAttribute(SAML11Constants.ISSUE_INSTANT);
XMLGregorianCalendar issueInstantVal = XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(issueInstant));
SAML11ResponseType response = new SAML11ResponseType(id, issueInstantVal);
while (xmlEventReader.hasNext()) {
// Let us peek at the next start element
startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
if (startElement == null)
break;
String elementName = StaxParserUtil.getElementName(startElement);
if (JBossSAMLConstants.SIGNATURE.get().equals(elementName)) {
Element sig = StaxParserUtil.getDOMElement(xmlEventReader);
response.setSignature(sig);
} else if (JBossSAMLConstants.ASSERTION.get().equals(elementName)) {
SAML11AssertionParser assertionParser = new SAML11AssertionParser();
response.add((SAML11AssertionType) assertionParser.parse(xmlEventReader));
} else if (JBossSAMLConstants.STATUS.get().equals(elementName)) {
response.setStatus(parseStatus(xmlEventReader));
} else
throw logger.parserUnknownStartElement(elementName, startElement.getLocation());
}
return response;
}
use of org.keycloak.dom.saml.v1.protocol.SAML11ResponseType in project keycloak by keycloak.
the class SAML11ResponseWriter method write.
public void write(SAML11ResponseType response) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.RESPONSE, namespace);
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_11_NSURI);
// Attributes
StaxUtil.writeAttribute(writer, SAML11Constants.RESPONSE_ID, response.getID());
StaxUtil.writeAttribute(writer, SAML11Constants.MAJOR_VERSION, response.getMajorVersion() + "");
StaxUtil.writeAttribute(writer, SAML11Constants.MINOR_VERSION, response.getMinorVersion() + "");
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), response.getIssueInstant().toString());
String inResp = response.getInResponseTo();
if (StringUtil.isNotNull(inResp)) {
StaxUtil.writeAttribute(writer, SAML11Constants.IN_RESPONSE_TO, inResp);
}
URI recipient = response.getRecipient();
if (recipient != null) {
StaxUtil.writeAttribute(writer, SAML11Constants.RECIPIENT, recipient.toString());
}
Element sig = response.getSignature();
if (sig != null) {
StaxUtil.writeDOMElement(writer, sig);
}
SAML11StatusType status = response.getStatus();
if (status != null) {
write(status);
}
List<SAML11AssertionType> assertions = response.get();
for (SAML11AssertionType assertion : assertions) {
assertionWriter.write(assertion);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
Aggregations