Search in sources :

Example 1 with SAML11StatusType

use of org.keycloak.dom.saml.v1.protocol.SAML11StatusType in project keycloak by keycloak.

the class SAML11ResponseWriter method write.

public void write(SAML11StatusType status) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.STATUS, namespace);
    SAML11StatusCodeType statusCode = status.getStatusCode();
    if (statusCode != null) {
        write(statusCode);
    }
    String statusMsg = status.getStatusMessage();
    if (StringUtil.isNotNull(statusMsg)) {
        StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.STATUS_MSG, namespace);
        StaxUtil.writeCharacters(writer, statusMsg);
        StaxUtil.writeEndElement(writer);
    }
    CommonStatusDetailType details = status.getStatusDetail();
    if (details != null) {
        StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.STATUS_DETAIL, namespace);
        List<Object> objs = details.getAny();
        for (Object theObj : objs) {
            StaxUtil.writeCharacters(writer, theObj.toString());
        }
        StaxUtil.writeEndElement(writer);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : CommonStatusDetailType(org.keycloak.dom.saml.common.CommonStatusDetailType) SAML11StatusCodeType(org.keycloak.dom.saml.v1.protocol.SAML11StatusCodeType)

Example 2 with SAML11StatusType

use of org.keycloak.dom.saml.v1.protocol.SAML11StatusType 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 3 with SAML11StatusType

use of org.keycloak.dom.saml.v1.protocol.SAML11StatusType in project keycloak by keycloak.

the class SAML11ResponseWriter method write.

public void write(SAML11ResponseType response) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.RESPONSE, namespace);
    StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
    StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_11_NSURI);
    // Attributes
    StaxUtil.writeAttribute(writer, SAML11Constants.RESPONSE_ID, response.getID());
    StaxUtil.writeAttribute(writer, SAML11Constants.MAJOR_VERSION, response.getMajorVersion() + "");
    StaxUtil.writeAttribute(writer, SAML11Constants.MINOR_VERSION, response.getMinorVersion() + "");
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), response.getIssueInstant().toString());
    String inResp = response.getInResponseTo();
    if (StringUtil.isNotNull(inResp)) {
        StaxUtil.writeAttribute(writer, SAML11Constants.IN_RESPONSE_TO, inResp);
    }
    URI recipient = response.getRecipient();
    if (recipient != null) {
        StaxUtil.writeAttribute(writer, SAML11Constants.RECIPIENT, recipient.toString());
    }
    Element sig = response.getSignature();
    if (sig != null) {
        StaxUtil.writeDOMElement(writer, sig);
    }
    SAML11StatusType status = response.getStatus();
    if (status != null) {
        write(status);
    }
    List<SAML11AssertionType> assertions = response.get();
    for (SAML11AssertionType assertion : assertions) {
        assertionWriter.write(assertion);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11StatusType(org.keycloak.dom.saml.v1.protocol.SAML11StatusType) Element(org.w3c.dom.Element) SAML11AssertionType(org.keycloak.dom.saml.v1.assertion.SAML11AssertionType) URI(java.net.URI)

Aggregations

SAML11StatusCodeType (org.keycloak.dom.saml.v1.protocol.SAML11StatusCodeType)2 SAML11StatusType (org.keycloak.dom.saml.v1.protocol.SAML11StatusType)2 Element (org.w3c.dom.Element)2 URI (java.net.URI)1 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 CommonStatusDetailType (org.keycloak.dom.saml.common.CommonStatusDetailType)1 SAML11AssertionType (org.keycloak.dom.saml.v1.assertion.SAML11AssertionType)1 StatusDetailType (org.keycloak.dom.saml.v2.protocol.StatusDetailType)1