Search in sources :

Example 1 with SAML11AttributeQueryType

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

the class SAML11RequestWriter method write.

public void write(SAML11RequestType request) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.REQUEST, namespace);
    StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
    StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_11_NSURI);
    StaxUtil.writeDefaultNameSpace(writer, namespace);
    // Attributes
    StaxUtil.writeAttribute(writer, SAML11Constants.REQUEST_ID, request.getID());
    StaxUtil.writeAttribute(writer, SAML11Constants.MAJOR_VERSION, request.getMajorVersion() + "");
    StaxUtil.writeAttribute(writer, SAML11Constants.MINOR_VERSION, request.getMinorVersion() + "");
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
    List<String> assertionIDRefs = request.getAssertionIDRef();
    for (String assertionIDRef : assertionIDRefs) {
        StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_ID_REF, SAML11Constants.ASSERTION_11_NSURI);
        StaxUtil.writeCharacters(writer, assertionIDRef);
        StaxUtil.writeEndElement(writer);
    }
    List<String> assertionArtifacts = request.getAssertionArtifact();
    for (String assertionArtifact : assertionArtifacts) {
        StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.ASSERTION_ARTIFACT, namespace);
        StaxUtil.writeCharacters(writer, assertionArtifact);
        StaxUtil.writeEndElement(writer);
    }
    SAML11QueryAbstractType query = request.getQuery();
    if (query instanceof SAML11AuthenticationQueryType) {
        SAML11AuthenticationQueryType authQuery = (SAML11AuthenticationQueryType) query;
        write(authQuery);
    } else if (query instanceof SAML11AttributeQueryType) {
        SAML11AttributeQueryType attQuery = (SAML11AttributeQueryType) query;
        write(attQuery);
    } else if (query instanceof SAML11AuthorizationDecisionQueryType) {
        SAML11AuthorizationDecisionQueryType attQuery = (SAML11AuthorizationDecisionQueryType) query;
        write(attQuery);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11AuthorizationDecisionQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AuthorizationDecisionQueryType) SAML11AuthenticationQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AuthenticationQueryType) SAML11QueryAbstractType(org.keycloak.dom.saml.v1.protocol.SAML11QueryAbstractType) SAML11AttributeQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AttributeQueryType)

Example 2 with SAML11AttributeQueryType

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

the class SAML11RequestParser 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, SAML11Constants.REQUEST);
    SAML11RequestType request = parseRequiredAttributes(startElement);
    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 (SAML11Constants.ATTRIBUTE_QUERY.equals(elementName)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            SAML11AttributeQueryType query = SAML11ParserUtil.parseSAML11AttributeQuery(xmlEventReader);
            request.setQuery(query);
        } else if (SAML11Constants.AUTHENTICATION_QUERY.equals(elementName)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            SAML11AuthenticationQueryType query = SAML11ParserUtil.parseSAML11AuthenticationQuery(xmlEventReader);
            request.setQuery(query);
        } else if (SAML11Constants.ASSERTION_ARTIFACT.equals(elementName)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            request.addAssertionArtifact(StaxParserUtil.getElementText(xmlEventReader));
        } else if (SAML11Constants.AUTHORIZATION_DECISION_QUERY.equals(elementName)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            SAML11AuthorizationDecisionQueryType query = SAML11ParserUtil.parseSAML11AuthorizationDecisionQueryType(xmlEventReader);
            request.setQuery(query);
        } else if (elementName.equals(JBossSAMLConstants.SIGNATURE.get())) {
            request.setSignature(StaxParserUtil.getDOMElement(xmlEventReader));
        } else if (SAML11Constants.ASSERTION_ID_REF.equals(elementName)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            request.addAssertionIDRef(StaxParserUtil.getElementText(xmlEventReader));
        } else
            throw logger.parserUnknownStartElement(elementName, startElement.getLocation());
    }
    return request;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SAML11AuthorizationDecisionQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AuthorizationDecisionQueryType) SAML11RequestType(org.keycloak.dom.saml.v1.protocol.SAML11RequestType) SAML11AuthenticationQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AuthenticationQueryType) SAML11AttributeQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AttributeQueryType)

Example 3 with SAML11AttributeQueryType

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

the class SAML11ParserUtil method parseSAML11AuthenticationQuery.

/**
 * Parse the {@link SAML11AttributeQueryType}
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
public static SAML11AuthenticationQueryType parseSAML11AuthenticationQuery(XMLEventReader xmlEventReader) throws ParsingException {
    SAML11AuthenticationQueryType query = new SAML11AuthenticationQueryType();
    StartElement startElement;
    // There may be additional things under subject confirmation
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            if (StaxParserUtil.matches(endElement, SAML11Constants.AUTHENTICATION_QUERY))
                break;
            else
                throw logger.parserUnknownEndElement(StaxParserUtil.getElementName(endElement), xmlEvent.getLocation());
        }
        if (xmlEvent instanceof StartElement) {
            startElement = (StartElement) xmlEvent;
            String startTag = StaxParserUtil.getElementName(startElement);
            if (startTag.equals(JBossSAMLConstants.SUBJECT.get())) {
                SAML11SubjectParser parser = new SAML11SubjectParser();
                query.setSubject((SAML11SubjectType) parser.parse(xmlEventReader));
            } else
                throw logger.parserUnknownTag(startTag, startElement.getLocation());
        }
    }
    return query;
}
Also used : StartElement(javax.xml.stream.events.StartElement) EndElement(javax.xml.stream.events.EndElement) SAML11AuthenticationQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AuthenticationQueryType) SAML11SubjectParser(org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 4 with SAML11AttributeQueryType

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

the class SAML11ParserUtil method parseSAML11AttributeQuery.

/**
 * Parse the {@link SAML11AttributeQueryType}
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
public static SAML11AttributeQueryType parseSAML11AttributeQuery(XMLEventReader xmlEventReader) throws ParsingException {
    SAML11AttributeQueryType query = new SAML11AttributeQueryType();
    StartElement startElement;
    // There may be additional things under subject confirmation
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            if (StaxParserUtil.matches(endElement, SAML11Constants.ATTRIBUTE_QUERY))
                break;
            else
                throw logger.parserUnknownEndElement(StaxParserUtil.getElementName(endElement), xmlEvent.getLocation());
        }
        if (xmlEvent instanceof StartElement) {
            startElement = (StartElement) xmlEvent;
            String startTag = StaxParserUtil.getElementName(startElement);
            if (startTag.equals(JBossSAMLConstants.SUBJECT.get())) {
                SAML11SubjectParser parser = new SAML11SubjectParser();
                query.setSubject((SAML11SubjectType) parser.parse(xmlEventReader));
            } else
                throw logger.parserUnknownTag(startTag, startElement.getLocation());
        }
    }
    return query;
}
Also used : StartElement(javax.xml.stream.events.StartElement) EndElement(javax.xml.stream.events.EndElement) SAML11SubjectParser(org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser) XMLEvent(javax.xml.stream.events.XMLEvent) SAML11AttributeQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AttributeQueryType)

Example 5 with SAML11AttributeQueryType

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

the class SAML11RequestWriter method write.

public void write(SAML11AttributeQueryType attr) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.ATTRIBUTE_QUERY, namespace);
    URI resource = attr.getResource();
    if (resource != null) {
        StaxUtil.writeAttribute(writer, SAML11Constants.RESOURCE, resource.toString());
    }
    SAML11SubjectType subject = attr.getSubject();
    if (subject != null) {
        assertionWriter.write(subject);
    }
    List<SAML11AttributeDesignatorType> attributes = attr.get();
    for (SAML11AttributeDesignatorType attribute : attributes) {
        if (attribute instanceof SAML11AttributeType) {
            SAML11AttributeType sat = (SAML11AttributeType) attribute;
            assertionWriter.write(sat);
        } else
            throw logger.writerUnknownTypeError(attribute.getClass().getName());
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) SAML11AttributeDesignatorType(org.keycloak.dom.saml.v1.assertion.SAML11AttributeDesignatorType) SAML11AttributeType(org.keycloak.dom.saml.v1.assertion.SAML11AttributeType) URI(java.net.URI)

Aggregations

StartElement (javax.xml.stream.events.StartElement)3 SAML11AttributeQueryType (org.keycloak.dom.saml.v1.protocol.SAML11AttributeQueryType)3 SAML11AuthenticationQueryType (org.keycloak.dom.saml.v1.protocol.SAML11AuthenticationQueryType)3 EndElement (javax.xml.stream.events.EndElement)2 XMLEvent (javax.xml.stream.events.XMLEvent)2 SAML11AuthorizationDecisionQueryType (org.keycloak.dom.saml.v1.protocol.SAML11AuthorizationDecisionQueryType)2 SAML11SubjectParser (org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser)2 URI (java.net.URI)1 SAML11AttributeDesignatorType (org.keycloak.dom.saml.v1.assertion.SAML11AttributeDesignatorType)1 SAML11AttributeType (org.keycloak.dom.saml.v1.assertion.SAML11AttributeType)1 SAML11SubjectType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectType)1 SAML11QueryAbstractType (org.keycloak.dom.saml.v1.protocol.SAML11QueryAbstractType)1 SAML11RequestType (org.keycloak.dom.saml.v1.protocol.SAML11RequestType)1