Search in sources :

Example 16 with Attribute

use of javax.xml.stream.events.Attribute 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 17 with Attribute

use of javax.xml.stream.events.Attribute in project keycloak by keycloak.

the class SAML11ParserUtil method parseSAML11Conditions.

/**
 * Parse {@link org.keycloak.dom.saml.v1.assertion.SAML11ConditionsType}
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
public static SAML11ConditionsType parseSAML11Conditions(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement;
    SAML11ConditionsType conditions = new SAML11ConditionsType();
    StartElement conditionsElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(conditionsElement, JBossSAMLConstants.CONDITIONS.get());
    String assertionNS = SAML11Constants.ASSERTION_11_NSURI;
    QName notBeforeQName = new QName("", JBossSAMLConstants.NOT_BEFORE.get());
    QName notBeforeQNameWithNS = new QName(assertionNS, JBossSAMLConstants.NOT_BEFORE.get());
    QName notAfterQName = new QName("", JBossSAMLConstants.NOT_ON_OR_AFTER.get());
    QName notAfterQNameWithNS = new QName(assertionNS, JBossSAMLConstants.NOT_ON_OR_AFTER.get());
    Attribute notBeforeAttribute = conditionsElement.getAttributeByName(notBeforeQName);
    if (notBeforeAttribute == null)
        notBeforeAttribute = conditionsElement.getAttributeByName(notBeforeQNameWithNS);
    Attribute notAfterAttribute = conditionsElement.getAttributeByName(notAfterQName);
    if (notAfterAttribute == null)
        notAfterAttribute = conditionsElement.getAttributeByName(notAfterQNameWithNS);
    if (notBeforeAttribute != null) {
        String notBeforeValue = StaxParserUtil.getAttributeValue(notBeforeAttribute);
        conditions.setNotBefore(XMLTimeUtil.parse(notBeforeValue));
    }
    if (notAfterAttribute != null) {
        String notAfterValue = StaxParserUtil.getAttributeValue(notAfterAttribute);
        conditions.setNotOnOrAfter(XMLTimeUtil.parse(notAfterValue));
    }
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader);
            if (StaxParserUtil.matches(end, JBossSAMLConstants.CONDITIONS.get()))
                break;
        }
        startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        if (startElement == null)
            break;
        String tag = StaxParserUtil.getElementName(startElement);
        if (SAML11Constants.AUDIENCE_RESTRICTION_CONDITION.equals(tag)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            SAML11AudienceRestrictionCondition restrictCond = new SAML11AudienceRestrictionCondition();
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            if (StaxParserUtil.getElementName(startElement).equals(JBossSAMLConstants.AUDIENCE.get())) {
                restrictCond.add(URI.create(StaxParserUtil.getElementText(xmlEventReader)));
            }
            EndElement theEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            StaxParserUtil.validate(theEndElement, SAML11Constants.AUDIENCE_RESTRICTION_CONDITION);
            conditions.add(restrictCond);
        } else
            throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
    return conditions;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SAML11ConditionsType(org.keycloak.dom.saml.v1.assertion.SAML11ConditionsType) SAML11AudienceRestrictionCondition(org.keycloak.dom.saml.v1.assertion.SAML11AudienceRestrictionCondition) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) QName(javax.xml.namespace.QName) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 18 with Attribute

use of javax.xml.stream.events.Attribute in project keycloak by keycloak.

the class StaxParserUtil method getBooleanAttributeValueRP.

/**
 * Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
 *
 * @param startElement
 * @param tag localpart of the qname of the attribute
 *
 * @return
 */
public static Boolean getBooleanAttributeValueRP(StartElement startElement, HasQName attrName) {
    Attribute attr = startElement.getAttributeByName(attrName.getQName());
    String value = getAttributeValueRP(attr);
    return value == null ? null : Boolean.valueOf(value);
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Example 19 with Attribute

use of javax.xml.stream.events.Attribute in project keycloak by keycloak.

the class StaxParserUtil method getIntegerAttributeValueRP.

/**
 * Get the Attribute value, replacing every occurrence of ${..} by corresponding system property value
 *
 * @param startElement
 * @param tag localpart of the qname of the attribute
 *
 * @return
 */
public static Integer getIntegerAttributeValueRP(StartElement startElement, HasQName attrName) {
    Attribute attr = startElement.getAttributeByName(attrName.getQName());
    String value = getAttributeValueRP(attr);
    return value == null ? null : Integer.valueOf(value);
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Example 20 with Attribute

use of javax.xml.stream.events.Attribute in project keycloak by keycloak.

the class StaxParserUtil method getRequiredAttributeValue.

public static String getRequiredAttributeValue(StartElement startElement, HasQName attrName) throws ParsingException {
    final QName qName = attrName.getQName();
    Attribute attr = startElement.getAttributeByName(qName);
    if (attr == null)
        throw logger.parserRequiredAttribute(qName.getLocalPart());
    return StaxParserUtil.getAttributeValue(attr);
}
Also used : Attribute(javax.xml.stream.events.Attribute) HasQName(org.keycloak.saml.processing.core.parsers.util.HasQName) QName(javax.xml.namespace.QName)

Aggregations

Attribute (javax.xml.stream.events.Attribute)140 QName (javax.xml.namespace.QName)71 StartElement (javax.xml.stream.events.StartElement)62 XMLEvent (javax.xml.stream.events.XMLEvent)52 XMLEventReader (javax.xml.stream.XMLEventReader)30 Namespace (javax.xml.stream.events.Namespace)26 EndElement (javax.xml.stream.events.EndElement)25 ArrayList (java.util.ArrayList)23 XMLStreamException (javax.xml.stream.XMLStreamException)20 XMLInputFactory (javax.xml.stream.XMLInputFactory)18 InputStream (java.io.InputStream)14 IOException (java.io.IOException)12 Iterator (java.util.Iterator)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Characters (javax.xml.stream.events.Characters)5 QNm (org.brackit.xquery.atomic.QNm)5