Search in sources :

Example 1 with SAML11NameIdentifierType

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);
}
Also used : SAML11SubjectConfirmationType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType) SAML11NameIdentifierType(org.keycloak.dom.saml.v1.assertion.SAML11NameIdentifierType) SAML11SubjectTypeChoice(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType.SAML11SubjectTypeChoice)

Example 2 with SAML11NameIdentifierType

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;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) SAML11SubjectConfirmationType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType) EndElement(javax.xml.stream.events.EndElement) Attribute(javax.xml.stream.events.Attribute) SAML11NameIdentifierType(org.keycloak.dom.saml.v1.assertion.SAML11NameIdentifierType) QName(javax.xml.namespace.QName) XMLEvent(javax.xml.stream.events.XMLEvent) SAML11SubjectTypeChoice(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType.SAML11SubjectTypeChoice)

Aggregations

SAML11NameIdentifierType (org.keycloak.dom.saml.v1.assertion.SAML11NameIdentifierType)2 SAML11SubjectConfirmationType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType)2 SAML11SubjectTypeChoice (org.keycloak.dom.saml.v1.assertion.SAML11SubjectType.SAML11SubjectTypeChoice)2 QName (javax.xml.namespace.QName)1 Attribute (javax.xml.stream.events.Attribute)1 EndElement (javax.xml.stream.events.EndElement)1 StartElement (javax.xml.stream.events.StartElement)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 SAML11SubjectType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectType)1