use of org.keycloak.dom.saml.v1.assertion.SAML11NameIdentifierType 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.SAML11NameIdentifierType 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