Search in sources :

Example 1 with SAML11SubjectType

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

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

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

the class SAML11AssertionWriter method write.

/**
 * write an {@code SubjectType} to stream
 *
 * @param subject
 * @param out
 *
 * @throws ProcessingException
 */
public void write(SAML11SubjectType subject) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT.get(), SAML11Constants.ASSERTION_11_NSURI);
    StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ns);
    SAML11SubjectTypeChoice choice = subject.getChoice();
    if (choice != null) {
        SAML11NameIdentifierType nameid = choice.getNameID();
        if (nameid != null) {
            write(nameid);
        }
        SAML11SubjectConfirmationType confirmation = choice.getSubjectConfirmation();
        if (confirmation != null)
            write(confirmation);
    }
    SAML11SubjectConfirmationType confirmation = subject.getSubjectConfirmation();
    if (confirmation != null)
        write(confirmation);
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11SubjectConfirmationType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType) SAML11NameIdentifierType(org.keycloak.dom.saml.v1.assertion.SAML11NameIdentifierType) SAML11SubjectTypeChoice(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType.SAML11SubjectTypeChoice)

Example 4 with SAML11SubjectType

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

the class SAML11AssertionWriter method write.

/**
 * Write an {@code AuthnStatementType} to stream
 *
 * @param authnStatement
 * @param out
 *
 * @throws ProcessingException
 */
public void write(SAML11AuthenticationStatementType authnStatement) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.AUTHENTICATION_STATEMENT, SAML11Constants.ASSERTION_11_NSURI);
    XMLGregorianCalendar authnInstant = authnStatement.getAuthenticationInstant();
    if (authnInstant != null) {
        StaxUtil.writeAttribute(writer, SAML11Constants.AUTHENTICATION_INSTANT, authnInstant.toString());
    }
    URI authMethod = authnStatement.getAuthenticationMethod();
    if (authMethod != null) {
        StaxUtil.writeAttribute(writer, SAML11Constants.AUTHENTICATION_METHOD, authMethod.toString());
    }
    SAML11SubjectType subject = authnStatement.getSubject();
    if (subject != null)
        write(subject);
    SAML11SubjectLocalityType locality = authnStatement.getSubjectLocality();
    if (locality != null)
        write(locality);
    List<SAML11AuthorityBindingType> authorities = authnStatement.getAuthorityBindingType();
    for (SAML11AuthorityBindingType authority : authorities) {
        write(authority);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11AuthorityBindingType(org.keycloak.dom.saml.v1.assertion.SAML11AuthorityBindingType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) SAML11SubjectLocalityType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectLocalityType) URI(java.net.URI)

Example 5 with SAML11SubjectType

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

the class SAML11RequestWriter method write.

public void write(SAML11AuthenticationQueryType auth) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.AUTHENTICATION_QUERY, namespace);
    URI authMethod = auth.getAuthenticationMethod();
    if (authMethod != null) {
        StaxUtil.writeAttribute(writer, SAML11Constants.AUTHENTICATION_METHOD, authMethod.toString());
    }
    SAML11SubjectType subject = auth.getSubject();
    if (subject != null) {
        assertionWriter.write(subject);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SAML11SubjectType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectType) URI(java.net.URI)

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