use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType in project keycloak by keycloak.
the class SAML11ParserUtil method parseSAML11SubjectConfirmation.
/**
* 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.getElementName(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;
}
use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType in project keycloak by keycloak.
the class SAML11AssertionWriter method write.
/**
* write an {@code SubjectType} to stream
*
* @param subject
* @param out
*
* @throws ProcessingException
*/
public void write(SAML11SubjectType subject) throws ProcessingException {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT.get(), SAML11Constants.ASSERTION_11_NSURI);
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ns);
SAML11SubjectTypeChoice choice = subject.getChoice();
if (choice != null) {
SAML11NameIdentifierType nameid = choice.getNameID();
if (nameid != null) {
write(nameid);
}
SAML11SubjectConfirmationType confirmation = choice.getSubjectConfirmation();
if (confirmation != null)
write(confirmation);
}
SAML11SubjectConfirmationType confirmation = subject.getSubjectConfirmation();
if (confirmation != null)
write(confirmation);
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType in project keycloak by keycloak.
the class SAML11SubjectParser method parse.
/**
* @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
*/
public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
StaxParserUtil.getNextEvent(xmlEventReader);
SAML11SubjectType subject = new SAML11SubjectType();
// Peek at the next event
while (xmlEventReader.hasNext()) {
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
if (xmlEvent instanceof EndElement) {
EndElement endElement = (EndElement) xmlEvent;
if (StaxParserUtil.matches(endElement, JBossSAMLConstants.SUBJECT.get())) {
endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
break;
} else
throw logger.parserUnknownEndElement(StaxParserUtil.getElementName(endElement), xmlEvent.getLocation());
}
StartElement peekedElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
if (peekedElement == null)
break;
String tag = StaxParserUtil.getElementName(peekedElement);
if (SAML11Constants.NAME_IDENTIFIER.equalsIgnoreCase(tag)) {
peekedElement = StaxParserUtil.getNextStartElement(xmlEventReader);
String val = StaxParserUtil.getElementText(xmlEventReader);
SAML11NameIdentifierType nameID = new SAML11NameIdentifierType(val);
Attribute formatAtt = peekedElement.getAttributeByName(new QName(SAML11Constants.FORMAT));
if (formatAtt != null) {
nameID.setFormat(URI.create(StaxParserUtil.getAttributeValue(formatAtt)));
}
Attribute nameQAtt = peekedElement.getAttributeByName(new QName(SAML11Constants.NAME_QUALIFIER));
if (nameQAtt != null) {
nameID.setNameQualifier(StaxParserUtil.getAttributeValue(nameQAtt));
}
SAML11SubjectTypeChoice subChoice = new SAML11SubjectTypeChoice(nameID);
subject.setChoice(subChoice);
} else if (JBossSAMLConstants.SUBJECT_CONFIRMATION.get().equalsIgnoreCase(tag)) {
SAML11SubjectConfirmationType subjectConfirmationType = SAML11ParserUtil.parseSAML11SubjectConfirmation(xmlEventReader);
subject.setSubjectConfirmation(subjectConfirmationType);
} else
throw logger.parserUnknownTag(tag, peekedElement.getLocation());
}
return subject;
}
Aggregations