Search in sources :

Example 6 with SAML11SubjectType

use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectType in project keycloak by keycloak.

the class SAML11RequestWriter method write.

public void write(SAML11AuthorizationDecisionQueryType attr) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.AUTHORIZATION_DECISION_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<SAML11ActionType> actions = attr.get();
    for (SAML11ActionType action : actions) {
        assertionWriter.write(action);
    }
    SAML11EvidenceType evidence = attr.getEvidence();
    if (evidence != null) {
        assertionWriter.write(evidence);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) SAML11EvidenceType(org.keycloak.dom.saml.v1.assertion.SAML11EvidenceType) SAML11ActionType(org.keycloak.dom.saml.v1.assertion.SAML11ActionType) URI(java.net.URI)

Example 7 with SAML11SubjectType

use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectType in project keycloak by keycloak.

the class SAML11AssertionParser method parse.

/**
 * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
 */
public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
    startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    // Special case: Encrypted Assertion
    StaxParserUtil.validate(startElement, ASSERTION);
    SAML11AssertionType assertion = parseBaseAttributes(startElement);
    Attribute issuerAttribute = startElement.getAttributeByName(new QName(SAML11Constants.ISSUER));
    String issuer = StaxParserUtil.getAttributeValue(issuerAttribute);
    assertion.setIssuer(issuer);
    // Peek at the next event
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent == null)
            break;
        if (xmlEvent instanceof EndElement) {
            xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
            EndElement endElement = (EndElement) xmlEvent;
            String endElementTag = StaxParserUtil.getElementName(endElement);
            if (endElementTag.equals(JBossSAMLConstants.ASSERTION.get()))
                break;
            else
                throw logger.parserUnknownEndElement(endElementTag, xmlEvent.getLocation());
        }
        StartElement peekedElement = null;
        if (xmlEvent instanceof StartElement) {
            peekedElement = (StartElement) xmlEvent;
        } else {
            peekedElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        }
        if (peekedElement == null)
            break;
        String tag = StaxParserUtil.getElementName(peekedElement);
        if (tag.equals(JBossSAMLConstants.SIGNATURE.get())) {
            assertion.setSignature(StaxParserUtil.getDOMElement(xmlEventReader));
        } else if (JBossSAMLConstants.ISSUER.get().equalsIgnoreCase(tag)) {
            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
            issuer = StaxParserUtil.getElementText(xmlEventReader);
            assertion.setIssuer(issuer);
        } else if (JBossSAMLConstants.SUBJECT.get().equalsIgnoreCase(tag)) {
            SAML11SubjectParser subjectParser = new SAML11SubjectParser();
            SAML11SubjectType subject = (SAML11SubjectType) subjectParser.parse(xmlEventReader);
            SAML11SubjectStatementType subStat = new SAML11SubjectStatementType();
            subStat.setSubject(subject);
        } else if (JBossSAMLConstants.CONDITIONS.get().equalsIgnoreCase(tag)) {
            startElement = (StartElement) xmlEvent;
            SAML11ConditionsType conditions = SAML11ParserUtil.parseSAML11Conditions(xmlEventReader);
            assertion.setConditions(conditions);
        } else if (SAML11Constants.AUTHENTICATION_STATEMENT.equals(tag)) {
            startElement = (StartElement) xmlEvent;
            SAML11AuthenticationStatementType authStat = SAML11ParserUtil.parseAuthenticationStatement(xmlEventReader);
            assertion.add(authStat);
        } else if (SAML11Constants.ATTRIBUTE_STATEMENT.equalsIgnoreCase(tag)) {
            SAML11AttributeStatementType attributeStatementType = SAML11ParserUtil.parseSAML11AttributeStatement(xmlEventReader);
            assertion.add(attributeStatementType);
        } else if (SAML11Constants.AUTHORIZATION_DECISION_STATEMENT.equalsIgnoreCase(tag)) {
            SAML11AuthorizationDecisionStatementType authzStat = SAML11ParserUtil.parseSAML11AuthorizationDecisionStatement(xmlEventReader);
            assertion.add(authzStat);
        } else
            throw logger.parserUnknownTag(tag, peekedElement.getLocation());
    }
    return assertion;
}
Also used : SAML11ConditionsType(org.keycloak.dom.saml.v1.assertion.SAML11ConditionsType) 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) StartElement(javax.xml.stream.events.StartElement) SAML11AuthenticationStatementType(org.keycloak.dom.saml.v1.assertion.SAML11AuthenticationStatementType) SAML11AssertionType(org.keycloak.dom.saml.v1.assertion.SAML11AssertionType) XMLEvent(javax.xml.stream.events.XMLEvent) SAML11AuthorizationDecisionStatementType(org.keycloak.dom.saml.v1.assertion.SAML11AuthorizationDecisionStatementType) SAML11SubjectStatementType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectStatementType) SAML11AttributeStatementType(org.keycloak.dom.saml.v1.assertion.SAML11AttributeStatementType)

Example 8 with SAML11SubjectType

use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectType in project keycloak by keycloak.

the class SAML11AssertionWriter method write.

public void write(SAML11AttributeStatementType statement) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get(), SAML11Constants.ASSERTION_11_NSURI);
    SAML11SubjectType subject = statement.getSubject();
    if (subject != null)
        write(subject);
    List<SAML11AttributeType> attributes = statement.get();
    if (attributes != null) {
        for (SAML11AttributeType attr : attributes) {
            write(attr);
        }
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) SAML11AttributeType(org.keycloak.dom.saml.v1.assertion.SAML11AttributeType)

Example 9 with SAML11SubjectType

use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectType in project keycloak by keycloak.

the class SAML11AssertionWriter method write.

public void write(SAML11AuthorizationDecisionStatementType xacmlStat) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.AUTHORIZATION_DECISION_STATEMENT, ns);
    String resource = xacmlStat.getResource().toString();
    StaxUtil.writeAttribute(writer, SAML11Constants.RESOURCE, resource);
    StaxUtil.writeAttribute(writer, SAML11Constants.DECISION, xacmlStat.getDecision().name());
    SAML11SubjectType subject = xacmlStat.getSubject();
    if (subject != null)
        write(subject);
    List<SAML11ActionType> actions = xacmlStat.getActions();
    for (SAML11ActionType action : actions) {
        write(action);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) SAML11ActionType(org.keycloak.dom.saml.v1.assertion.SAML11ActionType)

Example 10 with SAML11SubjectType

use of org.keycloak.dom.saml.v1.assertion.SAML11SubjectType 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)

Aggregations

SAML11SubjectType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectType)11 EndElement (javax.xml.stream.events.EndElement)8 StartElement (javax.xml.stream.events.StartElement)8 XMLEvent (javax.xml.stream.events.XMLEvent)8 SAML11SubjectParser (org.keycloak.saml.processing.core.parsers.saml.SAML11SubjectParser)6 URI (java.net.URI)5 QName (javax.xml.namespace.QName)5 Attribute (javax.xml.stream.events.Attribute)5 SAML11ActionType (org.keycloak.dom.saml.v1.assertion.SAML11ActionType)4 SAML11AttributeType (org.keycloak.dom.saml.v1.assertion.SAML11AttributeType)3 SAML11AttributeStatementType (org.keycloak.dom.saml.v1.assertion.SAML11AttributeStatementType)2 SAML11AuthenticationStatementType (org.keycloak.dom.saml.v1.assertion.SAML11AuthenticationStatementType)2 SAML11AuthorityBindingType (org.keycloak.dom.saml.v1.assertion.SAML11AuthorityBindingType)2 SAML11AuthorizationDecisionStatementType (org.keycloak.dom.saml.v1.assertion.SAML11AuthorizationDecisionStatementType)2 SAML11NameIdentifierType (org.keycloak.dom.saml.v1.assertion.SAML11NameIdentifierType)2 SAML11SubjectConfirmationType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType)2 SAML11SubjectLocalityType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectLocalityType)2 SAML11SubjectStatementType (org.keycloak.dom.saml.v1.assertion.SAML11SubjectStatementType)2 SAML11SubjectTypeChoice (org.keycloak.dom.saml.v1.assertion.SAML11SubjectType.SAML11SubjectTypeChoice)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1