Search in sources :

Example 1 with SAML11SubjectParser

use of org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser in project keycloak by keycloak.

the class SAML11ParserUtil method parseSAML11AttributeStatement.

/**
 * Parse an {@code SAML11AttributeStatementType}
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
public static SAML11AttributeStatementType parseSAML11AttributeStatement(XMLEventReader xmlEventReader) throws ParsingException {
    SAML11AttributeStatementType attributeStatementType = new SAML11AttributeStatementType();
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    String ATTRIBSTATEMT = JBossSAMLConstants.ATTRIBUTE_STATEMENT.get();
    StaxParserUtil.validate(startElement, ATTRIBSTATEMT);
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            StaxParserUtil.validate(endElement, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get());
            break;
        }
        // Get the next start element
        startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        String tag = startElement.getName().getLocalPart();
        if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag)) {
            SAML11AttributeType attribute = parseSAML11Attribute(xmlEventReader);
            attributeStatementType.add(attribute);
        } else if (JBossSAMLConstants.SUBJECT.get().equals(tag)) {
            SAML11SubjectParser parser = new SAML11SubjectParser();
            SAML11SubjectType subject = (SAML11SubjectType) parser.parse(xmlEventReader);
            attributeStatementType.setSubject(subject);
        } else
            throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
    return attributeStatementType;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) EndElement(javax.xml.stream.events.EndElement) SAML11SubjectParser(org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser) XMLEvent(javax.xml.stream.events.XMLEvent) SAML11AttributeType(org.keycloak.dom.saml.v1.assertion.SAML11AttributeType) SAML11AttributeStatementType(org.keycloak.dom.saml.v1.assertion.SAML11AttributeStatementType)

Example 2 with SAML11SubjectParser

use of org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser in project keycloak by keycloak.

the class SAML11ParserUtil method parseSAML11AuthorizationDecisionStatement.

public static SAML11AuthorizationDecisionStatementType parseSAML11AuthorizationDecisionStatement(XMLEventReader xmlEventReader) throws ParsingException {
    SAML11AuthorizationDecisionStatementType authzDecision = null;
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT);
    Attribute decision = startElement.getAttributeByName(new QName(SAML11Constants.DECISION));
    if (decision == null)
        throw logger.parserRequiredAttribute("Decision");
    String decisionValue = StaxParserUtil.getAttributeValue(decision);
    Attribute resource = startElement.getAttributeByName(new QName(SAML11Constants.RESOURCE));
    if (resource == null)
        throw logger.parserRequiredAttribute("Namespace");
    String resValue = StaxParserUtil.getAttributeValue(resource);
    authzDecision = new SAML11AuthorizationDecisionStatementType(URI.create(resValue), SAML11DecisionType.valueOf(decisionValue));
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader);
            if (StaxParserUtil.matches(end, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT))
                break;
        }
        startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        if (startElement == null)
            break;
        String tag = StaxParserUtil.getElementName(startElement);
        if (SAML11Constants.ACTION.equals(tag)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            SAML11ActionType samlAction = new SAML11ActionType();
            Attribute namespaceAttr = startElement.getAttributeByName(new QName(SAML11Constants.NAMESPACE));
            if (namespaceAttr != null) {
                samlAction.setNamespace(StaxParserUtil.getAttributeValue(namespaceAttr));
            }
            samlAction.setValue(StaxParserUtil.getElementText(xmlEventReader));
            authzDecision.addAction(samlAction);
        } else if (JBossSAMLConstants.SUBJECT.get().equals(tag)) {
            SAML11SubjectParser parser = new SAML11SubjectParser();
            authzDecision.setSubject((SAML11SubjectType) parser.parse(xmlEventReader));
        } else
            throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
    return authzDecision;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) QName(javax.xml.namespace.QName) SAML11SubjectParser(org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser) SAML11AuthorizationDecisionStatementType(org.keycloak.dom.saml.v1.assertion.SAML11AuthorizationDecisionStatementType) XMLEvent(javax.xml.stream.events.XMLEvent) SAML11ActionType(org.keycloak.dom.saml.v1.assertion.SAML11ActionType)

Example 3 with SAML11SubjectParser

use of org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser 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 SAML11SubjectParser

use of org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser 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 SAML11SubjectParser

use of org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser in project keycloak by keycloak.

the class SAML11ParserUtil method parseSAML11AuthorizationDecisionQueryType.

/**
 * Parse the {@link SAML11AuthorizationDecisionQueryType}
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
public static SAML11AuthorizationDecisionQueryType parseSAML11AuthorizationDecisionQueryType(XMLEventReader xmlEventReader) throws ParsingException {
    SAML11AuthorizationDecisionQueryType query = new SAML11AuthorizationDecisionQueryType();
    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.AUTHORIZATION_DECISION_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 if (startTag.equals(SAML11Constants.RESOURCE)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                query.setResource(URI.create(StaxParserUtil.getElementText(xmlEventReader)));
            } else if (startTag.equals(SAML11Constants.ACTION)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                SAML11ActionType action = new SAML11ActionType();
                Attribute nsAttr = startElement.getAttributeByName(new QName(SAML11Constants.NAMESPACE));
                if (nsAttr != null) {
                    action.setNamespace(StaxParserUtil.getAttributeValue(nsAttr));
                }
                action.setValue(StaxParserUtil.getElementText(xmlEventReader));
                query.add(action);
            } else
                throw logger.parserUnknownTag(startTag, startElement.getLocation());
        }
    }
    return query;
}
Also used : SAML11AuthorizationDecisionQueryType(org.keycloak.dom.saml.v1.protocol.SAML11AuthorizationDecisionQueryType) StartElement(javax.xml.stream.events.StartElement) EndElement(javax.xml.stream.events.EndElement) Attribute(javax.xml.stream.events.Attribute) SAML11SubjectParser(org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser) QName(javax.xml.namespace.QName) XMLEvent(javax.xml.stream.events.XMLEvent) SAML11ActionType(org.keycloak.dom.saml.v1.assertion.SAML11ActionType)

Aggregations

EndElement (javax.xml.stream.events.EndElement)6 StartElement (javax.xml.stream.events.StartElement)6 XMLEvent (javax.xml.stream.events.XMLEvent)6 SAML11SubjectParser (org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser)6 QName (javax.xml.namespace.QName)3 Attribute (javax.xml.stream.events.Attribute)3 SAML11SubjectType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectType)3 SAML11ActionType (org.keycloak.dom.saml.v1.assertion.SAML11ActionType)2 URI (java.net.URI)1 SAML11AttributeStatementType (org.keycloak.dom.saml.v1.assertion.SAML11AttributeStatementType)1 SAML11AttributeType (org.keycloak.dom.saml.v1.assertion.SAML11AttributeType)1 SAML11AuthenticationStatementType (org.keycloak.dom.saml.v1.assertion.SAML11AuthenticationStatementType)1 SAML11AuthorityBindingType (org.keycloak.dom.saml.v1.assertion.SAML11AuthorityBindingType)1 SAML11AuthorizationDecisionStatementType (org.keycloak.dom.saml.v1.assertion.SAML11AuthorizationDecisionStatementType)1 SAML11SubjectLocalityType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectLocalityType)1 SAML11SubjectStatementType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectStatementType)1 SAML11AttributeQueryType (org.keycloak.dom.saml.v1.protocol.SAML11AttributeQueryType)1 SAML11AuthenticationQueryType (org.keycloak.dom.saml.v1.protocol.SAML11AuthenticationQueryType)1 SAML11AuthorizationDecisionQueryType (org.keycloak.dom.saml.v1.protocol.SAML11AuthorizationDecisionQueryType)1