Search in sources :

Example 1 with StatusDetailType

use of org.keycloak.dom.saml.v2.protocol.StatusDetailType in project keycloak by keycloak.

the class SAML11ResponseParser method parseStatus.

/**
 * Parse the status element
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
protected SAML11StatusType parseStatus(XMLEventReader xmlEventReader) throws ParsingException {
    // Get the Start Element
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    String STATUS = JBossSAMLConstants.STATUS.get();
    StaxParserUtil.validate(startElement, STATUS);
    SAML11StatusType status = new SAML11StatusType();
    while (xmlEventReader.hasNext()) {
        startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        if (startElement == null)
            break;
        QName startElementName = startElement.getName();
        String elementTag = startElementName.getLocalPart();
        SAML11StatusCodeType statusCode = null;
        if (JBossSAMLConstants.STATUS_CODE.get().equals(elementTag)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            if (startElement == null)
                break;
            Attribute valueAttr = startElement.getAttributeByName(new QName("Value"));
            if (valueAttr != null) {
                statusCode = new SAML11StatusCodeType(new QName(StaxParserUtil.getAttributeValue(valueAttr)));
            }
            status.setStatusCode(statusCode);
            // Peek at the next start element to see if it is status code
            startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
            elementTag = startElement.getName().getLocalPart();
            if (JBossSAMLConstants.STATUS_CODE.get().equals(elementTag)) {
                SAML11StatusCodeType subStatusCodeType = null;
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                Attribute subValueAttr = startElement.getAttributeByName(new QName("Value"));
                if (subValueAttr != null) {
                    subStatusCodeType = new SAML11StatusCodeType(new QName(StaxParserUtil.getAttributeValue(subValueAttr)));
                }
                statusCode.setStatusCode(subStatusCodeType);
                // Go to Status code end element.
                EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                StaxParserUtil.validate(endElement, JBossSAMLConstants.STATUS_CODE.get());
                continue;
            }
        }
        if (JBossSAMLConstants.STATUS_MESSAGE.get().equals(elementTag)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            if (startElement == null)
                break;
            status.setStatusMessage(StaxParserUtil.getElementText(xmlEventReader));
        }
        if (JBossSAMLConstants.STATUS_DETAIL.get().equals(elementTag)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            if (startElement == null)
                break;
            Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);
            StatusDetailType statusDetailType = new StatusDetailType();
            statusDetailType.addStatusDetail(domElement);
            status.setStatusDetail(statusDetailType);
        }
        // Get the next end element
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            if (StaxParserUtil.matches(endElement, STATUS))
                break;
            else
                throw logger.parserUnknownEndElement(StaxParserUtil.getElementName(endElement), xmlEvent.getLocation());
        } else
            break;
    }
    return status;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SAML11StatusType(org.keycloak.dom.saml.v1.protocol.SAML11StatusType) StatusDetailType(org.keycloak.dom.saml.v2.protocol.StatusDetailType) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) EndElement(javax.xml.stream.events.EndElement) StartElement(javax.xml.stream.events.StartElement) XMLEvent(javax.xml.stream.events.XMLEvent) SAML11StatusCodeType(org.keycloak.dom.saml.v1.protocol.SAML11StatusCodeType)

Example 2 with StatusDetailType

use of org.keycloak.dom.saml.v2.protocol.StatusDetailType in project keycloak by keycloak.

the class SAMLStatusParser method processSubElement.

@Override
protected void processSubElement(XMLEventReader xmlEventReader, StatusType target, SAMLProtocolQNames element, StartElement elementDetail) throws ParsingException {
    switch(element) {
        case STATUS_CODE:
            target.setStatusCode(SAMLStatusCodeParser.getInstance().parse(xmlEventReader));
            break;
        case STATUS_MESSAGE:
            StaxParserUtil.advance(xmlEventReader);
            target.setStatusMessage(StaxParserUtil.getElementText(xmlEventReader));
            break;
        case STATUS_DETAIL:
            List<Element> elements = STATUS_DETAIL_PARSER.parse(xmlEventReader);
            StatusDetailType statusDetailType = new StatusDetailType();
            for (Element e : elements) {
                statusDetailType.addStatusDetail(e);
            }
            target.setStatusDetail(statusDetailType);
            break;
        default:
            throw LOGGER.parserUnknownTag(StaxParserUtil.getElementName(elementDetail), elementDetail.getLocation());
    }
}
Also used : StatusDetailType(org.keycloak.dom.saml.v2.protocol.StatusDetailType) Element(org.w3c.dom.Element) StartElement(javax.xml.stream.events.StartElement)

Example 3 with StatusDetailType

use of org.keycloak.dom.saml.v2.protocol.StatusDetailType in project keycloak by keycloak.

the class SAMLResponseWriter method write.

/**
 * Write a {@code StatusType} to stream
 *
 * @param status
 * @param out
 *
 * @throws ProcessingException
 */
public void write(StatusType status) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS.get(), JBossSAMLURIConstants.PROTOCOL_NSURI.get());
    StatusCodeType statusCodeType = status.getStatusCode();
    write(statusCodeType);
    String statusMessage = status.getStatusMessage();
    if (StringUtil.isNotNull(statusMessage)) {
        StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_MESSAGE.get(), JBossSAMLURIConstants.PROTOCOL_NSURI.get());
        StaxUtil.writeEndElement(writer);
    }
    StatusDetailType statusDetail = status.getStatusDetail();
    if (statusDetail != null)
        write(statusDetail);
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : StatusDetailType(org.keycloak.dom.saml.v2.protocol.StatusDetailType) StatusCodeType(org.keycloak.dom.saml.v2.protocol.StatusCodeType)

Aggregations

StatusDetailType (org.keycloak.dom.saml.v2.protocol.StatusDetailType)3 StartElement (javax.xml.stream.events.StartElement)2 Element (org.w3c.dom.Element)2 QName (javax.xml.namespace.QName)1 Attribute (javax.xml.stream.events.Attribute)1 EndElement (javax.xml.stream.events.EndElement)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 SAML11StatusCodeType (org.keycloak.dom.saml.v1.protocol.SAML11StatusCodeType)1 SAML11StatusType (org.keycloak.dom.saml.v1.protocol.SAML11StatusType)1 StatusCodeType (org.keycloak.dom.saml.v2.protocol.StatusCodeType)1