/** * Parse the {@link SubjectConfirmationDataType} * * @param xmlEventReader * @return * @throws ParsingException */ public static SubjectConfirmationDataType parseSubjectConfirmationData( XMLEventReader xmlEventReader) throws ParsingException { StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader); StaxParserUtil.validate(startElement, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get()); SubjectConfirmationDataType subjectConfirmationData = new SubjectConfirmationDataType(); Attribute inResponseTo = startElement.getAttributeByName(new QName(JBossSAMLConstants.IN_RESPONSE_TO.get())); if (inResponseTo != null) { subjectConfirmationData.setInResponseTo(StaxParserUtil.getAttributeValue(inResponseTo)); } Attribute notBefore = startElement.getAttributeByName(new QName(JBossSAMLConstants.NOT_BEFORE.get())); if (notBefore != null) { subjectConfirmationData.setNotBefore( XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(notBefore))); } Attribute notOnOrAfter = startElement.getAttributeByName(new QName(JBossSAMLConstants.NOT_ON_OR_AFTER.get())); if (notOnOrAfter != null) { subjectConfirmationData.setNotOnOrAfter( XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(notOnOrAfter))); } Attribute recipient = startElement.getAttributeByName(new QName(JBossSAMLConstants.RECIPIENT.get())); if (recipient != null) { subjectConfirmationData.setRecipient(StaxParserUtil.getAttributeValue(recipient)); } Attribute address = startElement.getAttributeByName(new QName(JBossSAMLConstants.ADDRESS.get())); if (address != null) { subjectConfirmationData.setAddress(StaxParserUtil.getAttributeValue(address)); } XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader); if (!(xmlEvent instanceof EndElement)) { startElement = StaxParserUtil.peekNextStartElement(xmlEventReader); String tag = StaxParserUtil.getStartElementName(startElement); if (tag.equals(WSTrustConstants.XMLDSig.KEYINFO)) { KeyInfoType keyInfo = parseKeyInfo(xmlEventReader); subjectConfirmationData.setAnyType(keyInfo); } else if (tag.equals(WSTrustConstants.XMLEnc.ENCRYPTED_KEY)) { subjectConfirmationData.setAnyType(StaxParserUtil.getDOMElement(xmlEventReader)); } else throw logger.parserUnknownTag(tag, startElement.getLocation()); } // Get the end tag EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader); StaxParserUtil.matches(endElement, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get()); return subjectConfirmationData; }
/** * Parse the {@link org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType} * * @param xmlEventReader * @return * @throws ParsingException */ public static SAML11SubjectConfirmationType parseSAML11SubjectConfirmation( XMLEventReader xmlEventReader) throws ParsingException { SAML11SubjectConfirmationType subjectConfirmationType = new SAML11SubjectConfirmationType(); StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader); // There may be additional things under subject confirmation while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader); if (xmlEvent instanceof EndElement) { EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader); StaxParserUtil.validate(endElement, JBossSAMLConstants.SUBJECT_CONFIRMATION.get()); break; } if (xmlEvent instanceof StartElement) { startElement = (StartElement) xmlEvent; String startTag = StaxParserUtil.getStartElementName(startElement); if (startTag.equals(SAML11Constants.CONFIRMATION_METHOD)) { startElement = StaxParserUtil.getNextStartElement(xmlEventReader); String method = StaxParserUtil.getElementText(xmlEventReader); subjectConfirmationType.addConfirmationMethod(URI.create(method)); } else if (startTag.equals(JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get())) { startElement = StaxParserUtil.getNextStartElement(xmlEventReader); SubjectConfirmationDataType subjectConfirmationData = parseSubjectConfirmationData(xmlEventReader); subjectConfirmationType.setSubjectConfirmationData(subjectConfirmationData); } else if (startTag.equals(JBossSAMLConstants.KEY_INFO.get())) { Element keyInfo = StaxParserUtil.getDOMElement(xmlEventReader); subjectConfirmationType.setKeyInfo(keyInfo); } else throw logger.parserUnknownTag(startTag, startElement.getLocation()); } } return subjectConfirmationType; }