Search in sources :

Example 1 with SAML11ResponseType

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

the class SAML11ResponseParser method parse.

/**
 * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
 */
public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
    // Get the startelement
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, RESPONSE);
    Attribute idAttr = startElement.getAttributeByName(new QName(SAML11Constants.RESPONSE_ID));
    if (idAttr == null)
        throw logger.parserRequiredAttribute(SAML11Constants.RESPONSE_ID);
    String id = StaxParserUtil.getAttributeValue(idAttr);
    Attribute issueInstant = startElement.getAttributeByName(new QName(SAML11Constants.ISSUE_INSTANT));
    if (issueInstant == null)
        throw logger.parserRequiredAttribute(SAML11Constants.ISSUE_INSTANT);
    XMLGregorianCalendar issueInstantVal = XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(issueInstant));
    SAML11ResponseType response = new SAML11ResponseType(id, issueInstantVal);
    while (xmlEventReader.hasNext()) {
        // Let us peek at the next start element
        startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        if (startElement == null)
            break;
        String elementName = StaxParserUtil.getElementName(startElement);
        if (JBossSAMLConstants.SIGNATURE.get().equals(elementName)) {
            Element sig = StaxParserUtil.getDOMElement(xmlEventReader);
            response.setSignature(sig);
        } else if (JBossSAMLConstants.ASSERTION.get().equals(elementName)) {
            SAML11AssertionParser assertionParser = new SAML11AssertionParser();
            response.add((SAML11AssertionType) assertionParser.parse(xmlEventReader));
        } else if (JBossSAMLConstants.STATUS.get().equals(elementName)) {
            response.setStatus(parseStatus(xmlEventReader));
        } else
            throw logger.parserUnknownStartElement(elementName, startElement.getLocation());
    }
    return response;
}
Also used : StartElement(javax.xml.stream.events.StartElement) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Attribute(javax.xml.stream.events.Attribute) SAML11ResponseType(org.keycloak.dom.saml.v1.protocol.SAML11ResponseType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) EndElement(javax.xml.stream.events.EndElement) StartElement(javax.xml.stream.events.StartElement) SAML11AssertionType(org.keycloak.dom.saml.v1.assertion.SAML11AssertionType)

Example 2 with SAML11ResponseType

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

SAML11AssertionType (org.keycloak.dom.saml.v1.assertion.SAML11AssertionType)2 Element (org.w3c.dom.Element)2 URI (java.net.URI)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)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 SAML11ResponseType (org.keycloak.dom.saml.v1.protocol.SAML11ResponseType)1 SAML11StatusType (org.keycloak.dom.saml.v1.protocol.SAML11StatusType)1